TextMeshProとDOTween Proをつかってゲームの起動時のタイトルをいい感じにする【Unity,TextMeshPro,DOTween】

デモ

使用アセット

TextMeshProの日本語化

hi-network.sakura.ne.jp

blog.naichilab.com

TextMeshProのoutlineについて

tsubakit1.hateblo.jp

kazupon.org

実装

タイトルのアニメーション

using System;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using TMPro;
using UnityEngine;

public class TitleAnimation : MonoBehaviour
{
    [SerializeField] private TextMeshProUGUI title;
    // Start is called before the first frame update
    async void Start()
    {
        await UniTask.Delay(TimeSpan.FromSeconds(1f));
        title = GetComponent<TextMeshProUGUI>();
        DOTweenTMPAnimator tmproAnimator = new DOTweenTMPAnimator(title);
        for (int i = 0; i < tmproAnimator.textInfo.characterCount; ++i)
        {
            tmproAnimator.DOScaleChar(i, 0.7f, 0);
            Vector3 currCharOffset = tmproAnimator.GetCharOffset(i);
            DOTween.Sequence()
                .Append(tmproAnimator.DOOffsetChar(i, currCharOffset + new Vector3(0, 30, 0), 0.4f).SetEase(Ease.OutFlash, 2))
                .Join(tmproAnimator.DOFadeChar(i, 1, 0.4f))
                .Join(tmproAnimator.DOScaleChar(i, 1, 0.4f).SetEase(Ease.OutBack))
                .SetDelay(0.07f * i);
        }
    }
}

メニュー選択

using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using TMPro;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

public class SelectButton : MonoBehaviour
{
    
    [SerializeField] private List<TextMeshProUGUI> menuList;
    [Header("game mode")]
    [SerializeField] private Canvas settingsPanel;
    [SerializeField] private Canvas gameContinuePanel;
    private TextMeshProUGUI selectedMenu;

    private int menuIndex = 0;
    private bool isOpenSettings = false;
    private bool isOpenContinue = false;

    private const float OutlineWidth = 0.3f;
    // Start is called before the first frame update
    void Start()
    {
        selectedMenu = menuList[menuIndex];
        selectedMenu.outlineWidth = OutlineWidth;
        Debug.Log(selectedMenu.name);
        this.UpdateAsObservable().Subscribe(
                _ =>
                {
                    if (menuIndex < menuList.Count-1 && Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        selectedMenu.outlineWidth = 0f;
                        menuIndex++;
                        selectedMenu = menuList[menuIndex];
                        selectedMenu.outlineWidth = OutlineWidth;
                        Debug.Log(selectedMenu.name);
                    }else if (0 < menuIndex && Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        selectedMenu.outlineWidth = 0f;
                        menuIndex--;
                        selectedMenu = menuList[menuIndex];
                        selectedMenu.outlineWidth = OutlineWidth;
                        Debug.Log(selectedMenu.name);
                    }
                    if(Input.GetKeyDown(KeyCode.Z))OpenMenu();
                });
    }

    async void OpenMenu()
    {
        if (selectedMenu.name == "NewGame")
        {
            Debug.Log("new game");
        }else if (selectedMenu.name == "Continue")
        {
            isOpenContinue = true;
            gameContinuePanel.gameObject.SetActive(true);
            await UniTask.Delay(TimeSpan.FromSeconds(3f));
            gameContinuePanel.gameObject.SetActive(false);
        }else if (selectedMenu.name == "Settings")
        {
            isOpenSettings = true;
            settingsPanel.gameObject.SetActive(true);
            await UniTask.Delay(TimeSpan.FromSeconds(3f));
            settingsPanel.gameObject.SetActive(false);
        }else if (selectedMenu.name == "Exit")
        {
            #if UNITY_EDITOR
                  UnityEditor.EditorApplication.isPlaying = false;
            #elif UNITY_STANDALONE
                  UnityEngine.Application.Quit();
            #endif
        }
    }

    void SettingOption()
    {
        
    }
}

参考サイト

game-ui.net