private void DuplicateLevel() { if (HasNewLocationNameAssigned() == true) { Debug.LogError("Has No New Location Name Assigned"); return; } if (gameLevelToCreateDuplicateOf == null) { Debug.LogError("Location Required to Duplicate"); return; } GameLevelToolkitWindow toolkit = GameLevelToolkitWindow.GetRefreshedToolkitWindow(); string projectPathName = GameLevelToolkitWindow.GetProjectPathStringWithSlash(); //Check if there is a location already existing with that name. GameLevel existingGameLevel = (GameLevel)AssetDatabase.LoadAssetAtPath("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + newGameLevelName + "/" + newGameLevelName + ".asset", typeof(GameLevel)); if (existingGameLevel != null) { Debug.LogError("Location With Same Name Already Exists"); return; } //Create the Location Resource GameLevel gameLevelResource = GameLevelData.CreateInstance <GameLevel>(); AssetDatabase.CreateAsset(GameLevel.CreateInstance <GameLevel>(), "Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + "Existing " + SceneAndResourceFolderName.folderNameValue + "/" + newGameLevelName + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); GameLevel createdGameLevel = (GameLevel)AssetDatabase.LoadAssetAtPath("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + "Existing " + SceneAndResourceFolderName.folderNameValue + "/" + newGameLevelName + ".asset", typeof(GameLevel)); createdGameLevel.gameLevelName = newGameLevelName; createdGameLevel.assignedScenesDirectory = "Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/" + newGameLevelName; createdGameLevel.levelDependencies = gameLevelToCreateDuplicateOf.levelDependencies; createdGameLevel.assignedScenes = gameLevelToCreateDuplicateOf.assignedScenes; GameLevelToolkitWindow.GetGameLevelsData().gameLevelsCreatedByUser.Add(createdGameLevel); //Create the Scene Directory string scenesFolder = AssetDatabase.CreateFolder("Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue, newGameLevelName); //Copy the Existing Scenes for (int i = 0; i < gameLevelToCreateDuplicateOf.assignedScenes.Count; i++) { string sceneToCopy = gameLevelToCreateDuplicateOf.assignedScenesDirectory + "/" + gameLevelToCreateDuplicateOf.gameLevelName + "_" + gameLevelToCreateDuplicateOf.assignedScenes[i] + ".unity"; string destination = createdGameLevel.assignedScenesDirectory + "/" + newGameLevelName + "_" + gameLevelToCreateDuplicateOf.assignedScenes[i] + ".unity"; FileUtil.CopyFileOrDirectory(sceneToCopy, destination); } EditorUtility.SetDirty(createdGameLevel); EditorUtility.SetDirty(toolkit.gameLevelsData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private void CreateLevel() { GameLevelToolkitWindow toolkit = GameLevelToolkitWindow.GetRefreshedToolkitWindow(); string projectPathName = GameLevelToolkitWindow.GetProjectPathStringWithSlash(); //Check If the Location Already Exists GameLevel existingLocation = (GameLevel)AssetDatabase.LoadAssetAtPath("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + gameLevelName + "/" + gameLevelName + ".asset", typeof(GameLevel)); if (existingLocation != null) { Debug.LogError("Level With Same Name Already Exists"); return; } //First We Will need to make sure we have all the required data before proceeding if (gameLevelName == null || gameLevelName == "") { Debug.LogError("Level Name Cannot Be Empty"); return; } //Check If Any Scene Names are empty for (int i = 0; i < scenesToCreateInGameLevel.Count; i++) { if (scenesToCreateInGameLevel[i].VerifySceneNameIsNotEmpty() == true) { Debug.LogError("Scene Name Cannot Be Empty"); return; } } for (int i = 0; i < scenesToCreateInGameLevel.Count; i++) { string sceneDirectory = gameLevelName; CreateScene.CreateEmptyScene(gameLevelName + "_" + scenesToCreateInGameLevel[i].sceneName, sceneDirectory); } //Create the Location Resources string resourceFolder = AssetDatabase.CreateFolder("Assets/" + projectPathName + "Resources/Locations", gameLevelName); string newFolderPath = AssetDatabase.GUIDToAssetPath(resourceFolder); //Check Does FolderExist To Place Resource File Inside if (!Directory.Exists("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/Existing " + SceneAndResourceFolderName.folderNameValue)) { AssetDatabase.CreateFolder("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue, "Existing " + SceneAndResourceFolderName.folderNameValue); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } GameLevel gameLevelResource = GameLevelData.CreateInstance <GameLevel>(); AssetDatabase.CreateAsset(GameLevel.CreateInstance <GameLevel>(), "Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/Existing " + SceneAndResourceFolderName.folderNameValue + "/" + gameLevelName + ".asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); GameLevel createdGameLevel = (GameLevel)AssetDatabase.LoadAssetAtPath("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/Existing " + SceneAndResourceFolderName.folderNameValue + "/" + gameLevelName + ".asset", typeof(GameLevel)); createdGameLevel.gameLevelName = gameLevelName; createdGameLevel.assignedScenesDirectory = "Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/" + gameLevelName; createdGameLevel.assignedCategory = categories[selectedCategoryValue]; GameLevelToolkitWindow.GetGameLevelsData().gameLevelsCreatedByUser.Add(createdGameLevel); EditorUtility.SetDirty(createdGameLevel); for (int i = 0; i < scenesToCreateInGameLevel.Count; i++) { createdGameLevel.assignedScenes.Add(scenesToCreateInGameLevel[i].sceneName); } for (int i = 0; i < gameLevelDependencies.Count; i++) { createdGameLevel.levelDependencies.Add(gameLevelDependencies[i]); } EditorUtility.SetDirty(toolkit.gameLevelsData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); OpenGameLevel.OpenLevel(createdGameLevel, true, false, true); if (addLevelToUnityBuildScenes == true) { BuildSettingsSceneManagement.AddLevelToBuild(createdGameLevel); } }
private void CreateRequiredInitialData() { string projectPathName = ""; string projectPathNameWithoutSlash = ""; GameLevelToolkitWindow toolkit = GetRefreshedToolkitWindow(); if (toolkit.useRootProjectDirectoryPath == false) { projectPathName = toolkit.projectDirectoryPathName + "/"; projectPathNameWithoutSlash = toolkit.projectDirectoryPathName; } if (!Directory.Exists("Assets/" + projectPathName + "Resources")) { if (useRootProjectDirectoryPath == true) { string resourcesDirectory = AssetDatabase.CreateFolder("Assets", "Resources"); } else { string resourcesDirectory = AssetDatabase.CreateFolder("Assets/" + projectPathNameWithoutSlash, "Resources"); } } if (!Directory.Exists("Assets/" + projectPathName + "Scenes")) { if (useRootProjectDirectoryPath == true) { string resourcesDirectory = AssetDatabase.CreateFolder("Assets", "Scenes"); } else { string resourcesDirectory = AssetDatabase.CreateFolder("Assets/" + projectPathNameWithoutSlash, "Scenes"); } } if (!Directory.Exists("Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue)) { //Create locationsResourceDirectory Directory string gameLevelsResourceDirectoryGuid = AssetDatabase.CreateFolder("Assets/" + projectPathName + "Resources", SceneAndResourceFolderName.folderNameValue); string gameLevelsResourceDirectoryPath = AssetDatabase.GUIDToAssetPath(gameLevelsResourceDirectoryGuid); } if (!Directory.Exists("Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue)) { //Create Locations Directory in Scenes string gameLevelsScenesDirectory = AssetDatabase.CreateFolder("Assets/" + projectPathName + "Scenes", SceneAndResourceFolderName.folderNameValue); } //Create Game Levels Data string desiredGameLevelsDataDirectory = "Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + SceneAndResourceFolderName.folderNameValue + " Data.asset"; if (!Directory.Exists(desiredGameLevelsDataDirectory)) { AssetDatabase.CreateAsset(GameLevelData.CreateInstance <GameLevelData>(), desiredGameLevelsDataDirectory); } //Create Game Levels Settings string desiredGameLevelsSettingsDirectory = "Assets/" + projectPathName + "Resources/" + SceneAndResourceFolderName.folderNameValue + "/" + SceneAndResourceFolderName.folderNameValue + " Settings.asset"; if (!Directory.Exists(desiredGameLevelsSettingsDirectory)) { AssetDatabase.CreateAsset(CreateInstance <GameLevelToolkitSettings>(), desiredGameLevelsSettingsDirectory); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); toolkit.gameLevelsData = Resources.Load(SceneAndResourceFolderName.folderNameValue + "/" + SceneAndResourceFolderName.folderNameValue + " Data") as GameLevelData; toolkit.settings = Resources.Load(SceneAndResourceFolderName.folderNameValue + "/" + SceneAndResourceFolderName.folderNameValue + " Settings") as GameLevelToolkitSettings; toolkit.settings.useRootProjectDirectoryPath = toolkit.useRootProjectDirectoryPath; toolkit.settings.projectDirectoryPathName = toolkit.projectDirectoryPathName; //Create Master Scene if (!Directory.Exists("Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/MasterScene")) { //Create Master Scene Directory string dir = AssetDatabase.CreateFolder("Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue, "Master Scene"); Scene masterScene = CreateScene.CreateEmptyScene("Master Scene", "Master Scene"); EditorSceneManager.OpenScene("Assets/" + projectPathName + "Scenes/" + SceneAndResourceFolderName.folderNameValue + "/Master Scene/Master Scene.unity"); } EditorUtility.SetDirty(toolkit.settings); EditorUtility.SetDirty(toolkit.gameLevelsData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorSceneManager.MarkAllScenesDirty(); //Setup Master Scene Scene currentScene = SceneManager.GetActiveScene(); // GameObject geo = new GameObject(); GameObject go = new GameObject("Game Level Manager"); go.AddComponent <GameLevelManager>(); EditorSceneManager.SaveOpenScenes(); BuildSettingsSceneManagement.AddMasterSceneToBuild(); initialDataHasBeenCreated = true; }