add ValidationContext

This commit is contained in:
ousttrue 2021-05-07 15:10:26 +09:00
parent 42b7a9b43b
commit 4d4cb0cf14
4 changed files with 114 additions and 34 deletions

View File

@ -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));
}
}
}

View File

@ -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();
}
}
}
}
}
}

View File

@ -26,6 +26,37 @@ namespace UniGLTF
Critical,
}
public struct ValidationContext
{
/// <summary>
/// Messageの発生個所にジャンプするための情報
/// </summary>
public Type Type;
public UnityEngine.Component Context;
/// <summary>
/// DrawGUIから呼び出す。追加のGUIボタンなどを実装する
/// </summary>
public Action Extended;
public static ValidationContext Create<T>(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;
/// <summary>
/// DrawGUIから呼び出す。追加のGUIボタンなどを実装する
/// </summary>
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);
}

View File

@ -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;
}