IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
ToolWidget.cs
1 using UnityEngine;
2 using UnityEngine.UI;
3 using System.Collections;
4 
5 public class ToolWidget : MonoBehaviour {
6 
7  public Sprite ToolIcon;
8 
9  public Sprite iconLeftControllerLeft;
10  public Sprite iconLeftControllerRight;
11  public Sprite iconLeftControllerUp;
12  public Sprite iconLeftControllerDown;
13  public Sprite iconRightControllerLeft;
14  public Sprite iconRightControllerRight;
15  public Sprite iconRightControllerUp;
16  public Sprite iconRightControllerDown;
17 
19  public enum ToolDisplayTime {
20  WhenPatientIsLoaded,
21  WhenNoPatientIsLoaded,
22  Always
23  };
24 
25  public ToolDisplayTime displayTime = ToolDisplayTime.WhenPatientIsLoaded;
26 
27 
28  // Use this for initialization
29  void Start () {
30 
31  // Set material for all texts:
32  Material mat = new Material(Shader.Find("Custom/TextShader"));
33  mat.renderQueue += 2; // overlay!
34  Component[] texts;
35  texts = GetComponentsInChildren( typeof(Text), true );
36 
37  if( texts != null )
38  {
39  foreach (Text t in texts)
40  t.material = mat;
41  }
42 
43  Material material = new Material(Shader.Find("Custom/UIObject"));
44  material.renderQueue += 2; // overlay!
45  Component[] images;
46  images = GetComponentsInChildren( typeof(Image), true );
47 
48  if( images != null )
49  {
50  foreach (Image i in images)
51  {
52  if( i.material.name == "Default UI Material")
53  i.material = material;
54  }
55  }
56  }
57 
58  public void OnEnable()
59  {
60  // Move the object to the current anchor (to "helmet" or to controller)
61  Invoke ("MoveToUIAnchor",0.0001f);
62 
63  InputDeviceManager.instance.setLeftControllerTouchpadIcons (
64  iconLeftControllerLeft, iconLeftControllerRight, iconLeftControllerUp, iconLeftControllerDown);
65 
66  InputDeviceManager.instance.setRightControllerTouchpadIcons (
67  iconRightControllerLeft, iconRightControllerRight, iconRightControllerUp, iconRightControllerDown);
68  }
69 
70  public void OnDisable()
71  {
72  // Move the object back to the toolControl:
73  Invoke ("MoveBackToToolControl",0.0001f);
74  }
75 
76  private void MoveToUIAnchor()
77  {
78  if( ToolUIAnchor.instance != null )
79  transform.SetParent (ToolUIAnchor.instance.transform, false);
80  }
81  private void MoveBackToToolControl()
82  {
83  transform.SetParent (ToolControl.instance.transform, false);
84  }
85 }