// Returns the number of Scenes that are currently present in the Assets/Scenes/Levels directory. public static int countScenes() { levelsFetched = AssetFetcher.GetLevels(); levelsArray = levelsFetched.ToArray <string> (); return(levelsArray.Length); }
/** * Generates GUI elements given a type of generator. * The GenData it points to should not be shared by multiple UI elements. */ private void GeneratorGUI(Type generatorType, string buttonName, GenerationData data) { SpriteGeneratorBuilder builder = ObjectController.GetContext(). AddComponent <SpriteGeneratorBuilder>().CreateBuilder(generatorType); GUILayout.BeginHorizontal(); // A dropdown list which displays all the PNG files that can be used as spites // See AssetController for IList <string> spriteList = AssetFetcher.GetSprites(); spriteList.Insert(0, "Default Sprite"); string[] sprites = spriteList.ToArray <string>(); GUILayout.Label("Sprite:"); data.idx = EditorGUILayout.Popup(data.idx, sprites); GUILayout.EndHorizontal(); if (GUILayout.Button(new GUIContent(buttonName))) { // We use the Builder pattern so that the GUI logic can get updated easily builder = builder.ByCoord(0.0f, 0.0f); if (data.idx != 0) { builder = builder.ByPath(sprites [data.idx]); } if (data.width != "") { builder = builder.ByWidth(int.Parse(data.width)); } if (data.height != "") { builder = builder.ByHeight(int.Parse(data.height)); } if (lightsUI.addLight) { builder = builder.ByLightData(lightsUI.lightData); } // We append the file name of the sprite at the end so the type of // the object is easily identifiable string finalName = "object-" + sprites[data.idx].Replace(" ", "-") + fileIncrement++; // The Builder is the component that should persist as a Script Component // together with the object. All the fields of the Builder *must* be serializable // to persist with the saved scene. The Builder can encasulate all behaviour // of the generators. GameObject gameObject = builder.Build().GenerateObject(finalName); gameObject.AddComponent <SpriteGeneratorBuilder>().ByBuilder(builder); } UnityEngine.Object.DestroyImmediate(builder); }
public string Serialize() { if (sceneName != null) { AssetFetcher.WorkOnLevel(sceneName); } LinkedList <GameObject> objects = GetSceneObjects(); string serializedObjects = serializeObjects(objects); return(serializedObjects); }
// Method that will make sure all currently loaded scenes will // be unloaded. public static void unloadScenes() { levelsFetched = AssetFetcher.GetLevels(); levelsArray = levelsFetched.ToArray <string> (); Scene sceneToUnload; foreach (string level in levelsArray) { sceneToUnload = SceneManager.GetSceneByName(level); EditorSceneManager.CloseScene(sceneToUnload, true); } // foreach }
public void OnGUI() { // Level buttons. GUILayout.Label("Select a level below to work on:"); foreach (string level in AssetFetcher.GetLevels()) { if (GUILayout.Button(new GUIContent(level, ""))) { AssetFetcher.WorkOnLevel(level); } } // Only let the level designer operate if it's a level. if (SceneManager.GetActiveScene().name.Equals("Main")) { return; } foreach (IMenu menu in menus) { menu.Display(); } }
public void OnGUI() { minSize = new Vector2(225, 0); // Level buttons. GUILayout.Label("Select a level below to work on:"); // Get all levels currently in the game. IList <string> levelList = AssetFetcher.GetLevels(); // Popup() expects a string[] array, so convert it. string[] levels = levelList.ToArray <string>(); // optionChosenByUser initialised to 0, so the dropdown will be blank. // After an option is chosen for the first time, we update this. optionChosenByUser--; optionChosenByUser = EditorGUILayout.Popup(optionChosenByUser, levels); // Index is returned and levels start from 1 so incrementing it. optionChosenByUser++; if (GUILayout.Button(new GUIContent("Work!"))) { EditorSceneManager.MarkAllScenesDirty(); EditorSceneManager.SaveOpenScenes(); AssetFetcher.WorkOnLevel("Level" + optionChosenByUser); } // Only let the level designer operate if it's a level. // ie. If the scene is called "Main" then it is not a level. // See the file hierarchy to understand. if (SceneManager.GetActiveScene().name.Equals("Main")) { return; } if (GUILayout.Button(new GUIContent("Create a new level."))) { EditorSceneManager.MarkAllScenesDirty(); EditorSceneManager.SaveOpenScenes(); Scene newScene = SceneHandler.createScene(); // Unload the scenes so we can create a new one. SceneHandler.unloadScenes(); // Calling countScenes() inside SceneHandler to find the new // filename to save our scene with. int currentNoOfLevels = SceneHandler.countScenes(); currentNoOfLevels++; LevelGenerator levelGenerator = new LevelGenerator(); levelGenerator.GenerateLevel(); EditorSceneManager.SaveScene(newScene, "Assets/Scenes/Levels/Level" + currentNoOfLevels + ".unity"); } EditorGUILayout.BeginScrollView(Vector2.zero); foreach (IMenu menu in menus) { menu.Display(); } EditorGUILayout.EndScrollView(); ListenForPickerEvents(); }