10 [CustomEditor(typeof(SceneLauncher))]
13 private SerializedProperty sceneMappingProperty;
14 private SerializedProperty buttonSpawnLocationProperty;
15 private SerializedProperty buttonPrefabProperty;
16 private SerializedProperty buttonRowMaxProperty;
18 private void OnEnable()
20 sceneMappingProperty = serializedObject.FindProperty(
"sceneMapping");
21 buttonSpawnLocationProperty = serializedObject.FindProperty(
"ButtonSpawnLocation");
22 buttonPrefabProperty = serializedObject.FindProperty(
"SceneButtonPrefab");
23 buttonRowMaxProperty = serializedObject.FindProperty(
"MaxRows");
25 CheckBuildScenes(sceneMappingProperty);
30 serializedObject.Update();
31 EditorGUILayout.PropertyField(buttonSpawnLocationProperty);
32 EditorGUILayout.PropertyField(buttonPrefabProperty);
33 EditorGUILayout.IntSlider(buttonRowMaxProperty, 1, 10);
34 EditorGUILayout.HelpBox(
"To add scenes to the Scene Mapper by adding scenes in the build window.", MessageType.Info);
35 CheckBuildScenes(sceneMappingProperty);
36 ShowSceneList(sceneMappingProperty);
37 serializedObject.ApplyModifiedProperties();
40 private void ShowSceneList(SerializedProperty sceneList)
43 EditorGUILayout.PropertyField(sceneList);
45 if (EditorBuildSettings.scenes.Length == 0)
47 sceneList.ClearArray();
49 int index = sceneList.arraySize;
51 sceneList.InsertArrayElementAtIndex(index);
52 sceneList.GetArrayElementAtIndex(index).FindPropertyRelative(
"ScenePath").stringValue = SceneManager.GetActiveScene().path;
53 sceneList.GetArrayElementAtIndex(index).FindPropertyRelative(
"IsButtonEnabled").boolValue =
true;
55 EditorBuildSettings.scenes =
new[] {
new EditorBuildSettingsScene(SceneManager.GetActiveScene().path,
true) };
58 if (sceneList.isExpanded)
60 EditorGUI.indentLevel++;
63 for (
int i = 0; i < sceneList.arraySize; i++)
65 EditorGUILayout.BeginHorizontal();
67 GUI.enabled = EditorBuildSettings.scenes[i].enabled;
69 EditorGUILayout.PropertyField(sceneList.GetArrayElementAtIndex(i).FindPropertyRelative(
"IsButtonEnabled"));
73 string path = sceneList.GetArrayElementAtIndex(i).FindPropertyRelative(
"ScenePath").stringValue;
74 var sceneAsset = AssetDatabase.LoadAssetAtPath(path, typeof(SceneAsset)) as SceneAsset;
75 EditorGUILayout.ObjectField(sceneAsset, typeof(SceneAsset),
false);
78 EditorGUILayout.EndHorizontal();
81 EditorGUI.indentLevel--;
85 private void CheckBuildScenes(SerializedProperty list)
87 if (EditorBuildSettings.scenes.Length == 0)
92 bool reBuildList = list.arraySize != EditorBuildSettings.scenes.Length;
97 for (
int i = 0; i < list.arraySize; i++)
99 if (list.GetArrayElementAtIndex(i).FindPropertyRelative(
"ScenePath").stringValue != EditorBuildSettings.scenes[i].path)
109 var oldBuildSceneMapping =
new EditorBuildSettingsScene[list.arraySize];
110 for (
int i = 0; i < list.arraySize; i++)
112 oldBuildSceneMapping[i] =
new EditorBuildSettingsScene
114 path = list.GetArrayElementAtIndex(i).FindPropertyRelative(
"ScenePath").stringValue,
115 enabled = list.GetArrayElementAtIndex(i).FindPropertyRelative(
"IsButtonEnabled").boolValue
122 for (
int i = 0; i < EditorBuildSettings.scenes.Length; i++)
124 list.InsertArrayElementAtIndex(i);
125 list.GetArrayElementAtIndex(i).FindPropertyRelative(
"ScenePath").stringValue = EditorBuildSettings.scenes[i].path;
126 list.GetArrayElementAtIndex(i).FindPropertyRelative(
"IsButtonEnabled").boolValue =
false;
128 for (var j = 0; j < oldBuildSceneMapping.Length; j++)
130 if (oldBuildSceneMapping[j].path == EditorBuildSettings.scenes[i].path)
132 list.GetArrayElementAtIndex(i).FindPropertyRelative(
"IsButtonEnabled").boolValue = oldBuildSceneMapping[j].enabled;