2022-06-06 12:17:31 -04:00
|
|
|
|
using System;
|
|
|
|
|
using Sirenix.OdinInspector.Editor.Validation;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
|
|
|
|
|
namespace TriInspector.Editor.Integrations.Odin
|
|
|
|
|
{
|
|
|
|
|
internal static class TriOdinExtensions
|
|
|
|
|
{
|
|
|
|
|
public static void CopyValidationResultsTo(this TriPropertyTree tree, ValidationResult result)
|
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
tree.EnumerateValidationResults(result.AddIfError);
|
|
|
|
|
tree.EnumerateValidationResults(result.AddIfWarning);
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 04:33:34 -04:00
|
|
|
|
private static void AddIfError(this ValidationResult result,
|
|
|
|
|
TriProperty property, TriValidationResult triResult)
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
if (triResult.MessageType != TriMessageType.Error)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 12:17:31 -04:00
|
|
|
|
#if ODIN_INSPECTOR_3_1
|
2022-05-25 04:33:34 -04:00
|
|
|
|
result.AddError(triResult.Message);
|
2022-06-06 12:17:31 -04:00
|
|
|
|
#else
|
|
|
|
|
if (result.ResultType == ValidationResultType.Error)
|
|
|
|
|
{
|
|
|
|
|
result.Message += Environment.NewLine + triResult.Message;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.ResultType = ValidationResultType.Error;
|
|
|
|
|
result.Message = triResult.Message;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 04:33:34 -04:00
|
|
|
|
private static void AddIfWarning(this ValidationResult result,
|
|
|
|
|
TriProperty property, TriValidationResult triResult)
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
if (triResult.MessageType != TriMessageType.Warning)
|
2022-05-21 04:49:12 -04:00
|
|
|
|
{
|
2022-05-25 04:33:34 -04:00
|
|
|
|
return;
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-06 12:17:31 -04:00
|
|
|
|
#if ODIN_INSPECTOR_3_1
|
2022-05-25 04:33:34 -04:00
|
|
|
|
result.AddWarning(triResult.Message);
|
2022-06-06 12:17:31 -04:00
|
|
|
|
#else
|
|
|
|
|
if (result.ResultType == ValidationResultType.Error)
|
|
|
|
|
{
|
|
|
|
|
// Do not override errors
|
|
|
|
|
}
|
|
|
|
|
else if (result.ResultType == ValidationResultType.Warning)
|
|
|
|
|
{
|
|
|
|
|
result.Message += Environment.NewLine + triResult.Message;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.ResultType = ValidationResultType.Warning;
|
|
|
|
|
result.Message = triResult.Message;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2022-05-21 04:49:12 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|