AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ModeTip.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 using HoloToolkit.Unity;
6 
7 namespace HoloToolkit.Examples.GazeRuler
8 {
12  public class ModeTip : Singleton<ModeTip>
13  {
14  private const string LineMode = "Line Mode";
15  private const string PolygonMode = "Geometry Mode";
16  private TextMesh text;
17  private int fadeTime = 100;
18  private Material material;
19 
20  private void Start()
21  {
22  text = GetComponent<TextMesh>();
23  material = GetComponent<Renderer>().material;
24  switch (MeasureManager.Instance.Mode)
25  {
26  case GeometryMode.Line:
27  text.text = LineMode;
28  break;
29  default:
30  text.text = PolygonMode;
31  break;
32  }
33  }
34 
35  protected override void OnDestroy()
36  {
37  DestroyImmediate(material);
38  }
39 
40  // Update is called once per frame
41  private void Update()
42  {
43  if (gameObject.activeInHierarchy)
44  {
45  // if you want log the position of mode tip text, just uncomment it.
46  // Debug.Log("pos: " + gameObject.transform.position);
47  switch (MeasureManager.Instance.Mode)
48  {
49  case GeometryMode.Line:
50  if (!text.text.Contains(LineMode))
51  {
52  text.text = LineMode;
53  }
54  break;
55  default:
56  if (!text.text.Contains(PolygonMode))
57  {
58  text.text = PolygonMode;
59  }
60  break;
61  }
62 
63  fadeTime = 100;
64  // fade tip text
65  if (fadeTime == 0)
66  {
67  var color = material.color;
68  fadeTime = 100;
69  color.a = 1f;
70  material.color = color;
71  gameObject.SetActive(false);
72  }
73  else
74  {
75  var color = material.color;
76  color.a -= 0.01f;
77  material.color = color;
78  fadeTime--;
79  }
80  }
81  }
82  }
83 }
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
override void OnDestroy()
Base OnDestroy method that destroys the Singleton&#39;s unique instance. Called by Unity when destroying ...
Definition: ModeTip.cs:35
provide a tip text of current measure mode
Definition: ModeTip.cs:12
Singleton behaviour class, used for components that should only have one instance.
Definition: Singleton.cs:14