让Unity插件Fungus在SayDialogue结束后不消失的办法

如下图这样,当我们连续say的时候
每句话都会print出来 然后对话框消失
连续Say
然而我需要让其呈现一种类似短信交流的效果
短信交流
我们打开 Fungus.SayDialog 能看到其中的Say 方法:

        /// <summary>
        /// Write a line of story text to the Say Dialog. Starts coroutine automatically.
        /// </summary>
        /// <param name="text">The text to display.</param>
        /// <param name="clearPrevious">Clear any previous text in the Say Dialog.</param>
        /// <param name="waitForInput">Wait for player input before continuing once text is written.</param>
        /// <param name="fadeWhenDone">Fade out the Say Dialog when writing and player input has finished.</param>
        /// <param name="stopVoiceover">Stop any existing voiceover audio before writing starts.</param>
        /// <param name="voiceOverClip">Voice over audio clip to play.</param>
        /// <param name="onComplete">Callback to execute when writing and player input have finished.</param>
        public virtual void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, bool waitForVO, AudioClip voiceOverClip, Action onComplete)
        {
    
    
            StartCoroutine(DoSay(text, clearPrevious, waitForInput, fadeWhenDone, stopVoiceover, waitForVO, voiceOverClip, onComplete));
        }

阅读注释,得知第二个参数 bool clearPrevious 控制是否清除上一句话,override之应该能达到效果。
果然:

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;

public class mySayDialogue : Fungus.SayDialog
{
    
    
    public bool oldTalk=false;
    public Scrollbar scBar;
    public override void Say(string text, bool clearPrevious, bool waitForInput, bool fadeWhenDone, bool stopVoiceover, bool waitForVO, AudioClip voiceOverClip, Action onComplete)
    {
    
    
        StartCoroutine(DoSay(text+"\n", false, waitForInput, fadeWhenDone, stopVoiceover, waitForVO, voiceOverClip, onComplete));
        scBar.value=0;
    }
    private void Update() {
    
    
        if(writer != null&&this.writer.IsWriting==true){
    
    
            scBar.value=0;
        }
    }
    public void clearOldText(){
    
    
        StartCoroutine(DoSay("", true, false, true, false, false, null, null));
        scBar.value=0;
    }
}

同时由于我的对话放在了一个ScrollView里,时不时将其拉到最下面非常合适。

另外,我目前没有找到不影响其他操作的使SayDialogue本身在flowchart结束后不消失的办法,暂时用的是复制一个克隆体scrollView 仔细与原SayDialogue对齐来达到,希望有更优雅方法的同志分享。

猜你喜欢

转载自blog.csdn.net/weixin_42767868/article/details/122991685
今日推荐