|
@@ -1,7 +1,7 @@
|
|
using System;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
-using System.Threading.Tasks;
|
|
|
|
|
|
+using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.Networking;
|
|
|
|
|
|
@@ -15,94 +15,94 @@ public class SetWebGLText : MonoBehaviour
|
|
void Awake()
|
|
void Awake()
|
|
{
|
|
{
|
|
Instance = this;
|
|
Instance = this;
|
|
- webglfont = font;
|
|
|
|
- // StartCoroutine(LoadAB());
|
|
|
|
|
|
+ webglfont = font;
|
|
|
|
+ // StartCoroutine(LoadAB());
|
|
}
|
|
}
|
|
IEnumerator Downloadip()
|
|
IEnumerator Downloadip()
|
|
- {
|
|
|
|
|
|
+ {
|
|
Debug.Log("开始获取ip文件" + Application.streamingAssetsPath + "/1.txt");
|
|
Debug.Log("开始获取ip文件" + Application.streamingAssetsPath + "/1.txt");
|
|
UnityWebRequest m_webrequest = UnityWebRequest.Get(Application.streamingAssetsPath + "/1.txt");
|
|
UnityWebRequest m_webrequest = UnityWebRequest.Get(Application.streamingAssetsPath + "/1.txt");
|
|
yield return m_webrequest.SendWebRequest();
|
|
yield return m_webrequest.SendWebRequest();
|
|
|
|
|
|
if (m_webrequest.result != UnityWebRequest.Result.Success)
|
|
if (m_webrequest.result != UnityWebRequest.Result.Success)
|
|
- {
|
|
|
|
|
|
+ {
|
|
Debug.Log("获取ip文件失败==》" + m_webrequest.downloadHandler.error);
|
|
Debug.Log("获取ip文件失败==》" + m_webrequest.downloadHandler.error);
|
|
Debug.LogError("Failed to download image");
|
|
Debug.LogError("Failed to download image");
|
|
}
|
|
}
|
|
else
|
|
else
|
|
- {
|
|
|
|
- DataManager.ip = RemoveWhitespace(m_webrequest.downloadHandler.text);
|
|
|
|
|
|
+ {
|
|
|
|
+ DataManager.ip = RemoveWhitespace(m_webrequest.downloadHandler.text);
|
|
Debug.Log("获取ip文件成功==》" + DataManager.ip);
|
|
Debug.Log("获取ip文件成功==》" + DataManager.ip);
|
|
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- string RemoveWhitespace(string input)
|
|
|
|
- {
|
|
|
|
- // 去除回车、换行、制表符和空格等空白字符
|
|
|
|
- return input.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ string RemoveWhitespace(string input)
|
|
|
|
+ {
|
|
|
|
+ // 去除回车、换行、制表符和空格等空白字符
|
|
|
|
+ return input.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace(" ", "");
|
|
|
|
+ }
|
|
IEnumerator DownloadMacIp()
|
|
IEnumerator DownloadMacIp()
|
|
- {
|
|
|
|
- string filePath = Application.streamingAssetsPath+"/1.txt";
|
|
|
|
-
|
|
|
|
- Debug.Log("开始获取ip文件"+ filePath);
|
|
|
|
|
|
+ {
|
|
|
|
+ string filePath = Application.streamingAssetsPath+"/1.txt";
|
|
|
|
+
|
|
|
|
+ Debug.Log("开始获取ip文件"+ filePath);
|
|
if (!stlist.ContainsKey(filePath))
|
|
if (!stlist.ContainsKey(filePath))
|
|
- {
|
|
|
|
- if (System.IO.File.Exists(filePath))
|
|
|
|
- {
|
|
|
|
- Task<string> fileData = System.IO.File.ReadAllTextAsync(filePath);
|
|
|
|
- while (!fileData.IsCompleted)
|
|
|
|
- {
|
|
|
|
- yield return null;
|
|
|
|
- }
|
|
|
|
- DataManager.ip = RemoveWhitespace(fileData.Result);
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
|
+ {
|
|
|
|
+ Task<string> fileData = System.IO.File.ReadAllTextAsync(filePath);
|
|
|
|
+ while (!fileData.IsCompleted)
|
|
|
|
+ {
|
|
|
|
+ yield return null;
|
|
|
|
+ }
|
|
|
|
+ DataManager.ip = RemoveWhitespace(fileData.Result);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
- yield return null;
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ yield return null;
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
IEnumerator DownloadImageMac(callback url)
|
|
IEnumerator DownloadImageMac(callback url)
|
|
- {
|
|
|
|
- string filePath = url.url;
|
|
|
|
-
|
|
|
|
|
|
+ {
|
|
|
|
+ string filePath = url.url;
|
|
|
|
+
|
|
if (!stlist.ContainsKey(url.url))
|
|
if (!stlist.ContainsKey(url.url))
|
|
- {
|
|
|
|
- if (System.IO.File.Exists(filePath))
|
|
|
|
- {
|
|
|
|
- Task<byte[]> fileData = System.IO.File.ReadAllBytesAsync(filePath);
|
|
|
|
- while (!fileData.IsCompleted)
|
|
|
|
- {
|
|
|
|
- yield return null;
|
|
|
|
- }
|
|
|
|
- Texture2D texture = new Texture2D(2, 2);
|
|
|
|
- if (texture.LoadImage(fileData.Result))
|
|
|
|
- {
|
|
|
|
- stlist.Add(url.url, texture);
|
|
|
|
- url.msg.Invoke(texture);
|
|
|
|
- isload = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- isload = false;
|
|
|
|
- Debug.LogError("Failed to download image "+ filePath);
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ {
|
|
|
|
+ if (System.IO.File.Exists(filePath))
|
|
|
|
+ {
|
|
|
|
+ Task<byte[]> fileData = System.IO.File.ReadAllBytesAsync(filePath);
|
|
|
|
+ while (!fileData.IsCompleted)
|
|
|
|
+ {
|
|
|
|
+ yield return null;
|
|
|
|
+ }
|
|
|
|
+ Texture2D texture = new Texture2D(2, 2);
|
|
|
|
+ if (texture.LoadImage(fileData.Result))
|
|
|
|
+ {
|
|
|
|
+ stlist.Add(url.url, texture);
|
|
|
|
+ url.msg.Invoke(texture);
|
|
|
|
+ isload = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ isload = false;
|
|
|
|
+ Debug.LogError("Failed to download image "+ filePath);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- else
|
|
|
|
- {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
yield return null;
|
|
yield return null;
|
|
url.msg.Invoke(stlist[url.url]);
|
|
url.msg.Invoke(stlist[url.url]);
|
|
- isload = false;
|
|
|
|
|
|
+ isload = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator LoadAB()
|
|
IEnumerator LoadAB()
|
|
- {
|
|
|
|
|
|
+ {
|
|
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "stzhongs");
|
|
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "stzhongs");
|
|
//UnityWebRequest request = UnityWebRequest.Get(filePath);
|
|
//UnityWebRequest request = UnityWebRequest.Get(filePath);
|
|
|
|
|
|
@@ -123,17 +123,17 @@ public class SetWebGLText : MonoBehaviour
|
|
Queue<callback> dl = new Queue<callback>();
|
|
Queue<callback> dl = new Queue<callback>();
|
|
public void GetTexture(string url,Action<Texture2D> msg)
|
|
public void GetTexture(string url,Action<Texture2D> msg)
|
|
{
|
|
{
|
|
- if(stlist.ContainsKey(url))
|
|
|
|
- {
|
|
|
|
- msg.Invoke(stlist[url]);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- callback cb = new callback();
|
|
|
|
- cb.url = url;
|
|
|
|
- cb.msg = msg;
|
|
|
|
- dl.Enqueue(cb);
|
|
|
|
|
|
+ if(stlist.ContainsKey(url))
|
|
|
|
+ {
|
|
|
|
+ msg.Invoke(stlist[url]);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ callback cb = new callback();
|
|
|
|
+ cb.url = url;
|
|
|
|
+ cb.msg = msg;
|
|
|
|
+ dl.Enqueue(cb);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
bool isload;
|
|
bool isload;
|
|
@@ -142,12 +142,12 @@ public class SetWebGLText : MonoBehaviour
|
|
if(dl.Count>0&&!isload)
|
|
if(dl.Count>0&&!isload)
|
|
{
|
|
{
|
|
isload = true;
|
|
isload = true;
|
|
- callback cb = dl.Dequeue();
|
|
|
|
|
|
+ callback cb = dl.Dequeue();
|
|
#if UNITY_EDITOR
|
|
#if UNITY_EDITOR
|
|
StartCoroutine(DownloadImageMac(cb));
|
|
StartCoroutine(DownloadImageMac(cb));
|
|
#else
|
|
#else
|
|
StartCoroutine(DownloadImage(cb));
|
|
StartCoroutine(DownloadImage(cb));
|
|
-#endif
|
|
|
|
|
|
+#endif
|
|
#if UNITY_EDITOR
|
|
#if UNITY_EDITOR
|
|
StartCoroutine(DownloadMacIp());
|
|
StartCoroutine(DownloadMacIp());
|
|
#else
|
|
#else
|