Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Validation.Extended #691

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Assets/UniGLTF/MeshUtility/Runtime/Validation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public bool CanExport

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
Expand All @@ -76,17 +77,24 @@ public void DrawGUI()
default:
throw new NotImplementedException();
}

if (Extended != null)
{
Extended();
}
}

public Action Extended;
#endif

public static Validation Critical(string msg)
{
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)
Expand Down
10 changes: 0 additions & 10 deletions Assets/VRM/Editor/FirstPerson/VRMFirstPersonEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ public override void OnInspectorGUI()
v.DrawGUI();
isValid = false;
}
if (!isValid)
{
if (GUILayout.Button("reset renderers"))
{
m_target.TraverseRenderers();
}
GUILayout.Space(10);
Separator();
GUILayout.Space(10);
}

base.OnInspectorGUI();
}
Expand Down
16 changes: 13 additions & 3 deletions Assets/VRM/Editor/FirstPerson/VRMFirstPersonValidator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MeshUtility;
Expand All @@ -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;
}

Expand All @@ -37,6 +39,14 @@ public static IEnumerable<Validation> Validate(this VRMFirstPerson self, GameObj
{
Hierarchy = self.GetComponentsInChildren<Transform>(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))
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRM/Runtime/FirstPerson/VRMFirstPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void SetDefault()
}
}

private void Reset()
public void Reset()
{
SetDefault();
TraverseRenderers();
Expand Down