AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SelectedObjectMessageReceiver.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))]
12  public class SelectedObjectMessageReceiver : MonoBehaviour, IInputClickHandler
13  {
14  [Tooltip("Object color changes to this when selected.")]
15  public Color SelectedColor = Color.red;
16 
17  private Color originalColor;
18  private Material cachedMaterial;
19 
20  private void Awake()
21  {
22  cachedMaterial = GetComponent<Renderer>().material;
23  originalColor = cachedMaterial.GetColor("_Color");
24  }
25 
26  public void OnSelectObject()
27  {
28  cachedMaterial.SetColor("_Color", SelectedColor);
29  }
30 
31  public void OnClearSelection()
32  {
33  cachedMaterial.SetColor("_Color", originalColor);
34  }
35 
36  private void OnDestroy()
37  {
38  DestroyImmediate(cachedMaterial);
39  }
40 
41  public void OnInputClicked(InputClickedEventData eventData)
42  {
43  OnClearSelection();
44  if (eventData.selectedObject == gameObject)
45  {
46  OnSelectObject();
47  }
48  }
49  }
50 }
This particular implementation controls object appearance by changing its color when selected...
Interface to implement to react to simple click input.
Describes an input event that involves a tap.