using System.Text; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Runtime.InteropServices; using SFB; // StandaloneFileBrowser using TMPro; using System.Collections; [RequireComponent(typeof(Button))] public class Save_LOCAL : MonoBehaviour, IPointerDownHandler { private static WaitForSeconds _waitForSeconds2 = new WaitForSeconds(2); [DllImport("__Internal")] private static extern void downloadToFile(string content, string filename); #if UNITY_WEBGL && !UNITY_EDITOR // // WebGL // [DllImport("__Internal")] private static extern void SaveloadFile(string gameObjectName, string methodName, string filename, byte[] byteArray, int byteArraySize); public void OnPointerDown(PointerEventData eventData) { _G.FileName = GameObject.Find("InputLocalName").GetComponent().text; GameObject.Find("FN").gameObject.GetComponent().text = _G.FileName; //var bytes = Encoding.UTF8.GetBytes(SaveXML.buildXMLData()); var bytes = SaveXML.BuildXmlBytes(); SaveloadFile(gameObject.name, "OnFileDownload", _G.FileName+".udt", bytes, bytes.Length); string xmls = Encoding.UTF8.GetString(bytes); if(!_G.saving ){StartCoroutine(Save_WEB.SendTextToFileBK(xmls));} OnFileDownload(); //DownloadToLocal(string content, string filename) } public void SaveLocal(){} public void OnFileDownload() { DOIT.CloseALLPNL(); _M.PH(2, 0,"ffffff", 1, 1); StaticCoroutine.Start(CloseMessage()); } #else // // Standalone platforms & editor // public void OnPointerDown(PointerEventData eventData) { } public void SaveLocal() { _G.FileName = GameObject.Find("InputLocalName").GetComponent().text; GameObject.Find("FN").GetComponent().text = _G.FileName; byte[] bytes = SaveXML.BuildXmlBytes(); string xmls = Encoding.UTF8.GetString(bytes); var path = StandaloneFileBrowser.SaveFilePanel("Save as udt", "", _G.FileName, "udt"); //var path = EditorUtility.SaveFilePanel("Save texture as udt", "", _G.FileName + ".udt", "udt"); Debug.Log("Save file: " + path); if (!string.IsNullOrEmpty(path)) { //System.IO.File.WriteAllText(path, xmls); System.IO.File.WriteAllText(path, xmls, new System.Text.UTF8Encoding(false)); _M.PH(2, 0, "ffffff", 1, 1); } if(!_G.saving ){StartCoroutine(Save_WEB.SendTextToFileBK(xmls));} GameObject.Find("PNL").transform.Find("SAVEpnl").gameObject.SetActive(false); _M.PH(2, 0, "ffffff", 1, 1); StaticCoroutine.Start(CloseMessage()); } #endif public static IEnumerator CloseMessage() { yield return _waitForSeconds2; Get.o2("HIDER", "MESSAGE").SetActive(false); Autosaving.StartAuto(); } public static void DownloadToLocal(string content, string filename) { downloadToFile(content, filename); } public void SaveFromMobile() { _G.FileName = GameObject.Find("InputLocalName").GetComponent().text; GameObject.Find("FN").GetComponent().text = _G.FileName; byte[] bytes = SaveXML.BuildXmlBytes(); string xmls = Encoding.UTF8.GetString(bytes); DownloadToLocal(xmls, _G.FileName + ".udt"); GameObject.Find("PNL").transform.Find("SAVEpnl").gameObject.SetActive(false); print("_G.Camz=2==" + _G.Camz); _M.PH(2, 0, "ffffff", 1, 1); } }