add file open

This commit is contained in:
2020-08-07 22:40:04 +08:00
parent c1e3f992aa
commit f9bedd2c62
115 changed files with 9835 additions and 1096 deletions

View File

@@ -0,0 +1,13 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [0.1.0] - 2020-07-30
### Added
- Init commit

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 73252913ec82f3b4fbb65300a8c44696
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020 Eduard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 317c760af475c2540b76a28e3783315c
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
# DocumentHandler
Open a document (e.g. PDF) with a corresponding native app.
Since ``Application.OpenURL(...path)`` is not working (anymore?) to open local files on iOS, I searched the internet for another solution (see credits). I found usable code and want to make it more accessible.
## How to install
Just add the plugin via Package Manager with the git url:
```
https://github.com/Draudastic26/document-handler.git#upm
```
## Usage
```csharp
using drstc.DocumentHandler;
...
DocumentHandler.OpenDocument(somePath);
```
## Notes
I just tested this on iOS with a PDF file. Please let me know if you tested this with other document types.
## Contribution
Feel free to create a pull request or an issue!
## Credits
martejpad post in this thread: [https://answers.unity.com/questions/1337996/ios-open-docx-file-from-applicationpersistentdata.html](https://answers.unity.com/questions/1337996/ios-open-docx-file-from-applicationpersistentdata.html)
Unity 2019.4.3f

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f7c4aa3b47f1f6d418567f4d798595d1
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eaaf4e73c50a9994a91535ac431ebcec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d93365ec5d0f214fa3e11145e4b8308
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
{
"name": "Drstc.DocumentHandler.Runtime"
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: eca2ed0e95167ad4aa975aab1849e6a5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c435a9dc757064648be238db0af31815
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 758b72d97ebaec34195e3f662c0334af
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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;
}
}

View File

@@ -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:

View File

@@ -0,0 +1,12 @@
{
"name": "com.drstc.documenthandler",
"displayName": "DocumentHandler",
"version": "0.1.0",
"unity": "2019.4",
"description": "Open a document (e.g. .pfd) with a corresponding native app.",
"author": {
"name": "Draudastic",
"email": "via gitHub",
"url": "https://github.com/Draudastic26"
}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f84eb8099ddc06e4b83d7bb97b4710a2
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: