Skip to content

Commit 54cb3eb

Browse files
committed
修复网络和并发问题
1 parent 2a1f06a commit 54cb3eb

File tree

14 files changed

+391
-266
lines changed

14 files changed

+391
-266
lines changed

Assets/Scenes/SampleScene.unity

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:d94453170ccc59a5cbce3bf8178b82cd0a138f2922a98ae48bc6f704e9f5a3ac
3-
size 428328
2+
oid sha256:6d50600ca7fb3a786af9d04be879932e6436ac7ec8fd1874e1061043f236be05
3+
size 434634

Assets/Scripts/Http/AvatarManager.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ public void SetAvatar(string url, string absolutePath)
2222
/// 加载并处理本地图片
2323
/// </summary>
2424
private IEnumerator LoadAndProcessImage(string filePath)
25-
{
26-
lock (lockObj) {
27-
Texture2D texture = LoadTextureFromFile(filePath);
28-
if (texture == null)
29-
{
30-
Debug.LogError("无法加载图片: " + filePath);
31-
yield break;
32-
}
33-
34-
Texture2D resizedTexture = ResizeTexture(texture, width, height);
35-
Sprite sprite = TextureToSprite(resizedTexture);
36-
avatarImage.sprite = sprite;
25+
{
26+
Texture2D texture = LoadTextureFromFile(filePath);
27+
if (texture == null)
28+
{
29+
Debug.LogError("无法加载图片: " + filePath);
30+
yield break;
3731
}
32+
Texture2D resizedTexture = ResizeTexture(texture, width, height);
33+
Sprite sprite = TextureToSprite(resizedTexture);
34+
avatarImage.sprite = sprite;
3835

3936
}
4037

@@ -43,7 +40,10 @@ private IEnumerator LoadAndProcessImage(string filePath)
4340
/// </summary>
4441
private Texture2D LoadTextureFromFile(string filePath)
4542
{
46-
byte[] fileData = File.ReadAllBytes(filePath);
43+
byte[] fileData = null;
44+
lock (lockObj) {
45+
fileData = File.ReadAllBytes(filePath);
46+
}
4747
Texture2D texture = new Texture2D(2, 2);
4848
if (texture.LoadImage(fileData))
4949
{

Assets/Scripts/Http/HttpDownloader.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private IEnumerator DownloadCoroutine(string url, string absolutePath, Action<Do
2626
DownloadResult result = new DownloadResult();
2727

2828
// 如果文件存在,跳过, unity读取图片时会占用,删不掉
29-
if (File.Exists(absolutePath))
29+
if (File.Exists(absolutePath) && new FileInfo(absolutePath).Length > 0)
3030
{
3131
result.Success = true;
3232
result.FilePath = absolutePath;
@@ -55,6 +55,9 @@ private IEnumerator DownloadCoroutine(string url, string absolutePath, Action<Do
5555
{
5656
result.Success = false;
5757
result.ErrorMessage = www.error; // 记录错误信息
58+
if (File.Exists(absolutePath)) {
59+
File.Delete(absolutePath);
60+
}
5861
}
5962

6063
// 调用回调函数,返回结果

Assets/Scripts/Live2D/DynamicFadeMotionSetup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ private void LoadFadeMotions()
104104
string modelJsonDir = Path.GetDirectoryName(modelJsonPath);
105105
motionClipsByGroup = new Dictionary<string, List<AnimationClip>>();
106106

107-
motionClipsByGroup = new ();
108107
// 加载每个 Motion 并缓存到字典
109108
for (int i = 0; i < motions.GroupNames.Length; i++)
110109
{

0 commit comments

Comments
 (0)