add file open
This commit is contained in:
24
Assets/3rd/DocumentHandler/Runtime/DocumentHandler.cs
Normal file
24
Assets/3rd/DocumentHandler/Runtime/DocumentHandler.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace drstc.DocumentHandler
|
||||
{
|
||||
public class DocumentHandler : MonoBehaviour
|
||||
{
|
||||
#if UNITY_IPHONE && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
internal static extern bool _OpenDocument(string path);
|
||||
|
||||
public static void OpenDocument(string path)
|
||||
{
|
||||
_OpenDocument(path);
|
||||
}
|
||||
#else
|
||||
public static void OpenDocument(string path)
|
||||
{
|
||||
Application.OpenURL("file:///" + path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/3rd/DocumentHandler/Runtime/DocumentHandler.cs.meta
Normal file
11
Assets/3rd/DocumentHandler/Runtime/DocumentHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d93365ec5d0f214fa3e11145e4b8308
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Drstc.DocumentHandler.Runtime"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eca2ed0e95167ad4aa975aab1849e6a5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/3rd/DocumentHandler/Runtime/Plugins.meta
Normal file
8
Assets/3rd/DocumentHandler/Runtime/Plugins.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c435a9dc757064648be238db0af31815
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/3rd/DocumentHandler/Runtime/Plugins/iOS.meta
Normal file
8
Assets/3rd/DocumentHandler/Runtime/Plugins/iOS.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 758b72d97ebaec34195e3f662c0334af
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,87 @@
|
||||
// Credits: https://answers.unity.com/questions/1337996/ios-open-docx-file-from-applicationpersistentdata.html
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface DocumentHandler : NSObject <UIDocumentInteractionControllerDelegate>
|
||||
{
|
||||
NSURL * fileURL;
|
||||
}
|
||||
|
||||
- (id)initWithURL:(NSURL*)unityURL;
|
||||
|
||||
- (void)UpdateURL:(NSURL*)unityURL;
|
||||
|
||||
- (bool)OpenDocument;
|
||||
|
||||
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation DocumentHandler
|
||||
|
||||
- (id)initWithURL:(NSURL*)unityURL
|
||||
{
|
||||
self = [super init];
|
||||
fileURL = unityURL;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)UpdateURL:(NSURL*)unityURL {
|
||||
fileURL = unityURL;
|
||||
}
|
||||
|
||||
- (bool)OpenDocument {
|
||||
|
||||
UIDocumentInteractionController *interactionController =
|
||||
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
|
||||
|
||||
// Configure Document Interaction Controller
|
||||
[interactionController setDelegate:self];
|
||||
|
||||
[interactionController presentPreviewAnimated:YES];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
|
||||
return UnityGetGLViewController();
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
static DocumentHandler* docHandler = nil;
|
||||
|
||||
// Converts C style string to NSString
|
||||
NSString* CreateNSString (const char* string)
|
||||
{
|
||||
if (string)
|
||||
return [NSString stringWithUTF8String: string];
|
||||
else
|
||||
return [NSString stringWithUTF8String: ""];
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool _OpenDocument (const char* path)
|
||||
{
|
||||
// Convert path to URL
|
||||
NSString * stringPath = CreateNSString(path);
|
||||
|
||||
NSURL *unityURL = [NSURL fileURLWithPath:stringPath];
|
||||
|
||||
if (docHandler == nil)
|
||||
docHandler = [[DocumentHandler alloc] initWithURL:unityURL];
|
||||
|
||||
else
|
||||
[docHandler UpdateURL:unityURL];
|
||||
|
||||
[docHandler OpenDocument];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93804f9d06962764c8ecf5d676d9c4e9
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user