using System; using System.Collections.Generic; using UnityEngine.UIElements; #if UNITY_EDITOR using UnityEditor; #endif [Serializable] public class SwitchableScene { public int index; } #if UNITY_EDITOR // custom property drawer [CustomPropertyDrawer(typeof(SwitchableScene))] public class SwitchableSceneDrawer : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) { // Get the SceneSwitcher component if (SceneSwitcher.Instance == null) { return new Label("SceneSwitcher component not found in the scene."); } // create dropdown based on the SceneSwitcher options var root = new VisualElement(); // Get the list of scenes List<(string name, int index)> scenes = SceneSwitcher.Instance.GetScenes(); // create dropdown var indexProperty = property.FindPropertyRelative("index"); var dropdown = new PopupField("Scene", scenes.ConvertAll(t => t.name), scenes[indexProperty.intValue].name); dropdown.RegisterValueChangedCallback(evt => { indexProperty.intValue = scenes.FindIndex(t => t.name == evt.newValue); indexProperty.serializedObject.ApplyModifiedProperties(); }); root.Add(dropdown); return root; } } #endif