From b93e5c4a3d4d3f71a30df4938fc171134bda8cfd Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 25 Jan 2021 15:09:27 +0900 Subject: [PATCH] add Validation.Extended #680 --- Assets/UniGLTF/MeshUtility/Runtime/Validation.cs | 14 +++++++++++--- .../Editor/FirstPerson/VRMFirstPersonEditor.cs | 10 ---------- .../FirstPerson/VRMFirstPersonValidator.cs | 16 +++++++++++++--- Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Assets/UniGLTF/MeshUtility/Runtime/Validation.cs b/Assets/UniGLTF/MeshUtility/Runtime/Validation.cs index 71bb4ad5f..82aee82aa 100644 --- a/Assets/UniGLTF/MeshUtility/Runtime/Validation.cs +++ b/Assets/UniGLTF/MeshUtility/Runtime/Validation.cs @@ -46,10 +46,11 @@ namespace MeshUtility public readonly String Message; - Validation(ErrorLevels canExport, string message) + Validation(ErrorLevels canExport, string message, Action extended = null) { ErrorLevel = canExport; Message = message; + Extended = extended; } #if UNITY_EDITOR @@ -76,7 +77,14 @@ namespace MeshUtility default: throw new NotImplementedException(); } + + if (Extended != null) + { + Extended(); + } } + + public Action Extended; #endif public static Validation Critical(string msg) @@ -84,9 +92,9 @@ namespace MeshUtility return new Validation(ErrorLevels.Critical, msg); } - public static Validation Error(string msg) + public static Validation Error(string msg, Action action = null) { - return new Validation(ErrorLevels.Error, msg); + return new Validation(ErrorLevels.Error, msg, action); } public static Validation Warning(string msg) diff --git a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonEditor.cs b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonEditor.cs index 0436fc112..53de7e2e6 100644 --- a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonEditor.cs +++ b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonEditor.cs @@ -72,16 +72,6 @@ namespace VRM v.DrawGUI(); isValid = false; } - if (!isValid) - { - if (GUILayout.Button("reset renderers")) - { - m_target.TraverseRenderers(); - } - GUILayout.Space(10); - Separator(); - GUILayout.Space(10); - } base.OnInspectorGUI(); } diff --git a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs index 9d5d422f3..e083c2137 100644 --- a/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs +++ b/Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using MeshUtility; @@ -8,24 +9,25 @@ namespace VRM public static class VRMFirstPersonValidator { public static Transform[] Hierarchy; + static Action extended; public static bool IsValid(this VRMFirstPerson.RendererFirstPersonFlags r, string name, out Validation validation) { if (r.Renderer == null) { - validation = Validation.Error($"{name}.Renderer is null"); + validation = Validation.Error($"{name}.Renderer is null", extended); return false; } if (!Hierarchy.Contains(r.Renderer.transform)) { - validation = Validation.Error($"{name}.Renderer is out of hierarchy"); + validation = Validation.Error($"{name}.Renderer is out of hierarchy", extended); return false; } if (!r.Renderer.EnableForExport()) { - validation = Validation.Error($"{name}.Renderer is not active"); + validation = Validation.Error($"{name}.Renderer is not active", extended); return false; } @@ -37,6 +39,14 @@ namespace VRM { Hierarchy = self.GetComponentsInChildren(true); + extended = () => + { + if (GUILayout.Button("reset VRMFirstPerson.Renderers")) + { + self.TraverseRenderers(); + } + }; + for (int i = 0; i < self.Renderers.Count; ++i) { if (!IsValid(self.Renderers[i], $"[VRMFirstPerson]{self.name}.Renderers[{i}]", out Validation v)) diff --git a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs index 050e4b191..42c995305 100644 --- a/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs @@ -76,7 +76,7 @@ namespace VRM } } - private void Reset() + public void Reset() { SetDefault(); TraverseRenderers();