From 6a5af4e687cd1c85a27fbab8a74068a20152f95c Mon Sep 17 00:00:00 2001 From: VladV Date: Tue, 12 Dec 2023 18:57:47 +0400 Subject: [PATCH] Fix Scene attribute --- Editor.Extras/Drawers/SceneDrawer.cs | 4 ++-- Editor.Extras/Validators/SceneValidator.cs | 15 +++++++++++---- .../Decorators/Decorators_SceneSample.cs | 5 ++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Editor.Extras/Drawers/SceneDrawer.cs b/Editor.Extras/Drawers/SceneDrawer.cs index ff14eb3..45bdd47 100644 --- a/Editor.Extras/Drawers/SceneDrawer.cs +++ b/Editor.Extras/Drawers/SceneDrawer.cs @@ -3,7 +3,7 @@ using TriInspector.Drawers; using UnityEditor; using UnityEngine; -[assembly: RegisterTriAttributeDrawer(typeof(SceneDrawer), TriDrawerOrder.Decorator)] +[assembly: RegisterTriAttributeDrawer(typeof(SceneDrawer), TriDrawerOrder.Decorator, ApplyOnArrayElement = true)] namespace TriInspector.Drawers { @@ -14,7 +14,7 @@ namespace TriInspector.Drawers var type = propertyDefinition.FieldType; if (type != typeof(string)) { - return "Scene attribute can only be used on field of type int or string"; + return "Scene attribute can only be used on field with string type"; } return base.Initialize(propertyDefinition); diff --git a/Editor.Extras/Validators/SceneValidator.cs b/Editor.Extras/Validators/SceneValidator.cs index d6de585..14627bd 100644 --- a/Editor.Extras/Validators/SceneValidator.cs +++ b/Editor.Extras/Validators/SceneValidator.cs @@ -2,7 +2,7 @@ using TriInspector.Validators; using UnityEditor; -[assembly: RegisterTriAttributeValidator(typeof(SceneValidator))] +[assembly: RegisterTriAttributeValidator(typeof(SceneValidator), ApplyOnArrayElement = true)] namespace TriInspector.Validators { @@ -12,7 +12,12 @@ namespace TriInspector.Validators { if (property.FieldType == typeof(string)) { - var value = property.Value; + var value = (string) property.Value; + + if (AssetDatabase.LoadAssetAtPath(value) == null) + { + return TriValidationResult.Error($"{value} not a valid scene"); + } foreach (var scene in EditorBuildSettings.scenes) { @@ -23,14 +28,16 @@ namespace TriInspector.Validators if (!scene.enabled) { - return TriValidationResult.Error($"{value} not in build settings"); + return TriValidationResult.Error($"{value} disabled in build settings"); } return TriValidationResult.Valid; } + + return TriValidationResult.Error($"{value} not added to build settings"); } - return TriValidationResult.Error($"{property.Value} not a valid scene"); + return TriValidationResult.Valid; } } } \ No newline at end of file diff --git a/Editor.Samples/Decorators/Decorators_SceneSample.cs b/Editor.Samples/Decorators/Decorators_SceneSample.cs index a959c5e..a9ee2bd 100644 --- a/Editor.Samples/Decorators/Decorators_SceneSample.cs +++ b/Editor.Samples/Decorators/Decorators_SceneSample.cs @@ -1,7 +1,10 @@ -using TriInspector; +using System.Collections.Generic; +using TriInspector; using UnityEngine; public class Decorators_SceneSample : ScriptableObject { [Scene] public string scene; + + [Scene] public List scenes; } \ No newline at end of file