-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateControlText.cs
More file actions
41 lines (36 loc) · 1.05 KB
/
UpdateControlText.cs
File metadata and controls
41 lines (36 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
public class UpdateControlText : MonoBehaviour
{
[SerializeField]
TextMesh m_TextMesh = new TextMesh();
public void OnSliderEvent(float value)
{
if (m_TextMesh)
m_TextMesh.text = string.Format("{0:0.#}", value);
}
public void OnKnobEvent(float value)
{
if (m_TextMesh)
m_TextMesh.text = string.Format("{0:0.#}", value);
}
IEnumerator StartTextMeshFade(TextMesh textMesh)
{
float duration = 0.5f;
float t = 0f;
while (t <= duration)
{
t += Time.deltaTime;
textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b,
Mathf.Lerp(1.0f, 0.0f, Mathf.Min(Mathf.SmoothStep(0f, 1f, t / duration), 1.0f)));
yield return null;
}
}
public void OnButtonEvent()
{
if (m_TextMesh)
StartCoroutine(StartTextMeshFade(m_TextMesh));
}
}