-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from TORISOUP/add_ObservableStateMachineTrigger
Add ObservableStateMachineTrigger to R3.Unity
- Loading branch information
Showing
3 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/R3.Unity/Assets/R3.Unity/Runtime/Triggers/ObservableStateMachineTrigger.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#if R3_ANIMATION_SUPPORT | ||
using UnityEngine; | ||
|
||
namespace R3.Triggers | ||
{ | ||
public class ObservableStateMachineTrigger : StateMachineBehaviour | ||
{ | ||
public class OnStateInfo | ||
{ | ||
public Animator Animator { get; private set; } | ||
public AnimatorStateInfo StateInfo { get; private set; } | ||
public int LayerIndex { get; private set; } | ||
|
||
public OnStateInfo(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | ||
{ | ||
Animator = animator; | ||
StateInfo = stateInfo; | ||
LayerIndex = layerIndex; | ||
} | ||
} | ||
|
||
public class OnStateMachineInfo | ||
{ | ||
public Animator Animator { get; private set; } | ||
public int StateMachinePathHash { get; private set; } | ||
|
||
public OnStateMachineInfo(Animator animator, int stateMachinePathHash) | ||
{ | ||
Animator = animator; | ||
StateMachinePathHash = stateMachinePathHash; | ||
} | ||
} | ||
|
||
// OnStateExit | ||
Subject<OnStateInfo> onStateExit; | ||
|
||
public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | ||
{ | ||
onStateExit?.OnNext(new OnStateInfo(animator, stateInfo, layerIndex)); | ||
} | ||
|
||
public Observable<OnStateInfo> OnStateExitAsObservable() | ||
{ | ||
return onStateExit ??= new Subject<OnStateInfo>(); | ||
} | ||
|
||
// OnStateEnter | ||
Subject<OnStateInfo> onStateEnter; | ||
|
||
public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | ||
{ | ||
onStateEnter?.OnNext(new OnStateInfo(animator, stateInfo, layerIndex)); | ||
} | ||
|
||
public Observable<OnStateInfo> OnStateEnterAsObservable() | ||
{ | ||
return onStateEnter ??= new Subject<OnStateInfo>(); | ||
} | ||
|
||
// OnStateIK | ||
Subject<OnStateInfo> onStateIK; | ||
|
||
public override void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | ||
{ | ||
if(onStateIK !=null) onStateIK.OnNext(new OnStateInfo(animator, stateInfo, layerIndex)); | ||
} | ||
|
||
public Observable<OnStateInfo> OnStateIKAsObservable() | ||
{ | ||
return onStateIK ??= new Subject<OnStateInfo>(); | ||
} | ||
|
||
// OnStateUpdate | ||
Subject<OnStateInfo> onStateUpdate; | ||
|
||
public override void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) | ||
{ | ||
onStateUpdate?.OnNext(new OnStateInfo(animator, stateInfo, layerIndex)); | ||
} | ||
|
||
public Observable<OnStateInfo> OnStateUpdateAsObservable() | ||
{ | ||
return onStateUpdate ??= new Subject<OnStateInfo>(); | ||
} | ||
|
||
// OnStateMachineEnter | ||
Subject<OnStateMachineInfo> onStateMachineEnter; | ||
|
||
public override void OnStateMachineEnter(Animator animator, int stateMachinePathHash) | ||
{ | ||
onStateMachineEnter?.OnNext(new OnStateMachineInfo(animator, stateMachinePathHash)); | ||
} | ||
|
||
public Observable<OnStateMachineInfo> OnStateMachineEnterAsObservable() | ||
{ | ||
return onStateMachineEnter ??= new Subject<OnStateMachineInfo>(); | ||
} | ||
|
||
// OnStateMachineExit | ||
Subject<OnStateMachineInfo> onStateMachineExit; | ||
|
||
public override void OnStateMachineExit(Animator animator, int stateMachinePathHash) | ||
{ | ||
onStateMachineExit?.OnNext(new OnStateMachineInfo(animator, stateMachinePathHash)); | ||
} | ||
|
||
public Observable<OnStateMachineInfo> OnStateMachineExitAsObservable() | ||
{ | ||
return onStateMachineExit ??= new Subject<OnStateMachineInfo>(); | ||
} | ||
} | ||
} | ||
#endif |
11 changes: 11 additions & 0 deletions
11
src/R3.Unity/Assets/R3.Unity/Runtime/Triggers/ObservableStateMachineTrigger.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.