Przeglądaj źródła

fix:修改贴图检测方法

chenbin 5 dni temu
rodzic
commit
da07ff80b9

+ 24 - 3
Assets/Scripts/Framework/Editor/Asset/Tools/TextureVerifyTask.cs

@@ -1,9 +1,10 @@
-using UnityEditor;
+using System.IO;
+using UnityEditor;
 using UnityEngine;
 
 namespace XGame.Editor.Asset.Tools
 {
-    internal class TextureVerifyTask
+    public class TextureVerifyTask
     {
         private const string asset_res = "Assets/Res/";
         public void Run()
@@ -44,6 +45,11 @@ namespace XGame.Editor.Asset.Tools
                 Debug.LogError($"贴图名字或者文件夹路径包含中文字符. Path:{path}", AssetDatabase.LoadAssetAtPath<Texture>(path));
                 return false;
             }
+            if (!VerifyFile(path))
+            {
+                Debug.LogError($"贴图文件大小超标. Path:{path}");
+                return false;
+            }
             var textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
             if (textureImporter != null)
             {
@@ -106,9 +112,24 @@ namespace XGame.Editor.Asset.Tools
             }
             return true;
         }
+        /// <summary>
+        /// 检测资源文件大小
+        /// </summary>
+        /// <param name="assetPath"></param>
+        /// <returns></returns>
+        public bool VerifyFile(string assetPath)
+        {
+            const int fileLengthLimit = 4 * 1024 * 1024;
+            var fileInfo = new FileInfo(Path.GetFullPath(assetPath));
+            if (fileInfo.Exists && fileInfo.Length > fileLengthLimit)
+            {
+                return false;
+            }
+            return true;
+        }
         public bool VerifyTextureSize(Texture texture, bool twoPower = false)
         {
-            if (texture == null) return false;
+            if (texture == null) return true;
             if (twoPower)
             {
                 return Get2Flag(texture.width) && Get2Flag(texture.height);