Tri-Inspector/Editor.Extras/Validators/SceneValidator.cs
2022-07-19 18:23:44 +03:00

36 lines
1.0 KiB
C#

using TriInspector;
using TriInspector.Validators;
using UnityEditor;
[assembly: RegisterTriAttributeValidator(typeof(SceneValidator))]
namespace TriInspector.Validators
{
public class SceneValidator : TriAttributeValidator<SceneAttribute>
{
public override TriValidationResult Validate(TriProperty property)
{
if (property.FieldType == typeof(string))
{
var value = property.Value;
foreach (var scene in EditorBuildSettings.scenes)
{
if (!property.Comparer.Equals(value, scene.path))
{
continue;
}
if (!scene.enabled)
{
return TriValidationResult.Error($"{value} not in build settings");
}
return TriValidationResult.Valid;
}
}
return TriValidationResult.Error($"{property.Value} not a valid scene");
}
}
}