public void Singleton() { if (_instance == null) { _instance = this; SceneManager.sceneLoaded += OnSceneLoadedEvent; SceneManager.sceneUnloaded += OnSceneUnloadedEvent; } else if (_instance != this) { Destroy(gameObject); } }
void OnDisable() {// delegate was added in singleton SceneManager.sceneLoaded -= OnSceneLoadedEvent; SceneManager.sceneUnloaded -= OnSceneUnloadedEvent; _instance = null; }
protected virtual void OnEnable() { targetScript = target as UISceneManager; if (UISceneManager.Instance == null) { targetScript.Singleton(); } m_openTab = serializedObject.FindProperty("openTab"); m_startScene = serializedObject.FindProperty("startScene"); m_previousScene = serializedObject.FindProperty("previousScene"); m_currnetScene = serializedObject.FindProperty("currentScene"); m_onSceneLoaded = serializedObject.FindProperty("onSceneLoaded"); m_onSceneUnloaded = serializedObject.FindProperty("onSceneUnloaded"); //m_startLoadingScreen = serializedObject.FindProperty("startLoadingScreen"); m_loadingScreens = new ReorderableList(serializedObject, serializedObject.FindProperty("loadingScreens"), false, true, true, true); m_sceneProperties = new ReorderableList(serializedObject, serializedObject.FindProperty("sceneProperties"), true, true, true, true); //m_sceneProperties.elementHeight = EditorGUIUtility.singleLineHeight * 7.5f; m_sceneProperties.drawHeaderCallback = (Rect rect) => { //EditorGUI.LabelField(rect, "Scenes List"); }; m_sceneProperties.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { SceneArrayGUI(rect, index, isActive, isFocused); }; m_sceneProperties.onSelectCallback = (ReorderableList l) => { var prefab = l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("scene").objectReferenceValue as SceneAsset; if (prefab) { EditorGUIUtility.PingObject(prefab); } }; m_sceneProperties.onRemoveCallback = (ReorderableList l) => { if (l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("scene").objectReferenceValue != null) { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete element " + l.serializedProperty.GetArrayElementAtIndex(l.index).FindPropertyRelative("scene").objectReferenceValue.name + " from Scenes list?", "Yes", "No")) { ReorderableList.defaultBehaviours.DoRemoveButton(l); } } else { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete element " + l.index + " from Scenes list?", "Yes", "No")) { ReorderableList.defaultBehaviours.DoRemoveButton(l); } } }; m_sceneProperties.elementHeightCallback = delegate(int index) { var element = m_sceneProperties.serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("onSceneLoaded"); var elementHeight = 110 + EditorGUI.GetPropertyHeight(element); return(elementHeight); }; //m_loadingScreens.elementHeight = EditorGUIUtility.singleLineHeight * 5.5f; m_loadingScreens.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "Loading Screens List"); }; m_loadingScreens.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { LoadingScreensArrayGUI(rect, index, isActive, isFocused); }; m_loadingScreens.onRemoveCallback = (ReorderableList l) => { if (EditorUtility.DisplayDialog("Warning!", "Are you sure you want to delete element " + (l.index + 1) + " from Loading Screens list?", "Yes", "No")) { ReorderableList.defaultBehaviours.DoRemoveButton(l); } }; m_loadingScreens.elementHeightCallback = delegate(int index) { var element = m_loadingScreens.serializedProperty.GetArrayElementAtIndex(index).FindPropertyRelative("onLoading"); var elementHeight = 90 + EditorGUI.GetPropertyHeight(element); return(elementHeight); }; }