/// <summary> /// Clears the temporary inspectors. /// </summary> public void ClearTemporary() { buildingPlace = null; pathway = null; spawnPoint = null; levelDescription = null; }
/// <summary> /// Sets the active level. /// </summary> /// <param name="levelPrefab">Level prefab.</param> public void SetActiveLevel(GameObject level) { LevelDescriptionInspector oldLevel = levelFolder.GetComponentInChildren <LevelDescriptionInspector>(); // Destroy old level description if (oldLevel != null) { DestroyImmediate(oldLevel.gameObject); } // Update level description level.transform.SetParent(levelFolder, false); level.transform.SetAsFirstSibling(); levelChooser.currentLevel = level; }
/// <summary> /// Sets the active level. /// </summary> /// <param name="levelPrefab">Level prefab.</param> public void SetActiveLevel(GameObject levelPrefab) { if (levelPrefab != null) { LevelDescriptionInspector oldLevel = levelFolder.GetComponentInChildren <LevelDescriptionInspector>(); // Destroy old level description if (oldLevel != null) { DestroyImmediate(oldLevel.gameObject); } // Create new level description GameObject level = Instantiate(levelPrefab, levelFolder); level.name = levelPrefab.name; level.transform.SetAsFirstSibling(); levelChooser.currentLevel = level; // Add to allowed levels list if (levelChooser.levelsPrefabs.Contains(levelPrefab) == false) { levelChooser.levelsPrefabs.Add(levelPrefab); } } }
/// <summary> /// Updates the stuff data. /// </summary> private void UpdateStuff() { // Set editor visual theme editorGuiSkin = (GUISkin)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/EditorGuiSkin.guiskin", typeof(GUISkin)); // Set labels for prebas. Label will use in picker window string[] prefabs; prefabs = AssetDatabase.FindAssets("", new string[] { "Assets/TD2D/Prefabs/Map/LevelMaps" }); foreach (string str in prefabs) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str)); AssetDatabase.SetLabels(obj, new string[] { Lables.map }); } prefabs = AssetDatabase.FindAssets("", new string[] { "Assets/TD2D/Prefabs/Map/SpawnIcons" }); foreach (string str in prefabs) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str)); AssetDatabase.SetLabels(obj, new string[] { Lables.spawnIcon }); } prefabs = AssetDatabase.FindAssets("", new string[] { "Assets/TD2D/Prefabs/Map/CaptureIcons" }); foreach (string str in prefabs) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str)); AssetDatabase.SetLabels(obj, new string[] { Lables.captureIcon }); } prefabs = AssetDatabase.FindAssets("", new string[] { "Assets/TD2D/Prefabs/Towers/Towers" }); foreach (string str in prefabs) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str)); AssetDatabase.SetLabels(obj, new string[] { Lables.tower }); } prefabs = AssetDatabase.FindAssets("", new string[] { "Assets/TD2D/Prefabs/Levels/Icons" }); foreach (string str in prefabs) { Object obj = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(str)); AssetDatabase.SetLabels(obj, new string[] { Lables.levelIcon }); } // Search for basic inspectors inspectors.mapFolder = GameObject.FindObjectOfType <MapFolderInspector>(); inspectors.towersFolder = GameObject.FindObjectOfType <TowersFolderInspector>(); inspectors.pathwaysFolder = GameObject.FindObjectOfType <PathwaysFolderInspector>(); inspectors.wavesInfo = GameObject.FindObjectOfType <WavesInfoInspector>(); inspectors.levelManager = GameObject.FindObjectOfType <LevelManagerInspector>(); inspectors.levelChooser = GameObject.FindObjectOfType <LevelChooseInspector>(); // Set visual content contents.levelsFolder = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Levels.png", typeof(Texture)), "Create new levels"); contents.mapFolder = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/ChooseMap.png", typeof(Texture)), "Game map visual settings"); contents.towersFolder = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddTower.png", typeof(Texture)), "Towers placement and settings"); contents.pathwaysFolder = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddPathway.png", typeof(Texture)), "Enemies pathways creating"); contents.conditionsFolder = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Conditions.png", typeof(Texture)), "Level conditions settings"); contents.newLevel = new GUIContent("Create new level", (Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/CreateNewLevel.png", typeof(Texture)), "Create new scene with tower defense map and open it"); contents.chooseMap = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/ChooseMap.png", typeof(Texture)), "Choose image for level map"); contents.spawnIcon = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddSpawnIcon.png", typeof(Texture)), "Add spawn place icon to level map"); contents.captureIcon = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddCaptureIcon.png", typeof(Texture)), "Add capture place icon to level map"); contents.addTower = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddTower.png", typeof(Texture)), "Add tower building place. The tower type may be choosen after that"); contents.buildingPlace = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddTower.png", typeof(Texture)), "Focus on building place of this tower"); contents.defendPoint = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/DefendPoint.png", typeof(Texture)), "Focus on defend point of this tower"); contents.tower = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Tower.png", typeof(Texture)), "Choose tower"); contents.addPathway = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddPathway.png", typeof(Texture)), "Add pathway for enemy waves. It consist of spawn point and waypoints. Dublicate waypoints to create a path"); contents.capturePoint = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/AddCapturePoint.png", typeof(Texture)), "Add capture point. The pathways must end inside capture point area"); contents.spawnPoint = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/SpawnPoint.png", typeof(Texture)), "Choose spawn point of this pathway"); contents.waypoint = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Waypoint.png", typeof(Texture)), "Add waypoint to this pathway"); contents.next = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Next.png", typeof(Texture))); contents.prev = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Prev.png", typeof(Texture))); contents.add = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Add.png", typeof(Texture))); contents.remove = new GUIContent((Texture)AssetDatabase.LoadAssetAtPath("Assets/TD2D/Sprites/Editor/Remove.png", typeof(Texture))); // Check what kind of scene opened now if (inspectors.mapFolder != null && inspectors.towersFolder != null && inspectors.pathwaysFolder != null && inspectors.levelManager != null && inspectors.wavesInfo != null) { // This is level map scene myState = MyState.LevelMap; string sceneName = SceneManager.GetActiveScene().name; currentLevelName = sceneName; // Focus camera on level map GameObject levelMap = GameObject.Find("LevelMap"); if (levelMap != null) { CameraFocus(levelMap); } // Get random enemies list enemiesList.Clear(); for (int i = 0; i < inspectors.levelManager.enemiesList.Count; ++i) { if (inspectors.levelManager.enemies.Contains(inspectors.levelManager.enemiesList[i]) == true) { enemiesList.Add(true); } else { enemiesList.Add(false); } } // Get tower upgrades list towersList.Clear(); for (int i = 0; i < inspectors.levelManager.towersList.Count; ++i) { if (inspectors.levelManager.towers.Contains(inspectors.levelManager.towersList[i]) == true) { towersList.Add(true); } else { towersList.Add(false); } } // Get spells list spellsList.Clear(); for (int i = 0; i < inspectors.levelManager.spellsList.Count; ++i) { if (inspectors.levelManager.spells.Contains(inspectors.levelManager.spellsList[i]) == true) { spellsList.Add(true); } else { spellsList.Add(false); } } } else { if (inspectors.levelChooser != null) { // This is a level description scene myState = MyState.LevelDescription; string sceneName = SceneManager.GetActiveScene().name; // Display active level description inspectors.levelChooser.SetActiveLevel(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/TD2D/Prefabs/Levels/" + currentLevelName + ".prefab")); LevelDescriptionInspector levelDescriptionInspector = GameObject.FindObjectOfType <LevelDescriptionInspector>(); if (levelDescriptionInspector != null) { // Focus on level description Selection.activeObject = levelDescriptionInspector.gameObject; CameraFocus(levelDescriptionInspector.gameObject); } } else { // This is not a Tower Defense level scene myState = MyState.Disabled; currentLevelName = ""; } } }