hellbound/Assets/Sources/Feel/MMTools/ToolsForTextMeshPro/MMFloatingText/MMFloatingTextMeshPro.cs

59 lines
1.7 KiB
C#
Raw Permalink Normal View History

2021-11-26 11:16:25 +03:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PlayerLoop;
using Random = System.Random;
using TMPro;
namespace MoreMountains.Tools
{
/// <summary>
/// A floating text variant using TextMeshPro instead of regular TextMesh
/// </summary>
public class MMFloatingTextMeshPro : MMFloatingText
{
[Header("TextMeshPro")]
/// the TextMeshPro object to use to display values
public TextMeshPro TargetTextMeshPro;
/// <summary>
/// On init we grab our TMP's color
/// </summary>
protected override void Initialization()
{
base.Initialization();
_initialTextColor = TargetTextMeshPro.color;
}
/// <summary>
/// Sets the TMP's value
/// </summary>
/// <param name="newValue"></param>
public override void SetText(string newValue)
{
TargetTextMeshPro.text = newValue;
}
/// <summary>
/// Sets the color of the target TMP
/// </summary>
/// <param name="newColor"></param>
public override void SetColor(Color newColor)
{
TargetTextMeshPro.color = newColor;
}
/// <summary>
/// Sets the opacity of the target TMP
/// </summary>
/// <param name="newOpacity"></param>
public override void SetOpacity(float newOpacity)
{
_newColor = TargetTextMeshPro.color;
_newColor.a = newOpacity;
TargetTextMeshPro.color = _newColor;
}
}
}