using System.Text; using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Xml; using UnityEngine.Networking; using UnityEditor; using System.IO; using SFB; // StandaloneFileBrowserusing System.Collections; using System; [RequireComponent(typeof(Button))] public class LoadListPrice : MonoBehaviour, IPointerDownHandler{ string load; #if UNITY_WEBGL && !UNITY_EDITOR [DllImport("__Internal")] private static extern void RequestTextFile(string gameObjectName, string methodName, string extensions); public void OnPointerDown(PointerEventData eventData) { Debug.Log("Button clicked - attempting file upload"); // Verify click works RequestTextFile(gameObject.name, "OnFileContentReceived", ".udt"); } 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); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); try { //xmlDoc.LoadXml(content); string[] loads = content.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } Invoke(nameof(LoadFile), 2); } catch (Exception e) { Debug.LogError("XML Load Error: " + e.Message); } } // WebGL----------------------------------------------------------------------------------WebGL #else // EDITOR----------------------------------------------------------------------------------EDITOR public void OnPointerDown(PointerEventData eventData) { } public void ClickLocal() { string paths = StandaloneFileBrowser.OpenFilePanel("Title", "", "csv",false)[0]; //string paths = EditorUtility.OpenFilePanel("Title", "", "udt"); if (paths.Length > 0) { StartCoroutine(OutputRoutineEditor(paths)); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); } } #endif private IEnumerator OutputRoutineEditor(string url) { using UnityWebRequest www = UnityWebRequest.Get(url); { UnityWebRequest.ClearCookieCache(); yield return www.SendWebRequest(); if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error + " library===" + "Client List"); } else { if (www.downloadHandler.data == null) yield break; string load = BinaryToText(www.downloadHandler.data); string[] loads = load.Split(new char[] { '\n' }); _G.LibraryLoads = new List(); foreach (string line in loads) { string l = line.Replace("/", "|"); _G.LibraryLoads.Add(l); } Invoke(nameof(LoadFile), 2); yield return null; yield break; } } } public void LoadFile() { ListPriceInput.SetOnList(); GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(false); } public static string BinaryToText(byte[] data) { return Encoding.UTF8.GetString(data); } }