UnityNovelProj Unity で VisualNovel を作成する

url: https://www.youtube.com/watch?v=uvsx9eHnuf4&list=PLGSox0FgA5B58Ki4t4VqAPDycEpmkBd0i&index=54
title: "Make a Visual Novel in Unity 2023 - Episode 16 (part1) Dialogue Continuation Prompt"
description: "Let's add a prompt that appears at the end of dialogue to let us know when to advance!Video Resources: - Arrow Graphic    - https://drive.google.com/file/d/1..."
host: www.youtube.com
favicon: https://www.youtube.com/s/desktop/ba3a814f/img/logos/favicon_32x32.png
image: https://i.ytimg.com/vi/uvsx9eHnuf4/maxresdefault.jpg

https://github.com/ganyariya/gnovel/pull/7

プロンプトを作成する

プロンプトは MonoBehaviour で作成します。 UI 上に表示する必要があるためです。

TextMeshProUGUI コンポーネントをもつ gameObject をインスペクタ上で参照し、それを親にします。

Imgur

この TextMeshProUGUI の最後の文字から1文字だけ右にずらした場所に DialogueContinuePrompt を配置します。 ここで、 localPosition で設定しており、親である TextMeshProUGUI の gameObject のローカル座標で配置しているようです。

namespace Core.DisplayDialogue  
{  
    public class DialogueContinuePrompt : MonoBehaviour  
    {  
        private RectTransform rootTransform;  
  
        [SerializeField] private Animator animator;  
        [SerializeField] private TextMeshProUGUI tmpro;  
  
        private bool IsShowing => animator.gameObject.activeSelf;  
  
        private void Start()  
        {            rootTransform = GetComponent<RectTransform>();  
            rootTransform.transform.SetParent(tmpro.transform);  
        }  
        public void Show()  
        {            if (tmpro.text == string.Empty)  
            {                if (IsShowing) Hide();  
                return;  
            }  
            // 文字ごとのジオメトリ情報を取得する  
            // 動画だと ForceMeshUpdate をしているが、自分の環境だと文字がすべて消えてしまう  
            // そのため無効化する  
            // tmpro.ForceMeshUpdate();  
  
            animator.gameObject.SetActive(true);  
  
            TMP_CharacterInfo finalCharacter = tmpro.textInfo.characterInfo[tmpro.textInfo.characterCount - 1];  
            Vector3 targetPos = new Vector3(finalCharacter.bottomRight.x + finalCharacter.pointSize,  
                finalCharacter.bottomRight.y, 0);  
  
            // 親からの相対座標で横にずらす  
            rootTransform.localPosition = targetPos;  
        }  
        public void Hide()  
        {            animator.gameObject.SetActive(false);  
        }    }}

tmpro.ForceMeshUpdate をしたところ文字が消えてしまいました。 そのため、これについては有効化していません。