Beispiel #1
0
        private void ValidateActivityBeforeStarting(Activity activity)
        {
            //Create current scene name list for validations
            IList <string> currentSceneNames = new List <string>();

            if (HasActivityRunning())
            {
                currentSceneNames = GetCurrentActivity().GetScenes();
            }

            //Create new scene name list for validations
            IList <string> newSceneNames = activity.GetScenes();

            //Can't start Activity if it's already running.
            if (HasActivityRunning())
            {
                if (GetCurrentActivity().Is(activity))
                {
                    throw new Exception("Unable to start Activity : it is already running.");
                }
            }

#if UNITY_EDITOR
            //Can't start Activity if one of his scenes is not in the BuildSettings. Can only check this while in Editor.
            foreach (string sceneName in newSceneNames)
            {
                string scenePath = AssetsExtensions.FindScenePath(sceneName).Replace("\\", "/");

                bool founded = false;
                foreach (UnityEditor.EditorBuildSettingsScene scene in UnityEditor.EditorBuildSettings.scenes)
                {
                    if (scene.path == scenePath)
                    {
                        founded = true;
                        break;
                    }
                }

                if (!founded)
                {
                    throw new Exception("Unable to start Activity : scene named \"" + sceneName + "\" is not in the Unity BuildSettings. " +
                                        "Thus, Unity can't load it. To solve this, just click the \"Harmony/Generate Build Settings From Activities\" " +
                                        "and try again.");
                }
            }
#endif
            //Can't start an Activity if one of his scenes is already loaded and is not part of the current activity
            foreach (string sceneName in newSceneNames)
            {
                if (SceneManagerExtensions.IsSceneLoaded(sceneName) && !currentSceneNames.Contains(sceneName))
                {
                    throw new Exception("Unable to start Activity : scene named \"" + sceneName + "\" is already loaded and is not part of the " +
                                        "current Activity. You may have loaded it manually somewhere.");
                }
            }
        }
Beispiel #2
0
        private void OpenWorldInEditor()
        {
            //Find startup scene
            string scenePath;

            if (world.MainScene == R.E.Scene.None)
            {
                if (EditorBuildSettings.scenes.Length > 0)
                {
                    scenePath = EditorBuildSettings.scenes[0].path;
                }
                else
                {
                    scenePath = null;
                }
            }
            else
            {
                scenePath = AssetsExtensions.FindScenePath(R.S.Scene.ToString(world.MainScene));
            }

            if (scenePath == null)
            {
                Debug.LogError("Cannot open a world without a startup scene. The startup scene is either the first scene in the" +
                               "Build Settings or the one specified in that world.");
            }
            else
            {
                //Load starting scene. This scene is allways loaded.
                SceneManager.SetActiveScene(EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single));

                //Load World scenes
                foreach (R.E.Scene scene in world.Scenes)
                {
                    var sceneName = R.S.Scene.ToString(scene);
                    scenePath = AssetsExtensions.FindScenePath(sceneName);
                    if (scenePath != null)
                    {
                        EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                    }
                    else
                    {
                        Debug.LogError("The Scene named \"" + sceneName + "\" of the world you are trying to open seems to have " +
                                       "been renamed or doesn't exist anymore. To solve this problem, re-generate const classes " +
                                       "with the \"Tools/Project/Generate Const Class\" menu and re-assign the Scene.");
                    }
                }
            }
        }
        private static IEnumerable <string> GetWorldsScenesPaths()
        {
            var scenePaths = new HashSet <string>();

            //Main scene
            var mainScenePath = AssetsExtensions.FindScenePath(MainSceneName);

            if (mainScenePath != null)
            {
                scenePaths.Add(mainScenePath);
            }
            else
            {
                Debug.LogError("No main scene found. Please create a scene named \"" + MainSceneName + "\", re-generate const classes " +
                               "and try again.");
            }

            //World scenes
            foreach (var world in AssetsExtensions.FindAssets <World>())
            {
                if (!world.IsDeveloppement)
                {
                    foreach (var scene in world.Scenes)
                    {
                        var sceneName = R.S.Scene.ToString(scene);
                        var scenePath = AssetsExtensions.FindScenePath(sceneName);

                        if (scenePath != null)
                        {
                            scenePaths.Add(scenePath);
                        }
                        else
                        {
                            Debug.LogError("The scene named \"" + sceneName + "\" found in World named \"" + world.name + "\" seems to have been " +
                                           "renamed or doesn't exist anymore. Remove it from this world or try to re-generate const classes and try " +
                                           "again.");
                        }
                    }
                }
            }

            return(scenePaths);
        }
