using System.Collections; using UnityEngine; using System.Xml; using UnityEngine.Networking; using System; using System.Text; public class AutoOpenUDTFile : MonoBehaviour { static string _decodedURL; static XmlDocument xmlDoc = null; public static void OpenUDT(string url) { _decodedURL = UnityWebRequest.UnEscapeURL(url); Debug.Log("Decoded url= " + _decodedURL); StaticCoroutine.Start(OutputRoutine(_decodedURL)); } private static IEnumerator OutputRoutine(string url) { GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); UnityWebRequest request = UnityWebRequest.Get(url); yield return request.SendWebRequest(); xmlDoc = new XmlDocument(); xmlDoc.LoadXml(request.downloadHandler.text); yield return new WaitForSeconds(2f); loadFile(); GameObject.Find("HIDER").transform.Find("LOADpnl").GetComponent().alpha = 0; GameObject.Find("HIDER").transform.Find("LoadingCircle").gameObject.SetActive(true); yield return null; yield break; } public static void loadFile() { LoadXML.SetGLOBAL(xmlDoc); } [ContextMenu("Save To Cieblink")] public void OpenCieblinkLink() { byte[] bytes = SaveXML.BuildXmlBytes(); string xmls = Encoding.UTF8.GetString(bytes); StartCoroutine(SendAndGenerateUDT(xmls)); } [ContextMenu("Receive Error Message")] public void TestErrorMessage() { DisplayErrorMessageCiemetric("Error : No Save File"); } public void DisplayErrorMessageCiemetric(string message) { Debug.Log(message); ErrorPopupPNL pnl = ErrorPopupPNL.Instance; pnl.UpdateErrorMessage(message); pnl.gameObject.SetActive(true); } public void CloseErrorPopupWindow(GameObject window) { Destroy(window); } public IEnumerator SendAndGenerateUDT(string xmls) { string guidString = System.Guid.NewGuid().ToString(); bool isCiecommerce = !string.IsNullOrEmpty(_G._SOURCE); Debug.Log("isCiecommerce = " + isCiecommerce); string pdfUrl = ""; if (isCiecommerce) { _G.PDF = null; // generate pdf PDFPLAN.Instance.GeneratePDFForURL(); yield return new WaitUntil (() => _G.PDF != null); Debug.Assert(_G.PDF != null, "PDF is null"); WWWForm formPdf = new WWWForm(); formPdf.AddField("filename", guidString); string pdfData = Convert.ToBase64String(_G.PDF); formPdf.AddField("pdfdata", pdfData); //formPdf.AddBinaryData("pdfdata", _G.PDF); string pathPdf = "https://software.ciemetric.com/9987/savepdf.php"; using (UnityWebRequest webRequest = UnityWebRequest.Post(pathPdf, formPdf)) { yield return webRequest.SendWebRequest(); if (webRequest.result == UnityWebRequest.Result.ConnectionError) { Debug.Log(webRequest.error); } else { Debug.Log(webRequest.downloadHandler.text); string url = "https://software.ciemetric.com/9987/" + guidString + ".pdf"; pdfUrl = UnityWebRequest.EscapeURL(url); Debug.Log("PDF URL generated successfully"); } } } WWWForm formXml = new WWWForm(); formXml.AddField("filename", guidString); formXml.AddField("xmldata", xmls); string pathxml = "https://software.ciemetric.com/9987/savexml.php"; using (UnityWebRequest webRequest = UnityWebRequest.Post(pathxml, formXml)) { yield return webRequest.SendWebRequest(); if (webRequest.result == UnityWebRequest.Result.ConnectionError) { Debug.Log(webRequest.error); } else { Debug.Log(webRequest.downloadHandler.text); if (!string.IsNullOrEmpty(_G._saveLink)) { string _decodedSaveLink = UnityWebRequest.UnEscapeURL(_G._saveLink); string url = "https://software.ciemetric.com/9987/" + guidString + ".udt"; string _codeDownloadedFileURL = UnityWebRequest.EscapeURL(url); if (isCiecommerce) { Debug.Log("pdf URL == " + pdfUrl); Application.ExternalEval("window.open('" + _decodedSaveLink + "&file=" + _codeDownloadedFileURL + "&pdf=" + pdfUrl + "','_self')"); } else { Application.ExternalEval("window.open('" + _decodedSaveLink + "&file=" + _codeDownloadedFileURL + "','_self')"); } } } yield break; } } }