提交 c14f7cec 编写于 作者: yqian1000's avatar yqian1000

优化图片列表加载

上级 c9f3fe11
...@@ -3863,9 +3863,9 @@ MonoBehaviour: ...@@ -3863,9 +3863,9 @@ MonoBehaviour:
scrollRect: {fileID: 2373949832944046736} scrollRect: {fileID: 2373949832944046736}
top: 30 top: 30
bottom: 30 bottom: 30
interval: 10 interval: 6
elem: {fileID: -7887652861602639447, guid: 690fc32fa58083545a25ccbc922a4ea5, type: 3} elem: {fileID: -7887652861602639447, guid: 690fc32fa58083545a25ccbc922a4ea5, type: 3}
elemCount: 20 elemCount: 10
--- !u!1 &2440221074765671710 --- !u!1 &2440221074765671710
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -298,7 +298,7 @@ MonoBehaviour: ...@@ -298,7 +298,7 @@ MonoBehaviour:
bottom: 30 bottom: 30
interval: 10 interval: 10
elem: {fileID: -7887652861602639447, guid: 690fc32fa58083545a25ccbc922a4ea5, type: 3} elem: {fileID: -7887652861602639447, guid: 690fc32fa58083545a25ccbc922a4ea5, type: 3}
elemCount: 20 elemCount: 6
--- !u!1 &1335748695387864072 --- !u!1 &1335748695387864072
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -56,7 +56,7 @@ public class CardManager : SingletonMono<CardManager> ...@@ -56,7 +56,7 @@ public class CardManager : SingletonMono<CardManager>
if (!File.Exists(SeriesListPath)) if (!File.Exists(SeriesListPath))
{ {
//尝试读取Resource包体自带 //尝试读取Resource包体自带
TextAsset tx = Resources.Load<TextAsset>("data/SeriesList.json"); TextAsset tx = Resources.Load<TextAsset>("data/SeriesList");
if (tx == null) if (tx == null)
return; return;
else else
......
...@@ -30,7 +30,7 @@ public class Card ...@@ -30,7 +30,7 @@ public class Card
} }
get get
{ {
if(_img == null) if (_img == null)
{ {
LoadImg(); LoadImg();
} }
......
...@@ -102,7 +102,7 @@ public class Series ...@@ -102,7 +102,7 @@ public class Series
if (!File.Exists(path)) if (!File.Exists(path))
{ {
//尝试读取本地的 //尝试读取本地的
TextAsset tx = Resources.Load<TextAsset>($"data/{Name.Replace("/", "")}/Cards.json"); TextAsset tx = Resources.Load<TextAsset>($"data/{Name.Replace("/", "")}/Cards");
if (tx == null) if (tx == null)
return; return;
else else
...@@ -120,7 +120,7 @@ public class Series ...@@ -120,7 +120,7 @@ public class Series
for (int i = 0; i < data.Count; i++) for (int i = 0; i < data.Count; i++)
{ {
Card card = new Card(data[i]); Card card = new Card(data[i]);
card.CheckImgFile(); //card.CheckImgFile();
AddCard(card); AddCard(card);
} }
} }
......
...@@ -165,16 +165,20 @@ public class DownloadData : SingletonMono<DownloadData> ...@@ -165,16 +165,20 @@ public class DownloadData : SingletonMono<DownloadData>
if (retry < 5) if (retry < 5)
{ {
Debug.Log($"重新尝试:{url} - 次数{retry}"); Debug.Log($"重新尝试:{url} - 次数{retry}");
webRequest.Dispose();
yield return StartCoroutine(DownloadText(url, success, fail, retry + 1)); yield return StartCoroutine(DownloadText(url, success, fail, retry + 1));
} }
else else
{
fail?.Invoke(webRequest.error); fail?.Invoke(webRequest.error);
webRequest.Dispose();
}
yield break; yield break;
} }
// 从网络请求中获取文本内容 // 从网络请求中获取文本内容
string text = webRequest.downloadHandler.text; string text = webRequest.downloadHandler.text;
webRequest.Dispose();
success?.Invoke(text); success?.Invoke(text);
......
...@@ -16,7 +16,7 @@ public class DownlaodImage : SingletonMono<DownlaodImage> ...@@ -16,7 +16,7 @@ public class DownlaodImage : SingletonMono<DownlaodImage>
Queue<Card> DownloadQueue = new Queue<Card>(); Queue<Card> DownloadQueue = new Queue<Card>();
bool downloading; bool downloading;
Texture2D RebirthBG; static Texture2D RebirthBG;
/// <summary> /// <summary>
/// 获取一个图片 /// 获取一个图片
...@@ -29,8 +29,8 @@ public class DownlaodImage : SingletonMono<DownlaodImage> ...@@ -29,8 +29,8 @@ public class DownlaodImage : SingletonMono<DownlaodImage>
if (texture2D == null) if (texture2D == null)
{ {
texture2D = (RebirthBG == null) ? LoadRebirthBG() : RebirthBG; texture2D = (RebirthBG == null) ? LoadRebirthBG() : RebirthBG;
DownloadQueue.Enqueue(card); //DownloadQueue.Enqueue(card);
if (!downloading) StartCoroutine(DownLoadQueue()); //if (!downloading) StartCoroutine(DownLoadQueue());
} }
return texture2D; return texture2D;
...@@ -146,6 +146,7 @@ public class DownlaodImage : SingletonMono<DownlaodImage> ...@@ -146,6 +146,7 @@ public class DownlaodImage : SingletonMono<DownlaodImage>
downloading = true; downloading = true;
while (DownloadQueue.TryDequeue(out Card card)) while (DownloadQueue.TryDequeue(out Card card))
{ {
//Logger.Log($"DownloadQueue:{DownloadQueue.Count}");
//尝试在Resource下加载 //尝试在Resource下加载
string path = ""; string path = "";
var resq = Resources.LoadAsync<Texture2D>(path); var resq = Resources.LoadAsync<Texture2D>(path);
...@@ -161,6 +162,9 @@ public class DownlaodImage : SingletonMono<DownlaodImage> ...@@ -161,6 +162,9 @@ public class DownlaodImage : SingletonMono<DownlaodImage>
else else
//没有则下载 //没有则下载
yield return StartCoroutine(DownloadingImg(card)); yield return StartCoroutine(DownloadingImg(card));
yield return null;
} }
downloading = false; downloading = false;
} }
...@@ -182,10 +186,11 @@ public class DownlaodImage : SingletonMono<DownlaodImage> ...@@ -182,10 +186,11 @@ public class DownlaodImage : SingletonMono<DownlaodImage>
Debug.Log($"重新尝试:{card.Num} - 次数{retry}"); Debug.Log($"重新尝试:{card.Num} - 次数{retry}");
yield return StartCoroutine(DownloadingImg(card, retry + 1)); yield return StartCoroutine(DownloadingImg(card, retry + 1));
} }
webRequest.Dispose();
yield break; yield break;
} }
byte[] bytes = webRequest.downloadHandler.data; byte[] bytes = webRequest.downloadHandler.data;
webRequest.Dispose();
Texture2D texture = null; Texture2D texture = null;
if (card.Type == CardType.Rebirth) if (card.Type == CardType.Rebirth)
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册