initial upload
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
|
||||
public abstract class AnimationModifier : MonoBehaviour
|
||||
{
|
||||
protected Animator animator;
|
||||
protected Baker baker;
|
||||
|
||||
public virtual void OnInitiate(Baker baker, Animator animator)
|
||||
{
|
||||
this.baker = baker;
|
||||
this.animator = animator;
|
||||
}
|
||||
|
||||
public virtual void OnStartClip(AnimationClip clip) { }
|
||||
|
||||
public virtual void OnBakerUpdate(float normalizedTime) { }
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f66200036e67da4998b9ac08649304f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
public class AnimationModifierStack : MonoBehaviour
|
||||
{
|
||||
public AnimationModifier[] modifiers = new AnimationModifier[0];
|
||||
|
||||
private Animator animator;
|
||||
private Baker baker;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
baker = GetComponent<Baker>();
|
||||
baker.OnStartClip += OnBakerStartClip;
|
||||
baker.OnUpdateClip += OnBakerUpdateClip;
|
||||
|
||||
foreach (AnimationModifier m in modifiers)
|
||||
{
|
||||
m.OnInitiate(baker, animator);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBakerStartClip(AnimationClip clip, float normalizedTime)
|
||||
{
|
||||
foreach (AnimationModifier m in modifiers)
|
||||
{
|
||||
m.OnStartClip(clip);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBakerUpdateClip(AnimationClip clip, float normalizedTime)
|
||||
{
|
||||
foreach (AnimationModifier m in modifiers)
|
||||
{
|
||||
if (!m.enabled) continue;
|
||||
m.OnBakerUpdate(normalizedTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!animator.enabled && !baker.isBaking) return;
|
||||
if (baker.isBaking && baker.mode == Baker.Mode.AnimationClips) return;
|
||||
if (animator.runtimeAnimatorController == null) return;
|
||||
|
||||
AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
|
||||
float n = info.normalizedTime;
|
||||
|
||||
foreach (AnimationModifier m in modifiers)
|
||||
{
|
||||
if (!m.enabled) continue;
|
||||
m.OnBakerUpdate(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: addea154dd3a3e442abb7c12a65ebf8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user