Browse Source

解决报错

胡佳骏 1 year ago
parent
commit
feafdd05e2
1 changed files with 8 additions and 4 deletions
  1. 8 4
      Assets/Scripts/Download/DownloadManager.cs

+ 8 - 4
Assets/Scripts/Download/DownloadManager.cs

@@ -321,12 +321,16 @@ public class DownloadManager : SingletonMono<DownloadManager>
         }
         StartCoroutine(LoadImage(data, (tex) =>
         {
-            Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
-            if (image != null)
+            if(tex)
             {
-                image.sprite = sprite;
+                Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
+                if (image != null)
+                {
+                    image.sprite = sprite;
+                    image.transform.localScale = new Vector3(1, (float)tex.height / (float)tex.width, 1);
+                }
+
             }
-            image.transform.localScale = new Vector3(1, (float)tex.height / (float)tex.width, 1);
         }));
     }