AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SpriteCursor.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 System;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.InputModule
8 {
12  public class SpriteCursor : Cursor
13  {
14  [Serializable]
15  public struct SpriteCursorDatum
16  {
17  public string Name;
19  public Sprite CursorSprite;
20  public Color CursorColor;
21  }
22 
23  [SerializeField]
25 
29  public SpriteRenderer TargetRenderer;
30 
34  protected override void OnEnable()
35  {
36  if(TargetRenderer == null)
37  {
38  TargetRenderer = GetComponentInChildren<SpriteRenderer>();
39  }
40 
41  base.OnEnable();
42  }
43 
49  public override void OnCursorStateChange(CursorStateEnum state)
50  {
51  base.OnCursorStateChange(state);
52 
53  if (state != CursorStateEnum.Contextual)
54  {
55  for (int i = 0; i < CursorStateData.Length; i++)
56  {
57  if (CursorStateData[i].CursorState == state)
58  {
59  SetCursorState(CursorStateData[i]);
60  }
61  }
62  }
63  }
64 
69  private void SetCursorState(SpriteCursorDatum stateDatum)
70  {
71  // Return if we do not have an animator
72  if (TargetRenderer != null)
73  {
74  TargetRenderer.sprite = stateDatum.CursorSprite;
75  TargetRenderer.color = stateDatum.CursorColor;
76  }
77  }
78 
79  }
80 
81 }
SpriteRenderer TargetRenderer
Sprite renderer to change. If null find one in children
Definition: SpriteCursor.cs:29
Object that represents a cursor comprised of sprites and colors for each state
Definition: SpriteCursor.cs:12
override void OnEnable()
On enable look for a sprite renderer on children
Definition: SpriteCursor.cs:34
CursorStateEnum
Enum for current cursor state
override void OnCursorStateChange(CursorStateEnum state)
Override OnCursorState change to set the correct sprite state for the cursor
Definition: SpriteCursor.cs:49