mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Move TriValidationResult to runtime assembly
This commit is contained in:
parent
2303292347
commit
849da7e8a7
@ -19,7 +19,7 @@ namespace TriInspector.Drawers
|
|||||||
{
|
{
|
||||||
var stack = new TriElement();
|
var stack = new TriElement();
|
||||||
stack.AddChild(new TriInfoBoxElement($"InlineEditor valid only on Object fields",
|
stack.AddChild(new TriInfoBoxElement($"InlineEditor valid only on Object fields",
|
||||||
MessageType.Error));
|
TriMessageType.Error));
|
||||||
stack.AddChild(next);
|
stack.AddChild(next);
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
|
@ -9,9 +9,10 @@ namespace TriInspector.Elements
|
|||||||
private readonly GUIContent _message;
|
private readonly GUIContent _message;
|
||||||
private readonly Color _color;
|
private readonly Color _color;
|
||||||
|
|
||||||
public TriInfoBoxElement(string message, MessageType type = MessageType.None, Color? color = null)
|
public TriInfoBoxElement(string message, TriMessageType type = TriMessageType.None, Color? color = null)
|
||||||
{
|
{
|
||||||
_message = new GUIContent(message, EditorGUIUtilityProxy.GetHelpIcon(type));
|
var messageType = GetMessageType(type);
|
||||||
|
_message = new GUIContent(message, EditorGUIUtilityProxy.GetHelpIcon(messageType));
|
||||||
_color = color ?? GetColor(type);
|
_color = color ?? GetColor(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,14 +31,14 @@ namespace TriInspector.Elements
|
|||||||
GUI.Label(position, _message, Styles.InfoBoxContent);
|
GUI.Label(position, _message, Styles.InfoBoxContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Color GetColor(MessageType type)
|
private static Color GetColor(TriMessageType type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case MessageType.Error:
|
case TriMessageType.Error:
|
||||||
return new Color(1f, 0.4f, 0.4f);
|
return new Color(1f, 0.4f, 0.4f);
|
||||||
|
|
||||||
case MessageType.Warning:
|
case TriMessageType.Warning:
|
||||||
return new Color(1f, 0.8f, 0.2f);
|
return new Color(1f, 0.8f, 0.2f);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -45,6 +46,18 @@ namespace TriInspector.Elements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MessageType GetMessageType(TriMessageType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case TriMessageType.None: return MessageType.None;
|
||||||
|
case TriMessageType.Info: return MessageType.Info;
|
||||||
|
case TriMessageType.Warning: return MessageType.Warning;
|
||||||
|
case TriMessageType.Error: return MessageType.Error;
|
||||||
|
default: return MessageType.None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class Styles
|
private static class Styles
|
||||||
{
|
{
|
||||||
public static readonly GUIStyle InfoBoxBg;
|
public static readonly GUIStyle InfoBoxBg;
|
||||||
|
@ -13,7 +13,7 @@ namespace TriInspector
|
|||||||
{
|
{
|
||||||
private static readonly IReadOnlyList<TriValidationResult> EmptyValidationResults =
|
private static readonly IReadOnlyList<TriValidationResult> EmptyValidationResults =
|
||||||
new List<TriValidationResult>();
|
new List<TriValidationResult>();
|
||||||
|
|
||||||
private readonly TriPropertyDefinition _definition;
|
private readonly TriPropertyDefinition _definition;
|
||||||
private readonly int _propertyIndex;
|
private readonly int _propertyIndex;
|
||||||
private readonly ITriPropertyParent _parent;
|
private readonly ITriPropertyParent _parent;
|
||||||
@ -43,7 +43,7 @@ namespace TriInspector
|
|||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public string DisplayName => DisplayNameContent.text;
|
public string DisplayName => DisplayNameContent.text;
|
||||||
|
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public GUIContent DisplayNameContent
|
public GUIContent DisplayNameContent
|
||||||
{
|
{
|
||||||
@ -231,7 +231,7 @@ namespace TriInspector
|
|||||||
// actualize
|
// actualize
|
||||||
PropertyTree.SerializedObject.Update();
|
PropertyTree.SerializedObject.Update();
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
PropertyTree.RequestValidation();
|
PropertyTree.RequestValidation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,10 +325,10 @@ namespace TriInspector
|
|||||||
{
|
{
|
||||||
_validationResults = _definition.Validators
|
_validationResults = _definition.Validators
|
||||||
.Select(it => it.Validate(this))
|
.Select(it => it.Validate(this))
|
||||||
.Where(it => it.MessageType != MessageType.None)
|
.Where(it => !it.IsValid)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_childrenProperties != null)
|
if (_childrenProperties != null)
|
||||||
{
|
{
|
||||||
foreach (var childrenProperty in _childrenProperties)
|
foreach (var childrenProperty in _childrenProperties)
|
||||||
|
@ -38,28 +38,4 @@ namespace TriInspector
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public abstract TriValidationResult Validate(TriValue<T> propertyValue);
|
public abstract TriValidationResult Validate(TriValue<T> propertyValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly struct TriValidationResult
|
|
||||||
{
|
|
||||||
public static TriValidationResult Valid => new TriValidationResult(null, MessageType.None);
|
|
||||||
|
|
||||||
private TriValidationResult(string message, MessageType messageType)
|
|
||||||
{
|
|
||||||
Message = message;
|
|
||||||
MessageType = messageType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Message { get; }
|
|
||||||
public MessageType MessageType { get; }
|
|
||||||
|
|
||||||
public static TriValidationResult Error(string error)
|
|
||||||
{
|
|
||||||
return new TriValidationResult(error, MessageType.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TriValidationResult Warning(string error)
|
|
||||||
{
|
|
||||||
return new TriValidationResult(error, MessageType.Warning);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
36
Runtime/TriValidationResult.cs
Normal file
36
Runtime/TriValidationResult.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace TriInspector
|
||||||
|
{
|
||||||
|
public readonly struct TriValidationResult
|
||||||
|
{
|
||||||
|
public static TriValidationResult Valid => new TriValidationResult(true, null, TriMessageType.None);
|
||||||
|
|
||||||
|
private TriValidationResult(bool valid, string message, TriMessageType messageType)
|
||||||
|
{
|
||||||
|
IsValid = valid;
|
||||||
|
Message = message;
|
||||||
|
MessageType = messageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsValid { get; }
|
||||||
|
public string Message { get; }
|
||||||
|
public TriMessageType MessageType { get; }
|
||||||
|
|
||||||
|
public static TriValidationResult Error(string error)
|
||||||
|
{
|
||||||
|
return new TriValidationResult(false, error, TriMessageType.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TriValidationResult Warning(string error)
|
||||||
|
{
|
||||||
|
return new TriValidationResult(false, error, TriMessageType.Warning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum TriMessageType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
}
|
||||||
|
}
|
3
Runtime/TriValidationResult.cs.meta
Normal file
3
Runtime/TriValidationResult.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 428f8881a0d34edf8148591af6f9a0e7
|
||||||
|
timeCreated: 1642525992
|
Loading…
Reference in New Issue
Block a user