Ejemplo n.º 1
0
        void Enter(string passageName)
        {
            _passageWaitingToEnter  = null;
            _passageEnterCueInvoked = false;
            _timeAccumulated        = 0;
            _timeChangedToPlay      = Time.time;

            this.InsertStack.Clear();
            this.Output.Clear();
            _groupStack.Clear();
            _passageUpdateCues = null;

            StoryPassage passage = GetPassage(passageName);

            this.Tags = (string[])passage.Tags.Clone();
            this.CurrentPassageName = passage.Name;

            PassageHistory.Add(passageName);

            // Prepare the thread enumerator
            _currentThread      = CollapseThread(GetPassageThread(passage).Invoke()).GetEnumerator();
            CurrentLinkInAction = null;

            this.State = StoryState.Playing;

            // Invoke the general passage enter event
            if (this.OnPassageEnter != null)
            {
                this.OnPassageEnter(passage);
            }

            // Story was paused, wait for it to resume
            if (this.State == StoryState.Paused)
            {
                return;
            }
            else
            {
                CuesInvoke(CuesGet(passage.Name, "Enter"));
                _passageEnterCueInvoked = true;
                ExecuteCurrentThread();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        public void GoTo(string passageName)
        {
            if (this.State != StoryState.Idle)
            {
                throw new InvalidOperationException(
                          // Paused
                          this.State == StoryState.Paused ?
                          "The story is currently paused. Resume() must be called before advancing to a different passage." :
                          // Playing
                          this.State == StoryState.Playing || this.State == StoryState.Exiting ?
                          "The story can only be advanced when it is in the Idle state." :
                          // Complete
                          "The story is complete. Reset() must be called before it can be played again."
                          );
            }

            // Indicate specified passage as next
            _passageWaitingToEnter = passageName;

            if (CurrentPassage != null)
            {
                this.State = StoryState.Exiting;

                if (this.OnPassageExit != null)
                {
                    this.OnPassageExit(this.CurrentPassage);
                }

                // invoke exit cues
                CuesInvoke(CuesFind(CueType.Exit, reverse: true));

                // Add the passage only now that we're leaving it
                PassageHistory.Add(CurrentPassage.Name);
            }

            if (this.State != StoryState.Paused)
            {
                Enter(passageName);
            }
        }