/// <summary> /// Syncs the settings back to the scene configuration when the scene configuration is modified. /// </summary> protected void SyncBuildSettingsIfRequired() { if (Target.activeConfiguration) { SMSceneConfigurationUtil.SyncWithBuildSettings(Target, sceneLookup); } }
/// <summary> /// Creates a new scene configuration and changes the selection to the new object /// </summary> /// <returns> /// The created configuration /// </returns> /// <typeparam name='C'> /// The type of configuration we want to create /// </typeparam> protected static C CreateConfiguration <C>() where C : SMSceneConfigurationBase { var name = typeof(C).Name; var path = "Assets"; foreach (UObject obj in Selection.GetFiltered(typeof(UObject), SelectionMode.Assets)) { path = AssetDatabase.GetAssetPath(obj); if (File.Exists(path)) { path = Path.GetDirectoryName(path); } break; } path = AssetDatabase.GenerateUniqueAssetPath(path + "/" + name + ".asset"); C configuration = ScriptableObject.CreateInstance <C> (); AssetDatabase.CreateAsset(configuration, path); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = configuration; if (SMSceneConfigurationUtil.FindConfigurations().Count == 1) { configuration.activeConfiguration = true; EditorBuildSettings.scenes = new EditorBuildSettingsScene[0]; } return(configuration); }
/// <summary> /// Draws the label indicating if the currently edited scene configuration is the currently active configuration. /// </summary> /// <seealso cref="SMSceneConfigurtion.activeConfiguration"/> protected void ConfigurationStatusGUI() { if (Invalid) { EditorGUILayout.BeginHorizontal(boxStyle); GUILayout.Label(string.Empty, warnIconStyle); GUILayout.Label("The configuration is invalid."); GUILayout.FlexibleSpace(); if (GUILayout.Button("Fix configuration")) { FixConfiguration(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); if (Target.activeConfiguration) { GUILayout.Label("This configuration will be used by the game."); } else { EditorGUILayout.BeginHorizontal(); GUILayout.Label("The configuration is currently not active."); GUILayout.FlexibleSpace(); if (GUILayout.Button("Activate")) { SMSceneConfigurationUtil.EnsureActiveConfiguration(Target, true); SyncBuildSettingsIfRequired(); } EditorGUILayout.EndHorizontal(); } }
public virtual void OnEnable() { sceneLookup = SMSceneConfigurationUtil.CreateSceneLookup(); List <string> sceneNames = new List <string>(sceneLookup.Keys); sceneNames.Sort(); scenes = sceneNames.ToArray(); CheckConfiguration(); }
protected void CheckConfiguration() { invalidScreens = Array.FindAll(Target.screens, screen => !sceneLookup.ContainsKey(screen)); invalidLevels = Array.FindAll(Target.levels, level => !sceneLookup.ContainsKey(level)); if (Target.activeConfiguration) { fixActiveState = SMSceneConfigurationUtil.FindConfigurations().Exists(configuration => configuration.activeConfiguration && configuration != Target); } UpdateGuid(); }
public static void VerifyConfigurations() // 修改配置文件 { bool successful = true; List <SMSceneConfigurationBase> configurations = SMSceneConfigurationUtil.FindConfigurations(); Dictionary <string, string> lookup = SMSceneConfigurationUtil.FindAllUnityScene(); HashSet <string> validScenes = new HashSet <string>(); foreach (string scene in lookup.Keys) { validScenes.Add(scene); } SMSceneConfigurationBase activeConfiguration = null; int activeConfigurations = 0; foreach (SMSceneConfigurationBase configuration in configurations) { successful &= configuration.IsValid(validScenes); if (configuration.activeConfiguration) { activeConfigurations++; activeConfiguration = configuration; } } if (activeConfigurations == 0) { Debug.LogWarning("Currently no scene configuration is active. This will lead to issues when your game is " + "started as Scene Manager doesn't know which scene configuration it should load. Please activate one " + "of your scene configurations. To activate a scene configuration, select it in the project view " + "and then click on the 'Activate' button in the inspector."); successful = false; } else if (activeConfigurations > 1) { Debug.LogWarning( "Currently more than one scene configuration is active. This will lead to issues when your game is " + "started as Scene Manager doesn't know which scene configuration it should load. Please select the configuration you " + "want to keep active in the project view and then press the 'Fix Configuration' button in the inspector. This will deactivate all other " + "scene configurations. To activate another scene configuration, select it in the project view " + "and then click on the 'Activate' button in the inspector."); successful = false; } else { SMSceneConfigurationUtil.SyncWithBuildSettings(activeConfiguration, lookup); } if (successful) { Debug.Log("All your scene configurations are valid."); } }
/// <summary> /// Fixes configuration issues such as multiple active configurations or removed scenes /// </summary> protected void FixConfiguration() { List <UnityEngine.Object> objects = new List <UnityEngine.Object>(SMSceneConfigurationUtil.FindConfigurations().ToArray()); CUUndoUtility.RegisterUndo(objects.ToArray(), "Fixing configuration"); UpdateGuid(); FixInvalidScenes(); if (fixActiveState) { SMSceneConfigurationUtil.EnsureActiveConfiguration(Target, false); } invalidScreens = null; invalidLevels = null; fixActiveState = false; EditorUtility.SetDirty(Target); }
/// <summary> /// Creates a new scene configuration and changes the selection to the new object /// </summary> /// <returns> /// The created configuration /// </returns> /// <typeparam name='C'> /// The type of configuration we want to create /// </typeparam> protected static C CreateConfiguration <C>() where C : SMSceneConfigurationBase { string path = AssetDatabase.GetAssetPath(Selection.activeObject); C configuration = ScriptableObject.CreateInstance <C>(); AssetDatabase.CreateAsset(configuration, AssetDatabase.GenerateUniqueAssetPath(path + "/" + typeof(C).Name + ".asset")); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = configuration; if (SMSceneConfigurationUtil.FindConfigurations().Count == 1) { configuration.activeConfiguration = true; EditorBuildSettings.scenes = new EditorBuildSettingsScene[0]; } return(configuration); }
public override void OnInspectorGUI() // 画 GUI { ProDraw(); if (Target.activeConfiguration) { GUILayout.Label("游戏使用该配置".AddYellow()); } else { EditorGUILayout.BeginHorizontal(); GUILayout.Label("游戏不是使用这个配置"); GUILayout.FlexibleSpace(); if (GUILayout.Button("使用该配置")) { SMSceneConfigurationUtil.EnsureActiveConfiguration(Target, true); SyncBuildSettingsIfRequired(); } EditorGUILayout.EndHorizontal(); } MyCreate.Box(() => { sceneListHeight = CUResizableContainer.BeginVertical(sceneListHeight); sceneListData = CUListControl.SelectionList(sceneListData, scenes, sceneRenderer); CUResizableContainer.EndVertical(); bool isChooseScene = !sceneListData.Empty; GUI.enabled = isChooseScene; // 判断有没有点击场景 int width = Screen.width / 3 - 10; MyGUI.Heng(() => { MyGUI.Button(isChooseScene ? "关卡".AddGreen() : "关卡", width, ChangeToLevel); MyGUI.Button(isChooseScene ? "场景".AddOrange() : "关卡", width, ChangeToScreen); MyGUI.Button("Ignore", width, ChangeToIgnore); }); GUI.enabled = !sceneListData.Empty && IsScreen(scenes[sceneListData.First]);// 判断点击的场景是否标记 Screen MyGUI.Heng(() => { MyGUI.Button("开始场景", width, ChangeToFirstScreen); MyGUI.Button("关卡完成后场景", width, ChangeToFirstScreenAfterLevel); GUI.enabled = sceneListData.Selection.Count == 1; MyGUI.Button("打开", width, () => { OpenScene(sceneListData); }); }); }); MyGUI.AddSpace(4); GUI.enabled = true; MyCreate.Box(() => { levelListHeight = CUResizableContainer.BeginVertical(levelListHeight); levelListData = CUListControl.SelectionList(levelListData, Target.levels, levelRenderer, "关卡"); CUResizableContainer.EndVertical(); GUI.enabled = !levelListData.Empty; MyGUI.Heng(() => { MyGUI.AddSpace(); MyGUI.Button("First", MoveToFirst); MyGUI.Button("↑", MoveUp); MyGUI.Button("↓", MoveDown); MyGUI.Button("Last", MoveToLast); }); GUI.enabled = true; }); }
public override void OnInspectorGUI() // 画 GUI { ProDraw(); if (Target.activeConfiguration) { GUILayout.Label("游戏使用该配置".AddYellow()); } else { EditorGUILayout.BeginHorizontal(); GUILayout.Label("游戏不是使用这个配置"); GUILayout.FlexibleSpace(); if (GUILayout.Button("使用该配置")) { SMSceneConfigurationUtil.EnsureActiveConfiguration(Target, true); SyncBuildSettingsIfRequired(); } EditorGUILayout.EndHorizontal(); } int workWidth = Screen.width / 3 - 34; WorkflowActionEnum targetWork = Target.actionAfterGroup; bool isLevel = targetWork == WorkflowActionEnum.LoadNextLevel; MyGUI.Heng(() => { MyGUI.Text("组结束,加载:"); MyGUI.Button(isLevel?"[下一关卡]".AddGreen(): "下一关卡".AddLightGreen(), workWidth, () => { if (!isLevel) { ChangeToWorkflowAction(WorkflowActionEnum.LoadNextLevel); } }); MyGUI.AddSpace(2); MyGUI.Button(isLevel ? "标记场景".AddLightGreen() : "[标记场景]".AddGreen(), workWidth, () => { if (isLevel) { ChangeToWorkflowAction(WorkflowActionEnum.LoadScreen); } }); MyGUI.AddSpace(); GUI.enabled = sceneListData.Selection.Count == 1; MyGUI.Button("打开", workWidth - 25, () => { OpenScene(sceneListData); }); GUI.enabled = true; }); MyCreate.Box(() => { sceneListHeight = CUResizableContainer.BeginVertical(sceneListHeight); sceneListData = CUListControl.SelectionList(sceneListData, scenes, sceneRenderer); CUResizableContainer.EndVertical(); bool isChooseScene = !sceneListData.Empty; GUI.enabled = isChooseScene; // 判断有没有点击场景 int width = Screen.width / 3 - 10; MyGUI.Heng(() => { MyGUI.Button(isChooseScene ? "关卡".AddGreen() : "关卡", width, ChangeToLevel); MyGUI.Button(isChooseScene ? "场景".AddOrange() : "关卡", width, ChangeToScreen); MyGUI.Button("Ignore", width, ChangeToIgnore); }); GUI.enabled = !sceneListData.Empty && IsScreen(scenes[sceneListData.First]);// 判断点击的场景是否标记 Screen MyCreate.Heng(() => { MyGUI.Button("开始场景", width, ChangeToFirstScreen); MyGUI.Button("关卡完成后场景", width, ChangeToFirstScreenAfterLevel); GUI.enabled = GUI.enabled && Target.actionAfterGroup == WorkflowActionEnum.LoadScreen;// 是否选择了标记场景 MyGUI.Button("完成组后场景", width, ChangeToFirstScreenAfterGroup); }); }); MyGUI.AddSpace(4); GUI.enabled = true; MyCreate.Box(() => { levelListHeight = CUResizableContainer.BeginVertical(levelListHeight); EditorGUILayout.BeginHorizontal(); groupListWidth = CUResizableContainer.BeginHorizontal(groupListWidth); int lastGroup = groupListData.First; groupListData = CUListControl.SelectionList(groupListData, Target.groups, groupRenderer, "组"); if (lastGroup != groupListData.First) { levelListData.ClearSelection(); } CUResizableContainer.EndHorizontal(); GUI.enabled = SelectedGroup != null; levelListData = CUListControl.SelectionList(levelListData, currentGroupLevels, levelRenderer, "关卡"); GUI.enabled = true; EditorGUILayout.EndHorizontal(); CUResizableContainer.EndVertical(); MyGUI.Heng(() => { MyGUI.Button("+", AddGroup); GUI.enabled = !groupListData.Empty && Target.groups.Length > 1; MyGUI.Button("-", RemoveGroup); GUI.enabled = !groupListData.Empty; MyGUI.Button("改名", RenameGroup); GUI.enabled = true; MyGUI.AddSpace(); GUI.enabled = !levelListData.Empty; MyGUI.Button("First", MoveToFirst); MyGUI.Button("↑", MoveUp); MyGUI.Button("↓", MoveDown); MyGUI.Button("Last", MoveToLast); GUI.enabled = true; }); }); }