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); } }