Tri-Inspector/Runtime/TriValidationResult.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2023-06-16 09:25:07 -04:00
using System;
using UnityEngine;
namespace TriInspector
{
public readonly struct TriValidationResult
{
public static TriValidationResult Valid => new TriValidationResult(true, null, TriMessageType.None);
2023-06-16 09:25:07 -04:00
public TriValidationResult(bool valid, string message, TriMessageType messageType,
Action fixAction = null, GUIContent fixActionContent = null)
{
IsValid = valid;
Message = message;
MessageType = messageType;
2023-06-16 09:25:07 -04:00
FixAction = fixAction;
FixActionContent = fixActionContent;
}
public bool IsValid { get; }
public string Message { get; }
public TriMessageType MessageType { get; }
2023-06-16 09:25:07 -04:00
public Action FixAction { get; }
public GUIContent FixActionContent { get; }
public TriValidationResult WithFix(Action action, string name = null)
{
2023-06-24 10:08:40 -04:00
return new TriValidationResult(IsValid, Message, MessageType, action, new GUIContent(name ?? "Fix"));
2023-06-16 09:25:07 -04:00
}
2023-04-05 13:14:35 -04:00
public static TriValidationResult Info(string error)
{
return new TriValidationResult(false, error, TriMessageType.Info);
}
2023-06-16 09:25:07 -04:00
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,
}
}