private static void OnGUINetworkManager() { // assign offline scene in NetworkManager if (EditorBuildSettings.scenes.Length > 1) { var nm = FindObjectOfType <UnityEngine.Networking.NetworkManager> (); string name = GetSceneNameFromPath(EditorBuildSettings.scenes [1].path); if (Utilities2.DisabledButtonWithCalculatedSize(nm != null && nm.offlineScene != name, "Assign offline scene in Network Manager")) { nm.offlineScene = name; Debug.Log("Assigned offline scene in Network Manager : " + nm.offlineScene); EditorUtility.SetDirty(nm); } GUILayout.Space(10); if (null == nm) { EditorGUILayout.HelpBox("Network Manager not found in scene.", MessageType.Warning); } } else { EditorGUILayout.HelpBox("Offline scene is not added to build settings.", MessageType.Warning); } }
public static List <string> GetDemoScenePaths() { return(new List <string> () { "Assets/" + Utilities2.GetAssetRootFolderName() + "/GamePlay/Scenes/demo.unity" }); }
// private static string RemoveStringFromEnd( string str, string strToRemove ) { // // // } private void OnGUIDemoScenes() { GUILayout.Label("Would you like to also add demo scenes to build settings ?", m_centeredLabelStyle); GUILayout.Label("This is recommended if you are installing for the first time.", m_centeredLabelStyle); GUILayout.Space(20); var demoScenes = GetDemoScenePaths(); var buildSettingsScenes = EditorBuildSettings.scenes.ToList(); int numNotAdded = 0; GUILayout.Label("Available demo scenes:"); GUILayout.Space(10); m_scrollViewPosDemoScenes = EditorGUILayout.BeginScrollView(m_scrollViewPosDemoScenes, GUILayout.MaxHeight(150)); foreach (var demoScene in demoScenes) { if (buildSettingsScenes.Any(s => s.path == demoScene)) { // already in build settings GUILayout.Label("(added) " + demoScene); } else { GUILayout.Label("+ " + demoScene); numNotAdded++; } } EditorGUILayout.EndScrollView(); GUILayout.Space(20); if (Utilities2.DisabledButtonWithCalculatedSize(numNotAdded > 0, "Add demo scenes")) { AddDemoScenesToBuildSettings(); } }
private static bool OnGUIEnsureStartupSceneIsLoaded(string warningMsg) { if (0 == EditorBuildSettings.scenes.Length) { EditorGUILayout.HelpBox("There are no scenes in build settings", MessageType.Warning); return(false); } var activeScene = EditorSceneManager.GetActiveScene(); if (activeScene.buildIndex != 0) { // this is not the startup scene EditorGUILayout.HelpBox(warningMsg, MessageType.Warning); GUILayout.Space(10); if (Utilities2.ButtonWithCalculatedSize("Open startup scene")) { if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { EditorSceneManager.OpenScene(EditorBuildSettings.scenes [0].path, OpenSceneMode.Single); // clear list // this.ClearFoundPrefabsList (); } EditorGUIUtility.ExitGUI(); } } else { return(true); } return(false); }
private void OnGUISetupScenes() { string text = "The package requires that you have 2 separate scenes.\n" + "First scene is the startup scene which" + "is loaded only once at startup, and the second is offline scene."; // GUILayout.Label ( text, GUILayout.MaxWidth(this.position.size.x - 15) ); GUILayout.Label(text, GUILayout.Height(40)); GUILayout.Space(10); GUILayout.Label("You can create new scenes, or use existing ones."); GUILayout.Space(20); DisplayForScene("startup scene", "MyStartupScene", ref m_startupScenePath, ref m_startupSceneChosenOption, GetDefaultStartupScenePath()); GUILayout.Space(20); DisplayForScene("offline scene", "MyOfflineScene", ref m_offlineScenePath, ref m_offlineSceneChosenOption, GetDefaultOfflineScenePath()); GUILayout.Space(50); // check if current build settings are valid // if they aren't, add button to configure them // foreach (var s in EditorBuildSettings.scenes) { // GUILayout.Label (s.path); // } bool areSettingsValid = false; if (!string.IsNullOrEmpty(m_startupScenePath) && !string.IsNullOrEmpty(m_offlineScenePath)) { // user has selected scenes // check if current settings are valid if (m_startupScenePath == m_offlineScenePath) { // the scenes are the same EditorGUILayout.HelpBox("Scenes are the same.", MessageType.Error); } else { areSettingsValid = AreSceneBuildSettingsValid(m_startupScenePath, m_offlineScenePath); if (!areSettingsValid) { GUILayout.Label("Scene build settings are not cofigured. You have to configure them before proceeding.\n" + "NOTE: This will modify your build settings"); // GUILayout.Label("Cofigure scenes.\nThis will modify your build settings, and assign offline scene in " + // "Network Manager."); if (Utilities2.ButtonWithCalculatedSize("Configure scene settings")) { ConfigureBuildSettings(m_startupScenePath, m_offlineScenePath); } GUILayout.Space(10); } } } GUILayout.Space(15); // if (areSettingsValid) { if (OnGUIEnsureStartupSceneIsLoaded("Startup scene must be opened to setup Network Manager")) { OnGUINetworkManager(); } // } // enable/disable next button this.GetCurrentStep().allowsNext = areSettingsValid; }
private void OnGUICreatePrefabs() { string s = "This asset is consisted of so called modules (which are actually prefabs)." + " Each prefab has it's own features which bring functionality to the game.\n\n" + "To see all available prefabs, click Find prefabs.\n" + "After that, you can select which ones you want to create.\n" + "When you are done, you can create them by clicking Create prefabs."; GUILayout.Label(s); GUILayout.Space(20); GUILayout.Label("Note that this may take a while depending on the size of your project."); if (Utilities2.ButtonWithCalculatedSize("Find prefabs")) { this.FindPrefabs(); } GUILayout.Space(20); // display some stats GUILayout.Label("Found prefabs: " + m_foundPrefabs.Count + ", new: " + m_foundPrefabs.Count(item => !item.isAlreadyCreated)); GUILayout.Space(10); // display found prefabs in a scroll view // m_scrollViewPosFoundPrefabs = EditorGUILayout.BeginScrollView( m_scrollViewPosFoundPrefabs, // GUILayout.MinHeight( m_foundPrefabs.Count * 15 ), GUILayout.MaxHeight( 450 ), GUILayout.Width(this.position.width - 15) ); for (int i = 0; i < m_foundPrefabs.Count; i++) { var foundPrefab = m_foundPrefabs [i]; string text = foundPrefab.prefab.name + " " + foundPrefab.prefabPath; if (foundPrefab.isAlreadyCreated) { // this one is already created GUILayout.Label(text); } else { // add option to select him foundPrefab.checkboxState = GUILayout.Toggle(foundPrefab.checkboxState, text); } } // EditorGUILayout.EndScrollView (); GUILayout.Space(20); if (OnGUIEnsureStartupSceneIsLoaded("This is not the startup scene, so prefabs can not be created.")) { // this is the startup scene m_groupPrefabsAfterCreating = EditorGUILayout.Toggle("group prefabs after creating", m_groupPrefabsAfterCreating); // prefabs can be created if (Utilities2.DisabledButtonWithCalculatedSize(m_foundPrefabs.Any(p => p.checkboxState && !p.isAlreadyCreated), "Create prefabs")) { this.CreatePrefabs(); if (m_groupPrefabsAfterCreating) { Utilities.GroupAllModules(); Utilities.GroupAllMenusAndCanvases(); } // clear list // this.ClearFoundPrefabsList (); } } GUILayout.Space(10); }
public static string GetDefaultOfflineScenePath() { return("Assets/" + Utilities2.GetAssetRootFolderName() + "/General/Scenes/offline_scene.unity"); }
private static void DisplayForScene(string sceneDisplayName, string sceneDefaultName, ref string selectedScenePath, ref int selectedOption, string defaultScenePath) { GUILayout.Label("selected " + sceneDisplayName + ": " + selectedScenePath); int oldOption = selectedOption; string[] options = new string[] { "Create new", "Use current", "Choose existing" }; selectedOption = GUILayout.SelectionGrid(selectedOption, options, 1, EditorStyles.radioButton); if (selectedOption != oldOption) { // option changed // reset scene path selectedScenePath = ""; } // string stringToRemove = ""; switch (selectedOption) { case 0: if (Utilities2.ButtonWithCalculatedSize("Create " + sceneDisplayName)) { if (CreateScene("Create " + sceneDisplayName, sceneDefaultName, ref selectedScenePath)) { // copy default scene to selected path // bool copied = false; try { FileUtil.CopyFileOrDirectory(defaultScenePath, selectedScenePath); AssetDatabase.Refresh(); // so that scene can be recognized // copied = true ; Debug.Log("Copied " + defaultScenePath + " to " + selectedScenePath); } catch (System.Exception ex) { // copied = false; // reset scene path selectedScenePath = ""; Debug.LogException(ex); } } EditorGUIUtility.ExitGUI(); } break; case 1: selectedScenePath = EditorSceneManager.GetActiveScene().path; // stringToRemove = "Assets/"; // if (selectedScenePath.StartsWith (stringToRemove)) // selectedScenePath = selectedScenePath.Substring (stringToRemove.Length); break; case 2: if (Utilities2.ButtonWithCalculatedSize("Select " + sceneDisplayName)) { SelectScene("Select " + sceneDisplayName, ref selectedScenePath); EditorGUIUtility.ExitGUI(); } // EditorGUILayout.ObjectField( "", null, typeof(SceneAsset), false ); break; } // // remove trailing '.unity', because scene paths inside build settings don't have it // stringToRemove = ".unity" ; // if (selectedScenePath.EndsWith (stringToRemove)) { // selectedScenePath = selectedScenePath.Substring (0, selectedScenePath.Length - stringToRemove.Length); // } }
void OnGUI() { // create style for centered label if (null == m_centeredLabelStyle) { m_centeredLabelStyle = new GUIStyle(GUI.skin.label); m_centeredLabelStyle.alignment = TextAnchor.MiddleCenter; } if (m_currentStepIndex < 0) { return; } var currentStep = m_steps [m_currentStepIndex]; // display title GUILayout.Space(5); GUILayout.Label(currentStep.title, m_centeredLabelStyle); GUILayout.Space(40); currentStep.scrollViewPos = EditorGUILayout.BeginScrollView(currentStep.scrollViewPos, GUILayout.MaxWidth(this.position.width - 15)); currentStep.onGUI(); EditorGUILayout.EndScrollView(); // draw footer => previous, next buttons GUILayout.Space(60); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (currentStep.previousIndex >= 0) { if (Utilities2.DisabledButton(currentStep.allowsPrevious, "Back")) { m_currentStepIndex = currentStep.previousIndex; } } if (currentStep.canSkip) { if (GUILayout.Button("Skip")) { m_currentStepIndex = currentStep.nextIndex; } } if (currentStep.nextIndex < 0) { // last step if (Utilities2.DisabledButton(currentStep.allowsNext, "Finish")) { this.Close(); } } else { if (Utilities2.DisabledButton(currentStep.allowsNext, "Next")) { m_currentStepIndex = currentStep.nextIndex; } } EditorGUILayout.EndHorizontal(); }