init
This commit is contained in:
commit
fca6784fe7
571 changed files with 84105 additions and 0 deletions
72
Assets/Scripts/CustomTMP_Animated.cs
Normal file
72
Assets/Scripts/CustomTMP_Animated.cs
Normal file
|
@ -0,0 +1,72 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace TMPro{
|
||||
[System.Serializable] public class CTextRevealEvent : UnityEvent<char> { }
|
||||
[System.Serializable] public class CDialogueEvent : UnityEvent { }
|
||||
|
||||
public class CustomTMP_Animated : TextMeshProUGUI{
|
||||
|
||||
float speed;
|
||||
|
||||
public CTextRevealEvent onTextReveal;
|
||||
public CDialogueEvent onDialogueFinish;
|
||||
|
||||
public void ReadText(string newText){
|
||||
text = string.Empty;
|
||||
|
||||
string[] subTexts = newText.Split('<', '>');
|
||||
|
||||
string displayText = "";
|
||||
for (int i = 0; i < subTexts.Length; i++){
|
||||
if (i % 2 == 0)
|
||||
displayText += subTexts[i];
|
||||
else if (!isCustomTag(subTexts[i].Replace(" ", "")))
|
||||
displayText += $"<{subTexts[i]}>";
|
||||
}
|
||||
|
||||
bool isCustomTag(string tag){
|
||||
return tag.StartsWith("speed=") || tag.StartsWith("pause=");
|
||||
}
|
||||
|
||||
text = displayText;
|
||||
maxVisibleCharacters = 0;
|
||||
StartCoroutine(Read());
|
||||
|
||||
IEnumerator Read(){
|
||||
int subCounter = 0;
|
||||
int visibleCounter = 0;
|
||||
while (subCounter < subTexts.Length){
|
||||
if (subCounter % 2 == 1){
|
||||
yield return EvaluateTag(subTexts[subCounter].Replace(" ", ""));
|
||||
}else{
|
||||
while (visibleCounter < subTexts[subCounter].Length){
|
||||
onTextReveal.Invoke(subTexts[subCounter][visibleCounter]);
|
||||
visibleCounter++;
|
||||
maxVisibleCharacters++;
|
||||
AudioManager.instance.PlayOneShot("text");
|
||||
yield return new WaitForSeconds(1f / speed);
|
||||
}
|
||||
visibleCounter = 0;
|
||||
}
|
||||
subCounter++;
|
||||
}
|
||||
yield return null;
|
||||
|
||||
WaitForSeconds EvaluateTag(string tag){
|
||||
if (tag.Length > 0){
|
||||
if (tag.StartsWith("speed=")){
|
||||
speed = float.Parse(tag.Split('=')[1]);
|
||||
}else if (tag.StartsWith("pause=")){
|
||||
return new WaitForSeconds(float.Parse(tag.Split('=')[1]));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
onDialogueFinish.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue