Exemplo n.º 1
0
 void OnStoryLoadedEvent(StratusStory.LoadedEvent e)
 {
     if (ValidateStory(e))
     {
         Activate();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a story from file
        /// </summary>
        /// <param name="storyFile"></param>
        private void LoadStory(TextAsset storyFile, bool restart = false, string knot = null)
        {
            StratusStory newStory = null;

            // If this story has already been loaded, use the previous state
            bool previouslyLoaded = stories.ContainsKey(storyFile.name);

            if (previouslyLoaded)
            {
                if (debug)
                {
                    StratusDebug.Log($"{storyFile.name} has already been loaded! Using the previous state.");
                }
                newStory = stories[storyFile.name];
                LoadState(newStory);
            }
            // If the story hasn't been loaded yet
            else
            {
                if (debug)
                {
                    StratusDebug.Log($"{storyFile.name} has not been loaded yet. Constructing a new state.");
                }
                newStory = ConstructStory(storyFile);
            }

            // Assign the story
            story = newStory;

            // If a knot was provided
            if (knot != null && knot.Length > 0)
            {
                if (!story.runtime.canContinue)
                {
                    if (automaticRestart)
                    {
                        Restart(clearStateOnRestart);
                    }
                    else
                    {
                        StratusDebug.LogError($"The story {story.name} has already been ended, thus we can't jump to the knot!", this);
                    }
                }
                JumpToKnot(knot);
            }
            else if (restart || automaticRestart)
            {
                Restart(clearStateOnRestart);
            }


            // Announce that we are loding the story
            var loadedEvent = new StratusStory.LoadedEvent()
            {
                reader = this, story = this.story
            };

            this.gameObject.Dispatch <StratusStory.LoadedEvent>(loadedEvent);
            StratusScene.Dispatch <StratusStory.LoadedEvent>(loadedEvent);

            // Invoke any subclass callbacks
            OnStoryLoaded(story);

            // Now start the story
            // If the story was previously loaded, we need not start from a new line
            this.StartStory(previouslyLoaded && story.started);
        }