Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using Game;
- using UnityEditor;
- using UnityEngine;
- namespace SceneManagement
- {
- [CreateAssetMenu(fileName = "New Portal", menuName = "RPG/Portal")]
- [Serializable]
- public class PortalSo : ScriptableObject
- {
- [SerializeField] private SceneReference sceneToLoad;
- [SerializeField, HideInInspector] private PortalSo portalData;
- public SceneReference SceneToLoad
- {
- get => sceneToLoad;
- set => sceneToLoad = value;
- }
- public PortalSo PortalData
- {
- get => portalData;
- set => portalData = value;
- }
- }
- #if UNITY_EDITOR
- [CustomEditor(typeof(PortalSo))]
- public class PortalSoEditor : Editor
- {
- private PortalSo portalSo;
- private PortalSo[] portalSos;
- private int selectedIndex;
- private string[] portalNames;
- private void OnEnable()
- {
- portalSo = target as PortalSo;
- if (portalSo is null)
- return;
- portalSos = Utilities.GetAllInstances<PortalSo>();
- portalNames = new string[portalSos.Length];
- selectedIndex = portalSos.ToList().IndexOf(portalSo.PortalData);
- for (int i = 0; i < portalSos.Length; i++)
- portalNames[i] = portalSos[i].name;
- }
- public override void OnInspectorGUI()
- {
- base.OnInspectorGUI();
- selectedIndex = EditorGUILayout.Popup(new GUIContent("Portal Data"), selectedIndex, portalNames);
- portalSo.PortalData = portalSos[selectedIndex];
- EditorUtility.SetDirty(target);
- }
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement