diff --git a/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs b/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs index 051bad319..f1735075d 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/Validation/HumanoidValidator.cs @@ -169,7 +169,7 @@ namespace UniGLTF var jaw = animator.GetBoneTransform(HumanBodyBones.Jaw); if (jaw != null) { - yield return Validation.Warning(ValidationMessages.JAW_BONE_IS_INCLUDED.Msg()); + yield return Validation.Warning(ValidationMessages.JAW_BONE_IS_INCLUDED.Msg(), ValidationContext.Create(jaw)); } } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/Validation/ValidationExtensions.cs b/Assets/UniGLTF/Editor/UniGLTF/Validation/ValidationExtensions.cs index 817a4d7a6..8dce0d313 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/Validation/ValidationExtensions.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/Validation/ValidationExtensions.cs @@ -1,10 +1,50 @@ using System; using UnityEditor; +using UnityEngine; namespace UniGLTF { public static class ValidationExtensions { + static GUIContent s_info; + public static GUIContent Info + { + get + { + if (s_info == null) + { + s_info = EditorGUIUtility.IconContent("console.infoicon"); + } + return s_info; + } + } + + static GUIContent s_warn; + public static GUIContent Warn + { + get + { + if (s_warn == null) + { + s_warn = EditorGUIUtility.IconContent("console.warnicon"); + } + return s_warn; + } + } + + static GUIContent s_error; + public static GUIContent Error + { + get + { + if (s_error == null) + { + s_error = EditorGUIUtility.IconContent("console.erroricon"); + } + return s_error; + } + } + public static void DrawGUI(this Validation self) { if (string.IsNullOrEmpty(self.Message)) @@ -12,26 +52,38 @@ namespace UniGLTF return; } - switch (self.ErrorLevel) + using (new GUILayout.VerticalScope(GUI.skin.box)) { - case ErrorLevels.Info: - EditorGUILayout.HelpBox(self.Message, MessageType.Info); - break; - case ErrorLevels.Warning: - EditorGUILayout.HelpBox(self.Message, MessageType.Warning); - break; - case ErrorLevels.Critical: - case ErrorLevels.Error: - EditorGUILayout.HelpBox(self.Message, MessageType.Error); - break; + using (new GUILayout.HorizontalScope()) + { + switch (self.ErrorLevel) + { + case ErrorLevels.Info: + EditorGUILayout.LabelField(Info, GUILayout.Width(30), GUILayout.Height(30)); + break; - default: - throw new NotImplementedException(); - } + case ErrorLevels.Warning: + EditorGUILayout.LabelField(Warn, GUILayout.Width(30), GUILayout.Height(30)); + break; - if (self.Extended != null) - { - self.Extended(); + case ErrorLevels.Error: + EditorGUILayout.LabelField(Error, GUILayout.Width(30), GUILayout.Height(30)); + break; + } + + using (new GUILayout.VerticalScope()) + { + EditorGUILayout.LabelField(self.Message); + if (self.Context.Context != null) + { + EditorGUILayout.ObjectField(self.Context.Context, self.Context.Type, true); + } + if (self.Context.Extended != null) + { + self.Context.Extended(); + } + } + } } } } diff --git a/Assets/UniGLTF/Runtime/UniGLTF/Validation/Validation.cs b/Assets/UniGLTF/Runtime/UniGLTF/Validation/Validation.cs index 01913b209..b6fa5ad92 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/Validation/Validation.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/Validation/Validation.cs @@ -26,6 +26,37 @@ namespace UniGLTF Critical, } + public struct ValidationContext + { + /// + /// Messageの発生個所にジャンプするための情報 + /// + public Type Type; + public UnityEngine.Component Context; + + /// + /// DrawGUIから呼び出す。追加のGUIボタンなどを実装する + /// + public Action Extended; + + public static ValidationContext Create(T c) where T : UnityEngine.Component + { + return new ValidationContext + { + Type = typeof(T), + Context = c, + }; + } + + public static ValidationContext Create(Action extended) + { + return new ValidationContext + { + Extended = extended, + }; + } + } + public struct Validation { public readonly ErrorLevels ErrorLevel; @@ -52,34 +83,31 @@ namespace UniGLTF public readonly String Message; - /// - /// DrawGUIから呼び出す。追加のGUIボタンなどを実装する - /// - public Action Extended; + public ValidationContext Context; - Validation(ErrorLevels canExport, string message, Action extended = null) + Validation(ErrorLevels canExport, string message, ValidationContext context = default) { ErrorLevel = canExport; Message = message; - Extended = extended; + Context = context; } - public static Validation Critical(string msg) + public static Validation Critical(string msg, ValidationContext context = default) { - return new Validation(ErrorLevels.Critical, msg); + return new Validation(ErrorLevels.Critical, msg, context); } - public static Validation Error(string msg, Action action = null) + public static Validation Error(string msg, ValidationContext context = default) { - return new Validation(ErrorLevels.Error, msg, action); + return new Validation(ErrorLevels.Error, msg, context); } - public static Validation Warning(string msg) + public static Validation Warning(string msg, ValidationContext context = default) { - return new Validation(ErrorLevels.Warning, msg); + return new Validation(ErrorLevels.Warning, msg, context); } - public static Validation Info(string msg) + public static Validation Info(string msg, ValidationContext context = default) { return new Validation(ErrorLevels.Info, msg); } diff --git a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs index ed134b2d1..048159d81 100644 --- a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs +++ b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs @@ -15,19 +15,19 @@ namespace VRM { if (r.Renderer == null) { - validation = Validation.Error($"{name}.Renderer is null", extended); + validation = Validation.Error($"{name}.Renderer is null", ValidationContext.Create(extended)); return false; } if (!Hierarchy.Contains(r.Renderer.transform)) { - validation = Validation.Error($"{name}.Renderer is out of hierarchy", extended); + validation = Validation.Error($"{name}.Renderer is out of hierarchy", ValidationContext.Create(extended)); return false; } if (!r.Renderer.EnableForExport()) { - validation = Validation.Error($"{name}.Renderer is not active", extended); + validation = Validation.Error($"{name}.Renderer is not active", ValidationContext.Create(extended)); return false; }