也是向csv投降了
This commit is contained in:
@@ -1,23 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using Data;
|
||||
using Event;
|
||||
using Event.EventArgs;
|
||||
using Newtonsoft.Json;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
public class Dialog : MonoBehaviour
|
||||
public class ScreenDialog : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string dialogsPath;
|
||||
[SerializeField] private string dialogJson;
|
||||
private Dictionary<int, string> _dialogsMap = new();
|
||||
|
||||
public float typingSpeed = 0.05f;
|
||||
public string IntroduceText;
|
||||
public string introduceText;
|
||||
private string _currentText = "";
|
||||
private float _timer;
|
||||
private int _currentIndex;
|
||||
@@ -27,22 +20,7 @@ namespace UI
|
||||
public float printTime;
|
||||
public float maxPrintTime=10;
|
||||
public bool isTime2Break;
|
||||
private void Awake()
|
||||
{
|
||||
dialogsPath = Application.persistentDataPath + "/" + "Dialogs.json";
|
||||
|
||||
if (File.Exists(dialogsPath))
|
||||
{
|
||||
dialogJson = File.ReadAllText(dialogsPath);
|
||||
_dialogsMap = JsonConvert.DeserializeObject<Dictionary<int, string>>(dialogJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dialogsMap.Add(0, "我会视奸你,永远...永远......");
|
||||
dialogJson = JsonConvert.SerializeObject(_dialogsMap, Formatting.Indented);
|
||||
File.WriteAllText(dialogsPath, dialogJson);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -52,11 +30,11 @@ namespace UI
|
||||
{
|
||||
isTime2Break = true;
|
||||
}
|
||||
if (_currentText == IntroduceText) return;
|
||||
if (_currentText == introduceText) return;
|
||||
_timer += Time.deltaTime;
|
||||
if (!(_timer >= typingSpeed)) return;
|
||||
_timer = 0f;
|
||||
_currentText += IntroduceText[_currentIndex];
|
||||
_currentText += introduceText[_currentIndex];
|
||||
textMeshPro.text = _currentText;
|
||||
_currentIndex++;
|
||||
}
|
||||
@@ -66,12 +44,6 @@ namespace UI
|
||||
EventManager.Instance.DialogPop += StartPrinting;
|
||||
}
|
||||
|
||||
/*public void OpenDialog(DialogPopArgs e)
|
||||
{
|
||||
Debug.Log(_dialogsMap[e.Index]);
|
||||
}*/
|
||||
|
||||
//闪烁光标
|
||||
private IEnumerator BlinkCursor()
|
||||
{
|
||||
while (true)
|
||||
@@ -95,19 +67,19 @@ namespace UI
|
||||
textMeshPro.text = textMeshPro.text[..^1];
|
||||
_isBlinking = false;
|
||||
}
|
||||
yield return new WaitForSeconds(0.3f); // 闪烁速度
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
// 调用此方法开始打印文字
|
||||
private void StartPrinting(DialogPopArgs e)
|
||||
{
|
||||
if(!e.IsScreenDialog) return;
|
||||
if(printTime != 0) return;
|
||||
_start = true;
|
||||
_currentText = "";
|
||||
|
||||
|
||||
IntroduceText = _dialogsMap[e.Index];
|
||||
|
||||
|
||||
introduceText = DialogManager.Instance.GetDialogByIndex(e.Index).Content;
|
||||
_currentIndex = 0;
|
||||
_timer = 0f;
|
||||
textMeshPro.fontSize = 80;
|
||||
Reference in New Issue
Block a user