#if UNITY_EDITOR
#define CHECK_ERRORS //used to check text errors
#endif
#if TA_Naninovel
#define INTEGRATE_NANINOVEL
#endif
using Febucci.UI.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.Assertions;
namespace Febucci.UI
{
///
/// The main TextAnimator component. Add this near to a TextMeshPro component in order to enable effects. It can also be used in combination with a TextAnimatorPlayer in order to display letters dynamically (like a typewriter).
/// - See also:
/// - Manual: How to add effects to your texts
///
[HelpURL("https://www.febucci.com/text-animator-unity/docs/1.X/how-to-add-effects-to-your-texts/")]
[AddComponentMenu("Febucci/TextAnimator/TextAnimator")]
[RequireComponent(typeof(TMP_Text)), DisallowMultipleComponent]
public class TextAnimator : MonoBehaviour
{
#region Types (Structs + Enums)
public enum UpdateMode
{
///
/// Update Loop
///
Auto = 0,
///
/// Via Script
///
Manual = 1
}
///
/// Contains TextAnimator's current time values.
///
[System.Serializable]
public struct TimeData
{
///
/// Time passed since the textAnimator started showing the very first letter
///
public float timeSinceStart { get; private set; }
///
/// TextAnimator's Component delta time, could be Scaled or Unscaled
///
public float deltaTime { get; private set; }
internal void ResetData()
{
timeSinceStart = 0;
}
internal void IncreaseTime()
{
timeSinceStart += deltaTime;
}
internal void UpdateDeltaTime(TimeScale timeScale)
{
deltaTime = timeScale == TimeScale.Unscaled ? Time.unscaledDeltaTime : Time.deltaTime;
//To avoid possible desync errors etc., effects can't be played backwards.
if (deltaTime < 0)
deltaTime = 0;
}
}
[System.Serializable]
class AppearancesContainer
{
[SerializeField, UnityEngine.Serialization.FormerlySerializedAs("tags")]
public string[] tagsFallback_Appearances = new string[] { TAnimTags.ap_Size }; //starts with a size effect by default
public string[] tagsFallback_Disappearances = new string[] { TAnimTags.ap_Size }; //starts with a size effect by default
public AppearanceDefaultValues values = new AppearanceDefaultValues();
}
internal struct InternalAction
{
public TypewriterAction action;
public int charIndex;
public bool triggered;
public int internalOrder;
}
enum ShowTextMode : byte
{
Hidden = 0,
Shown = 1,
UserTyping = 2
}
///
/// TextAnimator's effects time scale, which could match unity's Time.deltaTime or Time.unscaledDeltaTime
///
public enum TimeScale
{
Scaled,
Unscaled,
}
#endregion
private void Awake()
{
Canvas[] canvases = gameObject.GetComponentsInParent