Beispiel #4
0
        public static void GenerateBuildSettings()
        {
            List <EditorBuildSettingsScene> scenes = new List <EditorBuildSettingsScene>();

            //Add Main and Main scene
            scenes.Add(new EditorBuildSettingsScene(AssetsExtensions.FindScenePath(R.S.Scene.Main), true));
            scenes.Add(new EditorBuildSettingsScene(AssetsExtensions.FindScenePath(R.S.Scene.Game), true));

            //Add Util scenes
            foreach (string scenePath in AssetsExtensions.FindScenesPathIn("Scenes/Util"))
            {
                scenes.Add(new EditorBuildSettingsScene(scenePath, true));
            }

            //Add Activity scenes
            foreach (Activity activity in AssetsExtensions.FindAssets <Activity>())
            {
                if (activity.Scene != R.E.Scene.None)
                {
                    scenes.Add(new EditorBuildSettingsScene(AssetsExtensions.FindScenePath(R.S.Scene.ToString(activity.Scene)), true));
                }

                foreach (Fragment fragment in activity.Fragments)
                {
                    if (fragment.Scene != R.E.Scene.None)
                    {
                        scenes.Add(new EditorBuildSettingsScene(AssetsExtensions.FindScenePath(R.S.Scene.ToString(fragment.Scene)), true));
                    }
                }

                foreach (Menu menu in activity.Menus)
                {
                    if (menu.Scene != R.E.Scene.None)
                    {
                        scenes.Add(new EditorBuildSettingsScene(AssetsExtensions.FindScenePath(R.S.Scene.ToString(menu.Scene)), true));
                    }
                }
            }

            EditorBuildSettings.scenes = scenes.ToArray();
        }
Beispiel #5
0
        protected override void Draw()
        {
            if (EditorBuildSettings.scenes.Length == 0)
            {
                DrawErrorBox("You don't have any scene in the Build Settings. You will enconter errors. Generate the Build Settings" +
                             "using \"Tools/Project/Generate Build Settings\".");
            }

            BeginTable();
            BeginTableCol();
            DrawTitleLabel("World tools");

            if (!EditorApplication.isPlaying)
            {
                DrawButton("Open World", OpenWorldInEditor);
            }
            else
            {
                DrawDisabledButton("Open World");
            }

            EndTableCol();
            EndTable();


            DrawTitleLabel("Scenes");
            if (EditorBuildSettings.scenes.Length == 0)
            {
                DrawErrorBox("Builds settings are empty. Please generate them, and make sure the first scene is your \"Main\"" +
                             "scene.");
            }
            else
            {
                var mainSceneIsInWorldScenes = false;
                var mainSceneFileName        = Path.GetFileName(EditorBuildSettings.scenes[0].path);
                foreach (R.E.Scene scene in world.Scenes)
                {
                    var sceneFileName = Path.GetFileName(AssetsExtensions.FindScenePath(R.S.Scene.ToString(scene)));
                    if (sceneFileName == mainSceneFileName)
                    {
                        mainSceneIsInWorldScenes = true;
                        break;
                    }
                }

                if (mainSceneIsInWorldScenes)
                {
                    DrawErrorBox("Worlds must not contain the \"Main\" scene (i.e the first scene in the \"Build Settings\")." +
                                 "You will enconter errors.");
                }
            }

            DrawInfoBox("Is a Scene missing ? Go to \"Tools/Project/Generate Const Class\" to generate missing constants.");
            DrawProperty(scenes);

            DrawTitleLabel("Active Scene");
            if (world.ActiveScene != R.E.Scene.None)
            {
                var activeSceneIsInWorldScenes = false;
                foreach (R.E.Scene scene in world.Scenes)
                {
                    if (scene == world.ActiveScene)
                    {
                        activeSceneIsInWorldScenes = true;
                        break;
                    }
                }

                if (!activeSceneIsInWorldScenes)
                {
                    DrawErrorBox("The Active Scene must be part of the world scenes. You will enconter errors.");
                }
            }

            DrawProperty(activeScene);

            DrawTitleLabel("Is Scene used for developpement only ?");
            DrawInfoBox("Worlds marked as \"Developppement only\" will not be included in a release build.");
            DrawPropertyWithLabel(isDeveloppement);

            DrawTitleLabel("Main Scene for developpement");
            DrawWarningBox("In Editor Only for debuging purposes. In a release build, the main scene is " +
                           "the first scene in the build settings.");
            DrawProperty(mainScene);
        }
