private void AddScene()
        {
            if (HasSceneName() == true)
            {
                Debug.LogError("Scene Name Is Required");
                return;
            }

            GameLevelToolkitWindow toolkit = GameLevelToolkitWindow.GetRefreshedToolkitWindow();
            string targetSceneFolderPath   = GameLevelToolkitWindow.GetProjectPathStringWithSlash();


            //Check If scene Already Exists
            string targetSceneFile = "Assets/" + targetSceneFolderPath + "Scenes/" + targetSceneFolderPath + SceneAndResourceFolderName.folderNameValue + "/" + selectedGameLevel.gameLevelName + "_" + sceneNameToCreate + ".unity";

            if (System.IO.File.Exists(targetSceneFile))
            {
                Debug.LogError("Scene Already Exists");
                return;
            }

            CreateScene.CreateEmptyScene(selectedGameLevel.gameLevelName + "_" + sceneNameToCreate, selectedGameLevel.gameLevelName);

            selectedGameLevel.assignedScenes.Add(sceneNameToCreate);
            EditorUtility.SetDirty(selectedGameLevel);

            if (automaticallyAddSceneToBuild == true)
            {
                List <EditorBuildSettingsScene> editorBuildSettingsScenes = new List <EditorBuildSettingsScene>();

                //Get The Existing Build List
                foreach (EditorBuildSettingsScene item in EditorBuildSettings.scenes)
                {
                    editorBuildSettingsScenes.Add(item);
                }

                EditorBuildSettingsScene editorScene = new EditorBuildSettingsScene(targetSceneFile, true);

                if (editorBuildSettingsScenes.Count > 0)
                {
                    bool masterSceneNotFoundInBuild = false;
                    for (int i = 0; i < editorBuildSettingsScenes.Count; i++)
                    {
                        if (editorBuildSettingsScenes[i].path == editorScene.path)
                        {
                            masterSceneNotFoundInBuild = true;
                            break;
                        }
                    }
                    if (masterSceneNotFoundInBuild == false)
                    {
                        editorBuildSettingsScenes.Add(editorScene);
                    }
                }

                EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
            }

            OpenGameLevel.OpenLevel(selectedGameLevel, true, false, true);
        }
Пример #2
0
        public static void OpenMenu()
        {
            window = (OpenGameLevel)GetWindow(typeof(OpenGameLevel), false, "Load Game Level");
            window.gameLevelData = GameLevelToolkitWindow.GetGameLevelsData();
            window.selectedValue = 0;
            window.levels        = window.gameLevelData.gameLevelsCreatedByUser.ToArray();
            List <string> levelsToString = new List <string>();

            foreach (GameLevel item in window.levels)
            {
                levelsToString.Add(item.gameLevelName);
            }
            window.levelOptionsToLoad = levelsToString.ToArray();
        }
        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 LoadGameLevel()
 {
     OpenGameLevel.OpenMenu();
 }