也是向csv投降了
This commit is contained in:
89
Assets/Scripts/UI/ScreenDialog.cs
Normal file
89
Assets/Scripts/UI/ScreenDialog.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System.Collections;
|
||||
using Data;
|
||||
using Event;
|
||||
using Event.EventArgs;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class ScreenDialog : MonoBehaviour
|
||||
{
|
||||
public float typingSpeed = 0.05f;
|
||||
public string introduceText;
|
||||
private string _currentText = "";
|
||||
private float _timer;
|
||||
private int _currentIndex;
|
||||
private bool _start;
|
||||
private bool _isBlinking;
|
||||
public TMP_Text textMeshPro;
|
||||
public float printTime;
|
||||
public float maxPrintTime=10;
|
||||
public bool isTime2Break;
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!_start) return;
|
||||
printTime += Time.deltaTime;
|
||||
if (printTime > maxPrintTime)
|
||||
{
|
||||
isTime2Break = true;
|
||||
}
|
||||
if (_currentText == introduceText) return;
|
||||
_timer += Time.deltaTime;
|
||||
if (!(_timer >= typingSpeed)) return;
|
||||
_timer = 0f;
|
||||
_currentText += introduceText[_currentIndex];
|
||||
textMeshPro.text = _currentText;
|
||||
_currentIndex++;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
EventManager.Instance.DialogPop += StartPrinting;
|
||||
}
|
||||
|
||||
private IEnumerator BlinkCursor()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (isTime2Break)
|
||||
{
|
||||
_start = false;
|
||||
printTime = 0;
|
||||
isTime2Break = false;
|
||||
textMeshPro.fontSize = 48.7f;
|
||||
textMeshPro.text = "+";
|
||||
break;
|
||||
}
|
||||
if (!_isBlinking)
|
||||
{
|
||||
textMeshPro.text += "|";
|
||||
_isBlinking = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
textMeshPro.text = textMeshPro.text[..^1];
|
||||
_isBlinking = false;
|
||||
}
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartPrinting(DialogPopArgs e)
|
||||
{
|
||||
if(!e.IsScreenDialog) return;
|
||||
if(printTime != 0) return;
|
||||
_start = true;
|
||||
_currentText = "";
|
||||
|
||||
|
||||
introduceText = DialogManager.Instance.GetDialogByIndex(e.Index).Content;
|
||||
_currentIndex = 0;
|
||||
_timer = 0f;
|
||||
textMeshPro.fontSize = 80;
|
||||
StartCoroutine(BlinkCursor());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user