// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using UltimateXR.Animation.Interpolation;
using UltimateXR.Extensions.Unity;
using UnityEngine;
using UnityEngine.UI;
#if ULTIMATEXR_UNITY_TMPRO
using TMPro;
#endif
namespace UltimateXR.Animation.UI
{
///
/// Tweening component to animate a UI text component programatically or using the inspector. Supports both Unity's
/// Text and TMPro.
/// The text interpolation can be used to create a typewriter kind of effect.
/// Programatically it also offers the possibility to interpolate parameters in a text string.
///
[DisallowMultipleComponent]
public class UxrTextContentTween : UxrTween
{
#region Inspector Properties/Serialized Fields
[SerializeField] private string _startText;
[SerializeField] private string _endText;
#endregion
#region Public Types & Data
///
/// Gets the component whose string will be interpolated.
///
public Text TargetText => GetCachedComponent();
#if ULTIMATEXR_UNITY_TMPRO
///
/// Gets the component whose string will be interpolated.
///
public TextMeshProUGUI TargetTextTMPro => GetCachedComponent();
#endif
///
/// Gets or sets the text value.
///
public string Text
{
get
{
if (TargetText != null)
{
return TargetText.text;
}
#if ULTIMATEXR_UNITY_TMPRO
if (TargetTextTMPro != null)
{
return TargetTextTMPro.text;
}
#endif
return null;
}
set
{
if (TargetText != null)
{
TargetText.text = value;
}
#if ULTIMATEXR_UNITY_TMPRO
if (TargetTextTMPro != null)
{
TargetTextTMPro.text = value;
}
#endif
}
}
///
/// Gets whether the interpolation uses format string parameters.
///
///
/// false: Interpolation will be a plain typewriter effect from to
///
///
///
/// true: Interpolation will use and . For more
/// information on how these are used see
/// UxrInterpolator.InterpolateText
///
///
///
public bool UsesFormatString { get; private set; }
///
/// Animation start text
///
public string StartText
{
get => _startText;
set => _startText = value;
}
///
/// Animation end text
///
public string EndText
{
get => _endText;
set => _endText = value;
}
///
/// Animation format string, when is true.
///
public string FormatString { get; set; }
///
/// Animation format string parameter list, when is true.
///
public List