コード例 #1
0
        private void FilterPotentialLevels()
        {
            List <EditorBuildSettingsScene> editorBuildSettingsScenes = BuildSettingsSceneManagement.GetEditorBuildSettingsScenes();

            List <GameLevel> filteredGameLevelsList = new List <GameLevel>();

            foreach (GameLevel item in targetLevels)
            {
                //Get Scene and Scene Path
                bool doesAllScenesExistInBuild = false;
                for (int i = 0; i < item.assignedScenes.Count; i++)
                {
                    bool   sceneExistsInBuild            = false;
                    string gameLevelName                 = item.gameLevelName;
                    string scenePath                     = "Assets/" + GameLevelToolkitWindow.GetProjectPathStringWithSlash() + "Scenes/Game Levels/" + gameLevelName + "/" + gameLevelName + "_" + item.assignedScenes[i] + ".unity";
                    EditorBuildSettingsScene targetScene = new EditorBuildSettingsScene(scenePath, true);

                    for (int r = 0; r < editorBuildSettingsScenes.Count; r++)
                    {
                        if (editorBuildSettingsScenes[r].path == targetScene.path)
                        {
                            sceneExistsInBuild = true;
                            break;
                        }
                    }

                    if (sceneExistsInBuild == false)
                    {
                        doesAllScenesExistInBuild = false;
                        break;
                    }
                    else
                    {
                        doesAllScenesExistInBuild = true;
                    }
                }

                if (doesAllScenesExistInBuild == false)
                {
                    filteredGameLevelsList.Add(item);
                }
            }

            targetLevels = filteredGameLevelsList.ToArray();

            List <string> levelsToString = new List <string>();

            foreach (GameLevel item in targetLevels)
            {
                levelsToString.Add(item.gameLevelName);
            }
            targetLevelOptions = levelsToString.ToArray();
        }
コード例 #2
0
        private void RemoveScene()
        {
            if (HasSceneName() == true)
            {
                Debug.LogError("Scene Name Is Required");
                return;
            }

            //Check If scene Already Exists
            string targetSceneFile = selectedGameLevel.assignedScenesDirectory + "/" + selectedGameLevel.gameLevelName + "_" + selectedSceneToDestroy + ".unity";

            if (!System.IO.File.Exists(targetSceneFile))
            {
                //  Debug.Log(targetSceneFile);
                Debug.LogError("Scene Does Not Exist");
                return;
            }

            if (selectedGameLevel.assignedScenes.Count == 1)
            {
                Debug.LogError("Cannot Delete Last Scene in a location, a location required at least one scene, delete the location if you want otherwise");
                return;
            }

            //Remove From Build
            EditorBuildSettingsScene scene = new EditorBuildSettingsScene(targetSceneFile, true);

            BuildSettingsSceneManagement.RemoveSceneFromBuild(scene, null, false, true);


            selectedGameLevel.assignedScenes.Remove(selectedSceneToDestroy);
            EditorUtility.SetDirty(selectedGameLevel);
            FileUtil.DeleteFileOrDirectory(targetSceneFile);
            FileUtil.DeleteFileOrDirectory(targetSceneFile + ".meta");
            selectedSceneToDestroy = selectedGameLevel.assignedScenes[0];
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        private void AddSelectedLevel()
        {
            BuildSettingsSceneManagement.AddLevelToBuild(targetLevel);

            FilterPotentialLevels();
        }
コード例 #5
0
        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;
        }