Ejemplo n.º 1
0
        protected void Awake()
        {
            if (FindObjectsOfType(typeof(Game)).Length > 1)
            {
                Destroy(this.gameObject);
                return;
            }

            DontDestroyOnLoad(this.gameObject);
            DontDestroyOnLoad(Camera.main);

            executeStack = new Stack <KeyValuePair <Interactuable, ExecutionEvent> >();

            skin = Resources.Load("basic") as GUISkin;

            if (!string.IsNullOrEmpty(gamePath))
            {
                ResourceManager = ResourceManagerFactory.CreateExternal(gamePath + gameName);
            }
            else
            {
                if (!string.IsNullOrEmpty(gameName))
                {
                    ResourceManager = ResourceManagerFactory.CreateLocal(gameName, useSystemIO ? ResourceManager.LoadingType.SystemIO : ResourceManager.LoadingType.ResourcesLoad);
                }
                else
                {
                    ResourceManager = ResourceManagerFactory.CreateLocal("CurrentGame/", useSystemIO ? ResourceManager.LoadingType.SystemIO : ResourceManager.LoadingType.ResourcesLoad);
                }
            }

            if (Game.GameToLoad != "")
            {
                gameName    = Game.GameToLoad;
                gamePath    = ResourceManager.getCurrentDirectory() + System.IO.Path.DirectorySeparatorChar + "Games" + System.IO.Path.DirectorySeparatorChar;
                useSystemIO = true;
            }

            AdventureData    data       = new AdventureData();
            var              incidences = new List <Incidence>();
            AdventureHandler adventure  = new AdventureHandler(data, ResourceManager, incidences);

            adventure.Parse("descriptor.xml");

            game_state = new GameState(data);
            bookDrawer = new BookDrawer(ResourceManager);

            gameExtensions = new List <GameExtension>();
            foreach (var gameExtension in GetAllSubclassOf(typeof(GameExtension)))
            {
                gameExtensions.Add(gameObject.AddComponent(gameExtension) as GameExtension);
            }
        }
Ejemplo n.º 2
0
        protected void Awake()
        {
            if (FindObjectsOfType(typeof(Game)).Length > 1)
            {
                Destroy(this.gameObject);
                return;
            }
            else
            {
                Debug.Log("[START ENGINE] Starting...");
                DontDestroyOnLoad(this.gameObject);
                DontDestroyOnLoad(Camera.main);

                executeStack = new Stack <KeyValuePair <Interactuable, ExecutionEvent> >();

                skin = Resources.Load("basic") as GUISkin;

                if (!string.IsNullOrEmpty(gamePath))
                {
                    Debug.Log("[START ENGINE] Creating external resource manager: " + gamePath + gameName);
                    ResourceManager = ResourceManagerFactory.CreateExternal(gamePath + gameName);
                }
                else
                {
                    Debug.Log("[START ENGINE] Creating resource manager: " + gameName);
                    if (!string.IsNullOrEmpty(gameName))
                    {
                        ResourceManager = ResourceManagerFactory.CreateLocal(gameName, useSystemIO ? ResourceManager.LoadingType.SystemIO : ResourceManager.LoadingType.ResourcesLoad);
                    }
                    else
                    {
                        ResourceManager = ResourceManagerFactory.CreateLocal("CurrentGame/", useSystemIO ? ResourceManager.LoadingType.SystemIO : ResourceManager.LoadingType.ResourcesLoad);
                    }
                }

                if (!string.IsNullOrEmpty(Game.GameToLoad))
                {
                    gameName = Game.GameToLoad;
                    gamePath = ResourceManager.getCurrentDirectory() + System.IO.Path.DirectorySeparatorChar + "Games" + System.IO.Path.DirectorySeparatorChar;
                    Debug.Log("[START ENGINE] Loading game from GameToLoad: " + gamePath);
                    useSystemIO = true;
                }

                var incidences = new List <Incidence>();
                var loadScreen = ShowLoading();
                Debug.Log("[START ENGINE] Loading main assets...");
                loadScreen.Text = "Loading main assets...";
                var descriptorPromise = LoadDescriptor();
                descriptorPromise.AddProgressCallback((p) =>
                {
                    Debug.Log("[START ENGINE] Main assets loading progress: " + p);
                    loadScreen.Progress = p * 100f;
                });
                descriptorPromise.Then(adventureData =>
                {
                    Debug.Log("[START ENGINE] Main assets loading done!");
                    game_state     = new GameState(adventureData);
                    bookDrawer     = new BookDrawer(ResourceManager);
                    gameExtensions = new List <GameExtension>();
                    Debug.Log("[START ENGINE] Creating game extensions...");
                    foreach (var gameExtension in GetAllSubclassOf(typeof(GameExtension)))
                    {
                        Debug.Log("[START ENGINE] Creating " + gameExtension.ToString());
                        gameExtensions.Add(gameObject.AddComponent(gameExtension) as GameExtension);
                    }
                    Debug.Log("[START GAME] Loading Chapter...");
                    loadScreen.Text                 = "Loading chapter...";
                    var chapterPromise              = LoadChapter(1);
                    chapterPromise.ProgressChanged += (s, e) =>
                    {
                        Debug.Log("[START GAME] Chapter loading progress: " + chapterPromise.Progress);
                        loadScreen.Progress = chapterPromise.Progress;
                    };
                    return(chapterPromise);
                })
                .Then(() =>
                {
                    Debug.Log("[START GAME] Chapter loading done!");
                    loadScreen.Text = "Starting game...";
                    StartCoroutine(StartGame(loadScreen));
                });
            }
        }