Beispiel #6
0
        private void OpenActivityInEditor()
        {
            if (configuration.StartingScene != R.E.Scene.None)
            {
                //Load starting scene. This scene is allways loaded.
                string sceneName = R.S.Scene.ToString(configuration.StartingScene);
                string scenePath = AssetsExtensions.FindScenePath(sceneName);

                if (scenePath != null)
                {
                    EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
                }
                else
                {
                    Debug.LogError("The Startup Scene named \"" + sceneName + "\" seems to have been renamed or doesn't exist anymore. You can't start " +
                                   "an activity without a Startup Scene on the project. To solve this problem, re-generate const classes " +
                                   "with the \"Harmony/Generate Const Class\" menu and re-assign the Startup Scene in the \"Harmony/Settings\" menu.");
                }

                //Load Activity scene
                if (activity.Scene != R.E.Scene.None)
                {
                    sceneName = R.S.Scene.ToString(activity.Scene);
                    scenePath = AssetsExtensions.FindScenePath(sceneName);
                    if (scenePath != null)
                    {
                        EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                    }
                    else
                    {
                        Debug.LogError("The Scene named \"" + sceneName + "\" of the activity you are trying to open " +
                                       "seems to have been renamed or doesn't exist anymore. To solve this problem, re-generate const classes " +
                                       "with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in the Activity.");
                    }
                }

                //Load Activity fragments
                foreach (Fragment fragment in activity.Fragments)
                {
                    if (fragment != null && fragment.Scene != R.E.Scene.None)
                    {
                        sceneName = R.S.Scene.ToString(fragment.Scene);
                        scenePath = AssetsExtensions.FindScenePath(sceneName);
                        if (scenePath != null)
                        {
                            EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                        }
                        else
                        {
                            Debug.LogError("The Scene named \"" + sceneName + "\" of the Fragment named \"" + fragment.name + "\" of the activity " +
                                           "you are trying to open seems to have been renamed or doesn't exist anymore. To solve this problem, " +
                                           "re-generate const classes with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in " +
                                           "the Fragment.");
                        }
                    }
                }

                //Load Activity menus
                foreach (Menu menu in activity.Menus)
                {
                    if (menu != null && menu.Scene != R.E.Scene.None)
                    {
                        sceneName = R.S.Scene.ToString(menu.Scene);
                        scenePath = AssetsExtensions.FindScenePath(sceneName);
                        if (scenePath != null)
                        {
                            EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
                        }
                        else
                        {
                            Debug.LogError("The Scene named \"" + sceneName + "\" of the Menu named \"" + menu.name + "\" of the activity " +
                                           "you are trying to open seems to have been renamed or doesn't exist anymore. To solve this problem, " +
                                           "re-generate const classes with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in " +
                                           "the Menu.");
                        }
                    }
                }
            }
            else
            {
                DrawErrorBox("Cannot start an Activity without a Startup Scene. To solve this problem, open the \"Harmony/Settings\" menu " +
                             "and set a Startup Scene.");
            }
        }
        public static void GenerateBuildSettings()
        {
            Configuration configuration = Configuration.Get();

            //This HashSet prevent from adding the same scene twice.
            HashSet <string> scenePaths = new HashSet <string>();

            //Add startup scene
            if (configuration.StartingScene != R.E.Scene.None)
            {
                string sceneName = R.S.Scene.ToString(configuration.StartingScene);
                string scenePath = AssetsExtensions.FindScenePath(sceneName);

                if (scenePath != null)
                {
                    scenePaths.Add(scenePath);
                }
                else
                {
                    Debug.LogError("The Starting Scene previously named \"" + sceneName + "\" seems to have been renamed or doesn't exist anymore. " +
                                   "Re-generate const classes with the \"Harmony/Generate Const Class\" menu and re-assign the" +
                                   "Starting Scene in the \"Harmony/Settings\" menu.");
                }
            }
            else
            {
                Debug.LogError("No scene configured as Starting Scene. Open \"Harmony/Settings\" to set it.");
            }

            //Add utilitary scenes
            foreach (R.E.Scene utilitaryScene in configuration.UtilitaryScenes)
            {
                string sceneName = R.S.Scene.ToString(utilitaryScene);
                string scenePath = AssetsExtensions.FindScenePath(sceneName);

                if (scenePath != null)
                {
                    scenePaths.Add(scenePath);
                }
                else
                {
                    Debug.LogError("The Utilitary Scene previously named \"" + sceneName + "\" seems to have been renamed or doesn't exist anymore. " +
                                   "To solve this problem, re-generate const classes with the \"Harmony/Generate Const Class\" menu " +
                                   "and re-assign the Starting Scene in the \"Harmony/Settings\" menu.");
                }
            }

            //Add Activity scenes
            foreach (Activity activity in AssetsExtensions.FindAssets <Activity>())
            {
                if (activity.Scene != R.E.Scene.None)
                {
                    string sceneName = R.S.Scene.ToString(activity.Scene);
                    string scenePath = AssetsExtensions.FindScenePath(sceneName);

                    if (scenePath != null)
                    {
                        scenePaths.Add(scenePath);
                    }
                    else
                    {
                        Debug.LogError("The Scene previously named \"" + sceneName + "\" in the Activity named \"" + activity.name + "\" " +
                                       "seems to have been renamed or doesn't exist anymore. To solve this problem, re-generate const classes " +
                                       "with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in the Activity.");
                    }
                }

                foreach (Fragment fragment in activity.Fragments)
                {
                    if (fragment != null && fragment.Scene != R.E.Scene.None)
                    {
                        string sceneName = R.S.Scene.ToString(fragment.Scene);
                        string scenePath = AssetsExtensions.FindScenePath(sceneName);

                        if (scenePath != null)
                        {
                            scenePaths.Add(scenePath);
                        }
                        else
                        {
                            Debug.LogError("The Scene previously named \"" + sceneName + "\" in the Fragment named \"" + fragment.name + "\" " +
                                           "seems to have been renamed or doesn't exist anymore. To solve this problem, re-generate const classes " +
                                           "with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in the Fragment.");
                        }
                    }
                }

                foreach (Menu menu in activity.Menus)
                {
                    if (menu != null && menu.Scene != R.E.Scene.None)
                    {
                        string sceneName = R.S.Scene.ToString(menu.Scene);
                        string scenePath = AssetsExtensions.FindScenePath(sceneName);

                        if (scenePath != null)
                        {
                            scenePaths.Add(scenePath);
                        }
                        else
                        {
                            Debug.LogError("The Scene previously named \"" + sceneName + "\" in the Menu named \"" + menu.name + "\" " +
                                           "seems to have been renamed or doesn't exist anymore. To solve this problem, re-generate const classes " +
                                           "with the \"Harmony/Generate Const Class\" menu and re-assign the Scene in the Menu.");
                        }
                    }
                }
            }

            //Set the Editor Build Settings
            List <EditorBuildSettingsScene> scenes = new List <EditorBuildSettingsScene>();

            foreach (string scenePath in scenePaths)
            {
                scenes.Add(new EditorBuildSettingsScene(scenePath, true));
            }
            EditorBuildSettings.scenes = scenes.ToArray();
        }