|
|
@@ -0,0 +1,73 @@
|
|
|
+using UnityEditor;
|
|
|
+using UnityEngine;
|
|
|
+using System.Collections.Generic;
|
|
|
+
|
|
|
+public class WebGLTextureMaxSizeTool
|
|
|
+{
|
|
|
+ private const int TargetMaxSize = 1024;
|
|
|
+
|
|
|
+ [MenuItem("Tools/Force All Textures MaxSize = 1024")]
|
|
|
+ public static void ForceWebGLTextureMaxSize()
|
|
|
+ {
|
|
|
+ string[] guids = AssetDatabase.FindAssets("t:Texture2D", new[] { "Assets" });
|
|
|
+
|
|
|
+ int changedCount = 0;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ AssetDatabase.StartAssetEditing();
|
|
|
+
|
|
|
+ foreach (string guid in guids)
|
|
|
+ {
|
|
|
+ string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
|
+
|
|
|
+ TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter;
|
|
|
+ if (importer == null)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ // 跳过 Sprite Atlas(可选)
|
|
|
+ //if (importer.textureType == TextureImporterType.Sprite && importer.spriteImportMode == SpriteImportMode.Multiple)
|
|
|
+ //{
|
|
|
+ // // 如果你不想跳过,可以删掉这段
|
|
|
+ //}
|
|
|
+
|
|
|
+ TextureImporterPlatformSettings webglSettings =
|
|
|
+ importer.GetPlatformTextureSettings("WebGL");
|
|
|
+
|
|
|
+ bool needReimport = false;
|
|
|
+
|
|
|
+ if (!webglSettings.overridden)
|
|
|
+ {
|
|
|
+ webglSettings.overridden = true;
|
|
|
+ needReimport = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (webglSettings.maxTextureSize != TargetMaxSize)
|
|
|
+ {
|
|
|
+ webglSettings.maxTextureSize = TargetMaxSize;
|
|
|
+ needReimport = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (needReimport)
|
|
|
+ {
|
|
|
+ importer.SetPlatformTextureSettings(webglSettings);
|
|
|
+ changedCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ AssetDatabase.StopAssetEditing();
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ AssetDatabase.Refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ EditorUtility.DisplayDialog(
|
|
|
+ "WebGL Texture Tool",
|
|
|
+ $"处理完成\n\n修改贴图数量:{changedCount}",
|
|
|
+ "OK"
|
|
|
+ );
|
|
|
+
|
|
|
+ Debug.Log($"[WebGLTextureMaxSizeTool] 修改贴图数量:{changedCount}");
|
|
|
+ }
|
|
|
+}
|