mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-23 10:05:14 +00:00
53 lines
No EOL
1.4 KiB
C#
53 lines
No EOL
1.4 KiB
C#
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;
|
|
}
|
|
} |