Skip to content

Commit e4ae562

Browse files
committed
Added API for playing animator w/ or without coroutine
1 parent db3028a commit e4ae562

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

Assets/AdncAnimatorVariableStates/Examples/Default/New Animator Controller.controller

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/AdncAnimatorVariableStates/Examples/Default/New Animator Controller.controller.meta

Lines changed: 0 additions & 10 deletions
This file was deleted.

Assets/AdncAnimatorVariableStates/Examples/Default/Playback.asset

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@ MonoBehaviour:
1515
floats: []
1616
ints: []
1717
triggers: []
18-
waitForCondition: 0
18+
waitForCondition: 1
1919
conditions:
20-
- varType: 0
21-
varBool:
20+
- variableType: 0
21+
variableBool:
22+
name: a
23+
value: 0
24+
compareValues: 0
25+
variableFloat:
26+
name:
27+
value: 0
28+
variableInt:
2229
name:
2330
value: 0
24-
compareNumbers: 0
25-
VarFloat:
31+
- variableType: 1
32+
variableBool:
33+
name: b
34+
value: 1
35+
compareValues: 0
36+
variableFloat:
2637
name:
2738
value: 0
28-
VarInt:
39+
variableInt:
2940
name:
3041
value: 0

Assets/AdncAnimatorVariableStates/Scripts/AnimatorPlayback/AnimatorPlayback.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ public class AnimatorPlayback : ScriptableObject {
3030
};
3131

3232
/// <summary>
33-
/// Set the Animator variables
33+
/// Play the animation without a callback that checks if a specific condition has been met
3434
/// </summary>
3535
/// <param name="anim"></param>
36-
/// <param name="completeCallback">Fired when the complete condition is met. No complete
37-
/// condition will cause this to fire immediately</param>
38-
public void Play (Animator anim, Action completeCallback = null) {
36+
/// <returns></returns>
37+
public bool Play (Animator anim) {
38+
if (anim == null) {
39+
return false;
40+
}
41+
3942
foreach (var varBool in bools) {
4043
anim.SetBool(varBool.name, varBool.value);
4144
}
@@ -52,7 +55,37 @@ public void Play (Animator anim, Action completeCallback = null) {
5255
anim.SetTrigger(varTrigger.name);
5356
}
5457

55-
// @TODO Start coroutine here (see old implementation in pathfinding 2D)
58+
return true;
59+
}
60+
61+
/// <summary>
62+
/// Play the animation with a coroutine that returns when the required condition has been met
63+
/// </summary>
64+
/// <param name="anim"></param>
65+
/// <returns></returns>
66+
public IEnumerator PlayCoroutine (Animator anim) {
67+
if (!Play(anim) || !waitForCondition) {
68+
yield break;
69+
}
70+
71+
while (!IsConditionsMet(anim)) {
72+
yield return null;
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Checks if all conditions on the animator have been met
78+
/// </summary>
79+
/// <param name="anim"></param>
80+
/// <returns></returns>
81+
public bool IsConditionsMet (Animator anim) {
82+
var isValid = false;
83+
foreach (var condition in conditions) {
84+
isValid = condition.IsConditionMet(anim);
85+
if (!isValid) break;
86+
}
87+
88+
return isValid;
5689
}
5790
}
5891
}

0 commit comments

Comments
 (0)