AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
AnimControllerButton.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 using System;
6 
7 namespace HoloToolkit.Unity.Buttons
8 {
12  [RequireComponent(typeof(Animator))]
14  {
18  [HideInInspector]
20 
24  private Animator _animator;
25 
29  public override void OnStateChange(ButtonStateEnum newState)
30  {
31  if (_animator == null)
32  {
33  _animator = this.GetComponent<Animator>();
34  }
35 
36  if (AnimActions == null)
37  {
38  base.OnStateChange(newState);
39  return;
40  }
41 
42  for (int i = 0; i < AnimActions.Length; i++)
43  {
44  if (AnimActions[i].ButtonState == newState)
45  {
46  switch (AnimActions[i].ParamType)
47  {
48  case AnimatorControllerParameterType.Bool:
49  _animator.SetBool(AnimActions[i].ParamName, AnimActions[i].BoolValue);
50  break;
51  case AnimatorControllerParameterType.Float:
52  _animator.SetFloat(AnimActions[i].ParamName, AnimActions[i].FloatValue);
53  break;
54  case AnimatorControllerParameterType.Int:
55  _animator.SetInteger(AnimActions[i].ParamName, AnimActions[i].IntValue);
56  break;
57  case AnimatorControllerParameterType.Trigger:
58  _animator.SetTrigger(AnimActions[i].ParamName);
59  break;
60  default:
61  throw new ArgumentOutOfRangeException();
62  }
63  break;
64  }
65  }
66 
67  base.OnStateChange(newState);
68  }
69  }
70 }
ButtonStateEnum
State enum for buttons.
AnimatorControllerAction [] AnimActions
List of animation actions
override void OnStateChange(ButtonStateEnum newState)
On state change
Anim controller button offers as simple way to link button states to animation controller parameters ...