using System; using System.Text; using System.Collections; using System.Collections.Generic; #if UNITY_WEBGL && !UNITY_EDITOR using System.Runtime.InteropServices; #endif using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Xml; using UnityEngine.Networking; using System.IO; #if UNITY_EDITOR using UnityEditor; #endif using SFB; using AOT; [RequireComponent(typeof(Button))] public class Load_LOCAL : MonoBehaviour, IPointerDownHandler { public Text output; public XmlDocument xmlDoc = null; #if UNITY_WEBGL && !UNITY_EDITOR [DllImport("__Internal")] private static extern void RequestTextFile(string gameObjectName, string methodName, string extensions); [DllImport("__Internal")] private static extern void TestSendMessage(); public void OnReceiveMessage(string message) { Debug.Log("JS said: " + message); } public void OnPointerDown(PointerEventData eventData) { Debug.Log("Button clicked - attempting file upload"); // Verify click works RequestTextFile(gameObject.name, "OnFileContentReceived", ".udt"); } // [MonoPInvokeCallback(typeof(Action))] public void OnFileContentReceived(string content) { { try { if (string.IsNullOrEmpty(content)) { Debug.LogError("Received empty content"); return; } if (content.StartsWith("ERROR:")) { Debug.LogError(content); return; } Debug.Log($"Successfully received file content ({content.Length} chars)"); // Process your file content here ProcessFileContent(content); } catch (Exception e) { Debug.LogError($"Content processing failed: {e.Message}"); } } } private void ProcessFileContent(string content) { OutputRoutineEditor(content); WaitCircle.Setting(true, TRANS.This("M_Download") ); xmlDoc = new XmlDocument(); try { Debug.Log("ProcessXMLConten reach try"); xmlDoc.LoadXml(content); Invoke("loadFile", 2); GameObject.Find("HIDER").transform.Find("LOADpnl").GetComponent().alpha = 0; } catch (Exception e) { Debug.LogError("XML Load Error: " + e.Message); } } #else public void OnPointerDown(PointerEventData eventData) { Debug.Log("File upload would trigger here in WebGL build"); } public void ClickLocal() { string paths = ""; var extensions = new[] { new ExtensionFilter("UDT Files", "udt"), new ExtensionFilter("All Files", "*") }; var pathsArray = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, false); if (pathsArray.Length > 0) { paths = pathsArray[0]; StartCoroutine(OutputRoutineEditor(paths)); WaitCircle.Setting(true, TRANS.This("M_Download") ); } } #endif private IEnumerator OutputRoutineEditor(string url) { //Debug.Log("OutputRoutineEditor reach"); UnityWebRequest request = UnityWebRequest.Get(url); yield return request.SendWebRequest(); xmlDoc = new XmlDocument(); Debug.Log("string url==" + url); xmlDoc.Load(url); Invoke("loadFile", 2); GameObject.Find("HIDER").transform.Find("LOADpnl").GetComponent().alpha = 0; WaitCircle.Setting(true, TRANS.This("M_Download") ); yield return null; } public void loadFile() { LoadXML.SetGLOBAL(xmlDoc); } }