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

优化图片列表加载

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