public static void CheckDefault_Material() { var defaultMat = AssetDatabase.LoadAssetAtPath <Material>("Assets/ArtResources/DefaultMaterial.mat"); string[] ids = AssetDatabase.FindAssets("t:prefab"); Debuger.Log("Materials count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string matPath = AssetDatabase.GUIDToAssetPath(ids[i]); var go = AssetDatabase.LoadAssetAtPath <GameObject>(matPath); var renderers = go.GetComponentsInChildren <Renderer>(); if (renderers == null || renderers.Length == 0) { continue; } for (int j = 0; j < renderers.Length; j++) { if (renderers[j].sharedMaterial == null || renderers[j].sharedMaterial.name == "Default-Material") { Debuger.LogErrorFormat(nameof(CheckResources), "Default-Material: " + go.name, go); renderers[j].sharedMaterial = defaultMat; } } } AssetDatabase.SaveAssets(); }
public static void SpriteSizeGreater1024() { string[] ids = AssetDatabase.FindAssets("t:sprite"); Debuger.Log("sprite count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string spritePath = AssetDatabase.GUIDToAssetPath(ids[i]); var sprite = AssetDatabase.LoadAssetAtPath <Sprite>(spritePath); if (sprite.rect.size.x >= 512 || sprite.rect.size.y >= 512) { Debuger.LogErrorFormat(nameof(CheckResources), "sprite size >= 512: " + sprite.name + " path: " + spritePath, sprite); } } }
public static void CheckLLLL() { string[] ids = AssetDatabase.FindAssets("t:material"); Debuger.Log("Materials count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string matPath = AssetDatabase.GUIDToAssetPath(ids[i]); var mat = AssetDatabase.LoadAssetAtPath <Material>(matPath); if (mat.shader.name.ToLower().Contains("Legacy".ToLower()) && mat.shader.name.ToLower().Contains("Specular".ToLower())) { Debuger.LogErrorFormat(nameof(CheckResources), "Legacy Shaders_Bumped Specular Shader: " + mat.name + " path: " + matPath, mat); } } }
public static void SpriteMipmapOrRW() { string[] ids = AssetDatabase.FindAssets("t:sprite"); Debuger.Log("sprite count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string spritePath = AssetDatabase.GUIDToAssetPath(ids[i]); var sprite = AssetDatabase.LoadAssetAtPath <Sprite>(spritePath); if (sprite.texture.mipmapCount > 1) { Debuger.LogErrorFormat(nameof(CheckResources), "sprite mipmap: " + sprite.name + " path: " + spritePath, sprite); } TextureImporter texIm = (TextureImporter)AssetImporter.GetAtPath(spritePath); if (texIm.isReadable) { texIm.isReadable = false; AssetDatabase.ImportAsset(spritePath, ImportAssetOptions.ForceUpdate); Debuger.LogErrorFormat(nameof(CheckResources), spritePath, sprite.texture); } } }
public static void CheckStandard() { var defaultMat = AssetDatabase.LoadAssetAtPath <Material>("Assets/ArtResources/DefaultMaterial.mat"); string[] ids = AssetDatabase.FindAssets("t:material"); Debuger.Log("Materials count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string matPath = AssetDatabase.GUIDToAssetPath(ids[i]); var mat = AssetDatabase.LoadAssetAtPath <Material>(matPath); if (mat.shader.name.ToLower().Equals("standard")) { Debuger.LogErrorFormat(nameof(CheckResources), "Standard Shader: " + mat.name + " path: " + matPath, mat); mat.shader = Shader.Find("Standard-s"); } } AssetDatabase.SaveAssets(); ids = AssetDatabase.FindAssets("t:Model"); Debuger.Log("Models count: " + ids.Length); for (int i = 0; i < ids.Length; i++) { string matPath = AssetDatabase.GUIDToAssetPath(ids[i]); var fbx = AssetDatabase.LoadAssetAtPath <GameObject>(matPath); var meshRenderers = fbx.GetComponentsInChildren <Renderer>(true); foreach (var meshRenderer in meshRenderers) { var mats = meshRenderer.sharedMaterials; for (int j = 0; j < mats.Length; j++) { var material = mats[j]; if (material == null) { //Debuger.LogError("null material: " + rootGameObject.name + " meshRenderer:" + meshRenderer.name); continue; } if (material.shader.name.ToLower().Equals("standard")) { Debuger.LogErrorFormat(nameof(CheckResources), "Standard Shader: " + fbx.name + " meshRenderer:" + meshRenderer.name, fbx); meshRenderer.sharedMaterials[j] = defaultMat; } } } } for (int i = 0; i < SceneManager.sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); foreach (var rootGameObject in scene.GetRootGameObjects()) { var meshRenderers = rootGameObject.GetComponentsInChildren <Renderer>(true); foreach (var meshRenderer in meshRenderers) { var mats = meshRenderer.sharedMaterials; for (int j = 0; j < mats.Length; j++) { var material = mats[j]; if (material == null) { //Debuger.LogError("null material: " + rootGameObject.name + " meshRenderer:" + meshRenderer.name); continue; } if (material.shader.name.ToLower().Equals("standard")) { Debuger.LogError("Standard Shader: " + "Scene:" + scene.name + " " + rootGameObject.name + " meshRenderer:" + meshRenderer.name); meshRenderer.sharedMaterials[j] = defaultMat; EditorUtility.SetDirty(meshRenderer.gameObject); } } if (meshRenderer.sharedMaterial == null) { //Debuger.LogError("null material: " + rootGameObject.name + " meshRenderer:" + meshRenderer.name); continue; } if (meshRenderer.sharedMaterial.shader.name.ToLower().Equals("standard")) { Debuger.LogError("Standard Shader: " + "Scene:" + scene.name + " " + rootGameObject.name + " meshRenderer:" + meshRenderer.name); meshRenderer.sharedMaterial = defaultMat; EditorUtility.SetDirty(meshRenderer.gameObject); EditorSceneManager.MarkSceneDirty(scene); EditorSceneManager.SaveScene(scene); } } } } AssetDatabase.SaveAssets(); }