AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
FocusedObjectTest.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 
6 namespace HoloToolkit.Unity.InputModule.Tests
7 {
11  [RequireComponent(typeof(Renderer))]
13  {
14  [Tooltip("Object color changes to this when focused.")]
15  public Color FocusedColor = Color.red;
16  private const float DefaultSizeFactor = 2.0f;
17 
18  [Tooltip("Size multiplier to use when scaling the object up and down.")]
19  public float SizeFactor = DefaultSizeFactor;
20 
21  private Color originalColor;
22  private Material cachedMaterial;
23 
24  private void Awake()
25  {
26  cachedMaterial = GetComponent<Renderer>().material;
27  originalColor = cachedMaterial.GetColor("_Color");
28  if (SizeFactor <= 0.0f)
29  {
30  SizeFactor = DefaultSizeFactor;
31  }
32  }
33 
34  public void OnFocusEnter()
35  {
36  cachedMaterial.SetColor("_Color", FocusedColor);
37  }
38 
39  public void OnFocusExit()
40  {
41  cachedMaterial.SetColor("_Color", originalColor);
42  }
43 
44  private void OnDestroy()
45  {
46  DestroyImmediate(cachedMaterial);
47  }
48 
50  {
51  switch (eventData.RecognizedText.ToLower())
52  {
53  case "make bigger":
54  OnMakeBigger();
55  break;
56  case "make smaller":
57  OnMakeSmaller();
58  break;
59  }
60  }
61 
62  public void OnMakeBigger()
63  {
64  Vector3 scale = transform.localScale;
65  scale *= SizeFactor;
66  transform.localScale = scale;
67  }
68 
69  public void OnMakeSmaller()
70  {
71  Vector3 scale = transform.localScale;
72  scale /= SizeFactor;
73  transform.localScale = scale;
74  }
75 
76  public void OnFocusEnter(PointerSpecificEventData eventData)
77  {
78  cachedMaterial.SetColor("_Color", FocusedColor);
79  }
80 
81  public void OnFocusExit(PointerSpecificEventData eventData)
82  {
83  cachedMaterial.SetColor("_Color", originalColor);
84  }
85  }
86 }
Interface to implement to react to per-pointer focus enter/exit.
This class shows how to handle focus events and speech input events.
void OnSpeechKeywordRecognized(SpeechEventData eventData)
void OnFocusExit(PointerSpecificEventData eventData)
Event dispatched associated with a specific pointer.
string RecognizedText
The text that was recognized.
Interface to implement to react to focus enter/exit.
Definition: IFocusable.cs:11
Describes an input event that involves keyword recognition.
Interface to implement to react to speech recognition.
void OnFocusEnter(PointerSpecificEventData eventData)