示例#1
0
    /// <summary>
    /// Dialog works like this:
    ///
    /// We start by pulling a root node from the DialogTree,
    /// which has its own logic to determine the root node.
    ///
    /// We walk down the dialog tree,
    /// performing all callbacks BEFORE showing the current Saying
    ///
    /// After displaying a Saying node, we check if it was a EndBranch node,
    /// and if it was, we reset the CurrentSaying by pulling from the DialogTree again.
    ///
    /// If the dialog tree has nothing for us and gives null, we carry on without modifying CurrentSaying.
    /// </summary>
    /// <param name="player"></param>
    public override void Action(PlayerInteract player)
    {
        if (this.currentSaying == null)
        {
            return;
        }

        // before anything else, perform the callback
        if (this.currentSaying.sayingCallback != null)
        {
            this.currentSaying.sayingCallback.callBackMethod(player, this);
        }

        player.ShowText(this.currentSaying.Text, this.currentSaying.Font, FontSize(this.currentSaying.Font));

        if (this.currentSaying.IsEndBranch && this.DialogTree != null)
        {
            this.currentSaying = this.DialogTree;
        }
        else if (!this.currentSaying.DoesSayingBranch)
        {
            this.currentSaying = this.currentSaying.NextSaying;
        }
        else
        {
            // this saying requests a yes/no answer from the player
            // the callback with advance to the next Saying based on response
            player.TryRegisterHeadNodCallback(this);
        }
    }