mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:37:37 +02:00
Basic saving and loading system
This commit is contained in:
119
Assets/Plugins/StandaloneFileBrowser/Sample/BasicSample.cs
Normal file
119
Assets/Plugins/StandaloneFileBrowser/Sample/BasicSample.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using SFB;
|
||||
|
||||
public class BasicSample : MonoBehaviour {
|
||||
private string _path;
|
||||
|
||||
void OnGUI() {
|
||||
var guiScale = new Vector3(Screen.width / 800.0f, Screen.height / 600.0f, 1.0f);
|
||||
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, guiScale);
|
||||
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(20);
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
// Open File Samples
|
||||
|
||||
if (GUILayout.Button("Open File")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Async")) {
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", "", false, (string[] paths) => { WriteResult(paths); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Multiple")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Extension")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "txt", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Directory")) {
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", Application.dataPath, "", true));
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open File Filter")) {
|
||||
var extensions = new [] {
|
||||
new ExtensionFilter("Image Files", "png", "jpg", "jpeg" ),
|
||||
new ExtensionFilter("Sound Files", "mp3", "wav" ),
|
||||
new ExtensionFilter("All Files", "*" ),
|
||||
};
|
||||
WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true));
|
||||
}
|
||||
|
||||
GUILayout.Space(15);
|
||||
|
||||
// Open Folder Samples
|
||||
|
||||
if (GUILayout.Button("Open Folder")) {
|
||||
var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", "", true);
|
||||
WriteResult(paths);
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open Folder Async")) {
|
||||
StandaloneFileBrowser.OpenFolderPanelAsync("Select Folder", "", true, (string[] paths) => { WriteResult(paths); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Open Folder Directory")) {
|
||||
var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", Application.dataPath, true);
|
||||
WriteResult(paths);
|
||||
}
|
||||
|
||||
GUILayout.Space(15);
|
||||
|
||||
// Save File Samples
|
||||
|
||||
if (GUILayout.Button("Save File")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Async")) {
|
||||
StandaloneFileBrowser.SaveFilePanelAsync("Save File", "", "", "", (string path) => { WriteResult(path); });
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Default Name")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Default Name Ext")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", "dat");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Directory")) {
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", Application.dataPath, "", "");
|
||||
}
|
||||
GUILayout.Space(5);
|
||||
if (GUILayout.Button("Save File Filter")) {
|
||||
// Multiple save extension filters with more than one extension support.
|
||||
var extensionList = new [] {
|
||||
new ExtensionFilter("Binary", "bin"),
|
||||
new ExtensionFilter("Text", "txt"),
|
||||
};
|
||||
_path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", extensionList);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.Space(20);
|
||||
GUILayout.Label(_path);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public void WriteResult(string[] paths) {
|
||||
if (paths.Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
_path = "";
|
||||
foreach (var p in paths) {
|
||||
_path += p + "\n";
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteResult(string path) {
|
||||
_path = path;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5148400295519405d82bb0fa65246ea2
|
||||
timeCreated: 1483902788
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,248 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!29 &1
|
||||
OcclusionCullingSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_OcclusionBakeSettings:
|
||||
smallestOccluder: 5
|
||||
smallestHole: 0.25
|
||||
backfaceThreshold: 100
|
||||
m_SceneGUID: 00000000000000000000000000000000
|
||||
m_OcclusionCullingData: {fileID: 0}
|
||||
--- !u!104 &2
|
||||
RenderSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 9
|
||||
m_Fog: 0
|
||||
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
|
||||
m_FogMode: 3
|
||||
m_FogDensity: 0.01
|
||||
m_LinearFogStart: 0
|
||||
m_LinearFogEnd: 300
|
||||
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
|
||||
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
|
||||
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
|
||||
m_AmbientIntensity: 1
|
||||
m_AmbientMode: 3
|
||||
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
|
||||
m_SkyboxMaterial: {fileID: 0}
|
||||
m_HaloStrength: 0.5
|
||||
m_FlareStrength: 1
|
||||
m_FlareFadeSpeed: 3
|
||||
m_HaloTexture: {fileID: 0}
|
||||
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
|
||||
m_DefaultReflectionMode: 0
|
||||
m_DefaultReflectionResolution: 128
|
||||
m_ReflectionBounces: 1
|
||||
m_ReflectionIntensity: 1
|
||||
m_CustomReflection: {fileID: 0}
|
||||
m_Sun: {fileID: 0}
|
||||
m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_UseRadianceAmbientProbe: 0
|
||||
--- !u!157 &3
|
||||
LightmapSettings:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 11
|
||||
m_GIWorkflowMode: 1
|
||||
m_GISettings:
|
||||
serializedVersion: 2
|
||||
m_BounceScale: 1
|
||||
m_IndirectOutputScale: 1
|
||||
m_AlbedoBoost: 1
|
||||
m_TemporalCoherenceThreshold: 1
|
||||
m_EnvironmentLightingMode: 0
|
||||
m_EnableBakedLightmaps: 0
|
||||
m_EnableRealtimeLightmaps: 0
|
||||
m_LightmapEditorSettings:
|
||||
serializedVersion: 10
|
||||
m_Resolution: 2
|
||||
m_BakeResolution: 40
|
||||
m_AtlasSize: 1024
|
||||
m_AO: 0
|
||||
m_AOMaxDistance: 1
|
||||
m_CompAOExponent: 1
|
||||
m_CompAOExponentDirect: 0
|
||||
m_Padding: 2
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_LightmapsBakeMode: 1
|
||||
m_TextureCompression: 1
|
||||
m_FinalGather: 0
|
||||
m_FinalGatherFiltering: 1
|
||||
m_FinalGatherRayCount: 256
|
||||
m_ReflectionCompression: 2
|
||||
m_MixedBakeMode: 1
|
||||
m_BakeBackend: 0
|
||||
m_PVRSampling: 1
|
||||
m_PVRDirectSampleCount: 32
|
||||
m_PVRSampleCount: 500
|
||||
m_PVRBounces: 2
|
||||
m_PVRFilterTypeDirect: 0
|
||||
m_PVRFilterTypeIndirect: 0
|
||||
m_PVRFilterTypeAO: 0
|
||||
m_PVRFilteringMode: 0
|
||||
m_PVRCulling: 1
|
||||
m_PVRFilteringGaussRadiusDirect: 1
|
||||
m_PVRFilteringGaussRadiusIndirect: 5
|
||||
m_PVRFilteringGaussRadiusAO: 2
|
||||
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
|
||||
m_PVRFilteringAtrousPositionSigmaIndirect: 2
|
||||
m_PVRFilteringAtrousPositionSigmaAO: 1
|
||||
m_ShowResolutionOverlay: 1
|
||||
m_LightingDataAsset: {fileID: 0}
|
||||
m_UseShadowmask: 0
|
||||
--- !u!196 &4
|
||||
NavMeshSettings:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_BuildSettings:
|
||||
serializedVersion: 2
|
||||
agentTypeID: 0
|
||||
agentRadius: 0.5
|
||||
agentHeight: 2
|
||||
agentSlope: 45
|
||||
agentClimb: 0.4
|
||||
ledgeDropHeight: 0
|
||||
maxJumpAcrossDistance: 0
|
||||
minRegionArea: 2
|
||||
manualCellSize: 0
|
||||
cellSize: 0.16666667
|
||||
manualTileSize: 0
|
||||
tileSize: 256
|
||||
accuratePlacement: 0
|
||||
debug:
|
||||
m_Flags: 0
|
||||
m_NavMeshData: {fileID: 0}
|
||||
--- !u!1 &382763637
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 382763642}
|
||||
- component: {fileID: 382763641}
|
||||
- component: {fileID: 382763640}
|
||||
- component: {fileID: 382763639}
|
||||
- component: {fileID: 382763638}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!81 &382763638
|
||||
AudioListener:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!124 &382763639
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!92 &382763640
|
||||
Behaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
--- !u!20 &382763641
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
|
||||
m_projectionMatrixMode: 1
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_FocalLength: 50
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 5
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 0
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!4 &382763642
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 382763637}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &986049433
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 986049435}
|
||||
- component: {fileID: 986049434}
|
||||
m_Layer: 0
|
||||
m_Name: GameObject
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &986049434
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 986049433}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 5148400295519405d82bb0fa65246ea2, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!4 &986049435
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 986049433}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 1
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d97280fe82b874466870f709c3315d41
|
||||
timeCreated: 1483902786
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,53 @@
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileImage : MonoBehaviour, IPointerDownHandler {
|
||||
public RawImage output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".png, .jpg", false);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string url) {
|
||||
StartCoroutine(OutputRoutine(url));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", ".png", false);
|
||||
if (paths.Length > 0) {
|
||||
StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string url) {
|
||||
var loader = new WWW(url);
|
||||
yield return loader;
|
||||
output.texture = loader.texture;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 331c95b7bf39e4792acecff50a972040
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,53 @@
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileText : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".txt", false);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string url) {
|
||||
StartCoroutine(OutputRoutine(url));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "txt", false);
|
||||
if (paths.Length > 0) {
|
||||
StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string url) {
|
||||
var loader = new WWW(url);
|
||||
yield return loader;
|
||||
output.text = loader.text;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99a65d6437df64949b37cba4eadc67a2
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,62 @@
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleOpenFileTextMultiple : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple);
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
UploadFile(gameObject.name, "OnFileUpload", ".txt", true);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileUpload(string urls) {
|
||||
StartCoroutine(OutputRoutine(urls.Split(',')));
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick() {
|
||||
// var paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "txt", true);
|
||||
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", true);
|
||||
if (paths.Length > 0) {
|
||||
var urlArr = new List<string>(paths.Length);
|
||||
for (int i = 0; i < paths.Length; i++) {
|
||||
urlArr.Add(new System.Uri(paths[i]).AbsoluteUri);
|
||||
}
|
||||
StartCoroutine(OutputRoutine(urlArr.ToArray()));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private IEnumerator OutputRoutine(string[] urlArr) {
|
||||
var outputText = "";
|
||||
for (int i = 0; i < urlArr.Length; i++) {
|
||||
var loader = new WWW(urlArr[i]);
|
||||
yield return loader;
|
||||
outputText += loader.text;
|
||||
}
|
||||
output.text = outputText;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71c09849449d61e47a4599e06b964998
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,65 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleSaveFileImage : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
private byte[] _textureBytes;
|
||||
|
||||
void Awake() {
|
||||
// Create red texture
|
||||
var width = 100;
|
||||
var height = 100;
|
||||
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
tex.SetPixel(i, j, Color.red);
|
||||
}
|
||||
}
|
||||
tex.Apply();
|
||||
_textureBytes = tex.EncodeToPNG();
|
||||
UnityEngine.Object.Destroy(tex);
|
||||
}
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
|
||||
|
||||
// Broser plugin should be called in OnPointerDown.
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
DownloadFile(gameObject.name, "OnFileDownload", "sample.png", _textureBytes, _textureBytes.Length);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileDownload() {
|
||||
output.text = "File Successfully Downloaded";
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
// Listen OnClick event in standlone builds
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void OnClick() {
|
||||
var path = StandaloneFileBrowser.SaveFilePanel("Title", "", "sample", "png");
|
||||
if (!string.IsNullOrEmpty(path)) {
|
||||
File.WriteAllBytes(path, _textureBytes);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e681018aa67241a69b8447678ec3b4e
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,52 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using SFB;
|
||||
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class CanvasSampleSaveFileText : MonoBehaviour, IPointerDownHandler {
|
||||
public Text output;
|
||||
|
||||
// Sample text data
|
||||
private string _data = "Example text created by StandaloneFileBrowser";
|
||||
|
||||
#if UNITY_WEBGL && !UNITY_EDITOR
|
||||
//
|
||||
// WebGL
|
||||
//
|
||||
[DllImport("__Internal")]
|
||||
private static extern void DownloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize);
|
||||
|
||||
// Broser plugin should be called in OnPointerDown.
|
||||
public void OnPointerDown(PointerEventData eventData) {
|
||||
var bytes = Encoding.UTF8.GetBytes(_data);
|
||||
DownloadFile(gameObject.name, "OnFileDownload", "sample.txt", bytes, bytes.Length);
|
||||
}
|
||||
|
||||
// Called from browser
|
||||
public void OnFileDownload() {
|
||||
output.text = "File Successfully Downloaded";
|
||||
}
|
||||
#else
|
||||
//
|
||||
// Standalone platforms & editor
|
||||
//
|
||||
public void OnPointerDown(PointerEventData eventData) { }
|
||||
|
||||
// Listen OnClick event in standlone builds
|
||||
void Start() {
|
||||
var button = GetComponent<Button>();
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void OnClick() {
|
||||
var path = StandaloneFileBrowser.SaveFilePanel("Title", "", "sample", "txt");
|
||||
if (!string.IsNullOrEmpty(path)) {
|
||||
File.WriteAllText(path, _data);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e97f52f0bd664ee78305dae0094a755
|
||||
timeCreated: 1489946149
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
1520
Assets/Plugins/StandaloneFileBrowser/Sample/CanvasSampleScene.unity
Normal file
1520
Assets/Plugins/StandaloneFileBrowser/Sample/CanvasSampleScene.unity
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0e4eec5741834194a946535d535405c
|
||||
timeCreated: 1483902786
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user