Ejemplo n.º 3
0
        protected void Awake()
        {
            Game.instance = this;
            executeStack  = new Stack <KeyValuePair <Interactuable, ExecutionEvent> >();

            skin = Resources.Load("basic") as GUISkin;

            if (!string.IsNullOrEmpty(gamePath))
            {
                ResourceManager = ResourceManagerFactory.CreateExternal(gamePath + gameName);
            }
            else
            {
                if (!string.IsNullOrEmpty(gameName))
                {
                    ResourceManager = ResourceManagerFactory.CreateLocal(gameName, useSystemIO ? ResourceManager.LoadingType.SYSTEM_IO : ResourceManager.LoadingType.RESOURCES_LOAD);
                }
                else
                {
                    ResourceManager = ResourceManagerFactory.CreateLocal("CurrentGame/", useSystemIO ? ResourceManager.LoadingType.SYSTEM_IO : ResourceManager.LoadingType.RESOURCES_LOAD);
                }
            }

            if (Game.GameToLoad != "")
            {
                gameName    = Game.GameToLoad;
                gamePath    = ResourceManager.getCurrentDirectory() + System.IO.Path.DirectorySeparatorChar + "Games" + System.IO.Path.DirectorySeparatorChar;
                useSystemIO = true;
            }

            AdventureData    data       = new AdventureData();
            var              incidences = new List <Incidence>();
            AdventureHandler adventure  = new AdventureHandler(data, ResourceManager, incidences);

            adventure.Parse("descriptor.xml");
            PrepareTracker(data.getTrackerConfig());

            game_state = new GameState(data);

            //Create Main game completable

            Completable mainGame = new Completable();

            Completable.Milestone gameStart = new Completable.Milestone();
            gameStart.setType(Completable.Milestone.MilestoneType.SCENE);
            gameStart.setId(data.getChapters()[0].getInitialChapterTarget().getId());
            mainGame.setStart(gameStart);
            mainGame.setId(data.getTitle());
            mainGame.setType(Completable.TYPE_GAME);

            Completable.Milestone gameEnd = new Completable.Milestone();
            gameEnd.setType(Completable.Milestone.MilestoneType.ENDING);
            mainGame.setEnd(gameEnd);

            Completable.Progress gameProgress = new Completable.Progress();
            gameProgress.setType(Completable.Progress.ProgressType.SUM);

            Completable.Score mainScore = new Completable.Score();
            mainScore.setMethod(Completable.Score.ScoreMethod.AVERAGE);

            foreach (Completable part in GameState.GetCompletables())
            {
                Completable.Milestone tmpMilestone = new Completable.Milestone();
                tmpMilestone.setType(Completable.Milestone.MilestoneType.COMPLETABLE);
                tmpMilestone.setId(part.getId());
                gameProgress.addMilestone(tmpMilestone);

                Completable.Score tmpScore = new Completable.Score();
                tmpScore.setMethod(Completable.Score.ScoreMethod.SINGLE);
                tmpScore.setType(Completable.Score.ScoreType.COMPLETABLE);
                tmpScore.setId(part.getId());
                mainScore.addSubScore(tmpScore);
            }
            mainGame.setProgress(gameProgress);
            mainGame.setScore(mainScore);

            GameState.GetCompletables().Insert(0, mainGame);

            CompletablesController.Instance.SetCompletables(GameState.GetCompletables());

            bookDrawer = new BookDrawer(ResourceManager);
        }