From 2428630ec9a8a5f66aefc352198073fe3eba4785 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 6 May 2021 15:31:05 +0900 Subject: [PATCH] DIFFERENT_MATERIAL_COUNT --- .../ExportDialog/MeshExportValidator.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs index ca5ea8a25..becf276b1 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ExportDialog/MeshExportValidator.cs @@ -10,12 +10,6 @@ namespace UniGLTF [Serializable] public class MeshExportValidator : ScriptableObject { - public enum Messages - { - MATERIALS_CONTAINS_NULL, - UNKNOWN_SHADER, - } - public static Mesh GetMesh(Renderer r) { if (r is SkinnedMeshRenderer smr) @@ -197,15 +191,31 @@ namespace UniGLTF return null; } + public enum Messages + { + DIFFERENT_MATERIAL_COUNT, + MATERIALS_CONTAINS_NULL, + UNKNOWN_SHADER, + } + public IEnumerable Validate(GameObject ExportRoot) { foreach (var info in Meshes) { // invalid materials.len - - // material null - if (info.Renderer.sharedMaterials.Any(x => x == null)) + if (info.Renderer.sharedMaterials.Length < info.Mesh.subMeshCount) { + // すべての submesh に material が割り当てられていない + yield return Validation.Error(Messages.DIFFERENT_MATERIAL_COUNT.Msg()); + } + else if (info.Renderer.sharedMaterials.Length > info.Mesh.subMeshCount) + { + // 未使用の material がある + yield return Validation.Warning(Messages.DIFFERENT_MATERIAL_COUNT.Msg()); + } + else if (info.Renderer.sharedMaterials.Any(x => x == null)) + { + // material に null が含まれる(unity で magenta になっているはず) yield return Validation.Error($"{info.Renderer}: {Messages.MATERIALS_CONTAINS_NULL.Msg()}"); } }