AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
AnimatedCursor.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 {
13  public class AnimatedCursor : Cursor
14  {
18  [Obsolete("Use InputEnabledParameter")]
19  [Tooltip("Cursor State Data to use when enabling the cursor")]
21 
25  [Obsolete("Use InputDisabledParameter")]
26  [Tooltip("Cursor State Data to use when the cursor is disabled")]
28 
32  [Header("Animated Cursor State Data")]
33  [Tooltip("Cursor state data to use for its various states")]
34  [SerializeField]
36 
37  [Tooltip("Animator parameter to set when input is enabled.")]
39 
40  [Tooltip("Animator parameter to set when input is disabled.")]
42 
46  [SerializeField]
47  [Tooltip("Animator for the cursor")]
48  protected Animator CursorAnimator;
49 
53  public override void OnInputEnabled()
54  {
55  base.OnInputEnabled();
56  SetAnimatorParameter(InputEnabledParameter);
57  }
58 
62  public override void OnInputDisabled()
63  {
64  base.OnInputDisabled();
65  SetAnimatorParameter(InputDisabledParameter);
66  }
67 
72  protected override void OnActiveModifier(CursorModifier modifier)
73  {
74  base.OnActiveModifier(modifier);
75 
76  if (modifier != null)
77  {
78  if ((modifier.CursorParameters != null) && (modifier.CursorParameters.Length > 0))
79  {
80  OnCursorStateChange(CursorStateEnum.Contextual);
81  foreach (var param in modifier.CursorParameters)
82  {
83  SetAnimatorParameter(param);
84  }
85  }
86  }
87  else
88  {
89  OnCursorStateChange(CursorStateEnum.None);
90  }
91  }
92 
98  public override void OnCursorStateChange(CursorStateEnum state)
99  {
100  base.OnCursorStateChange(state);
101  if (state != CursorStateEnum.Contextual)
102  {
103  for (int i = 0; i < CursorStateData.Length; i++)
104  {
105  if (CursorStateData[i].CursorState == state)
106  {
107  SetAnimatorParameter(CursorStateData[i].Parameter);
108  }
109  }
110  }
111  }
112 
117  protected void SetAnimatorParameter(AnimatorParameter animationParameter)
118  {
119  // Return if we do not have an animator
120  if (CursorAnimator == null)
121  {
122  return;
123  }
124 
125  switch (animationParameter.Type)
126  {
127  case AnimatorControllerParameterType.Bool:
128  CursorAnimator.SetBool(animationParameter.NameHash, animationParameter.DefaultBool);
129  break;
130  case AnimatorControllerParameterType.Float:
131  CursorAnimator.SetFloat(animationParameter.NameHash, animationParameter.DefaultFloat);
132  break;
133  case AnimatorControllerParameterType.Int:
134  CursorAnimator.SetInteger(animationParameter.NameHash, animationParameter.DefaultInt);
135  break;
136  case AnimatorControllerParameterType.Trigger:
137  CursorAnimator.SetTrigger(animationParameter.NameHash);
138  break;
139  }
140  }
141  }
142 }
Component that can be added to any game object with a collider to modify how a cursor reacts when on ...
Animator CursorAnimator
Link the cursor animator
AnimCursorDatum [] CursorStateData
Serialized set of cursor state data
AnimCursorDatum EnableStateData
Enabled state Data when enabling
Data struct for cursor state information for the Animated Cursor, which leverages the Unity animation...
override void OnInputDisabled()
Change animation state when disabling input
override void OnCursorStateChange(CursorStateEnum state)
Override OnCursorState change to set the correct animation state for the cursor
override void OnActiveModifier(CursorModifier modifier)
Override to set the cursor animation trigger
Created a copy of the AnimatorControllerParameter because that class is not Serializable and cannot b...
override void OnInputEnabled()
Change animation state when enabling input
Animated cursor is a cursor driven using an animator to inject state information and animate accordin...
void SetAnimatorParameter(AnimatorParameter animationParameter)
Based on the type of animator state info pass it through to the animator
AnimCursorDatum DisableStateData
Disabled state Data when disabled
CursorStateEnum
Enum for current cursor state