public static void CheckTextureQriginalSize(Texture texture) { if(texture == null) return; int width = -1; int height = -1; string path = AssetDatabase.GetAssetPath(texture); TextureImporter importerTexture = AssetImporter.GetAtPath(path) as TextureImporter; if(importerTexture == null) throw new System.Exception(string.Format("GetRawTexSize failed: importer is null, path={0}", path)); object[] args = new object[2] { 0, 0 }; MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); mi.Invoke(importerTexture, args); width = (int)args[0]; height = (int)args[1]; if (width > 1024 || height > 1024) { EditorGUILayout.HelpBox(string.Format("{0}的纹理尺寸大于1024宽:{1} 高:{2}",texture.name, width, height), MessageType.Warning); } }
TexturePostprocessor检查texture原始大小
最新推荐文章于 2022-04-01 21:36:24 发布