-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimationStateBehavior.cs
65 lines (60 loc) · 2.07 KB
/
AnimationStateBehavior.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using UnityEngine;
public class AnimationStateBehavior : StateMachineBehaviour
{
[System.Serializable]
public class AnimationAction
{
public string parameterName;
public ActionType actionType;
public float floatValue;
public int intValue;
public bool boolValue;
public bool setTrigger; // New field to determine whether to set or reset the trigger
public enum ActionType
{
Float,
Int,
Bool,
Trigger
}
}
public AnimationAction[] actions;
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
ApplyActions(animator);
}
private void ApplyActions(Animator animator)
{
if (actions != null)
{
foreach (var action in actions)
{
switch (action.actionType)
{
case AnimationAction.ActionType.Float:
animator.SetFloat(action.parameterName, action.floatValue);
break;
case AnimationAction.ActionType.Int:
animator.SetInteger(action.parameterName, action.intValue);
break;
case AnimationAction.ActionType.Bool:
animator.SetBool(action.parameterName, action.boolValue);
break;
case AnimationAction.ActionType.Trigger:
if (action.setTrigger)
{
animator.SetTrigger(action.parameterName);
}
else
{
animator.ResetTrigger(action.parameterName);
}
break;
default:
Debug.LogError("Unsupported action type");
break;
}
}
}
}
}