mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 18:56:54 +08:00
MixMode list added to SkeletonAnimator
This commit is contained in:
parent
39e754315e
commit
f25f33fbc5
@ -34,22 +34,22 @@ using Spine;
|
|||||||
|
|
||||||
[CustomEditor(typeof(SkeletonAnimator))]
|
[CustomEditor(typeof(SkeletonAnimator))]
|
||||||
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
public class SkeletonAnimatorInspector : SkeletonRendererInspector {
|
||||||
protected SerializedProperty animationName, loop, timeScale;
|
protected SerializedProperty layerMixModes;
|
||||||
protected bool isPrefab;
|
|
||||||
|
|
||||||
protected override void OnEnable () {
|
protected override void OnEnable () {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
animationName = serializedObject.FindProperty("_animationName");
|
layerMixModes = serializedObject.FindProperty("layerMixModes");
|
||||||
loop = serializedObject.FindProperty("loop");
|
|
||||||
timeScale = serializedObject.FindProperty("timeScale");
|
|
||||||
|
|
||||||
if (PrefabUtility.GetPrefabType(this.target) == PrefabType.Prefab)
|
|
||||||
isPrefab = true;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void gui () {
|
protected override void gui () {
|
||||||
base.gui();
|
base.gui();
|
||||||
|
|
||||||
|
|
||||||
|
EditorGUILayout.PropertyField(layerMixModes, true);
|
||||||
|
|
||||||
|
serializedObject.ApplyModifiedProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,9 @@ using Spine;
|
|||||||
[RequireComponent(typeof(Animator))]
|
[RequireComponent(typeof(Animator))]
|
||||||
public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
|
public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
|
||||||
|
|
||||||
|
public enum MixMode { AlwaysMix, MixNext, SpineStyle }
|
||||||
|
public MixMode[] layerMixModes = new MixMode[0];
|
||||||
|
|
||||||
public event UpdateBonesDelegate UpdateLocal {
|
public event UpdateBonesDelegate UpdateLocal {
|
||||||
add { _UpdateLocal += value; }
|
add { _UpdateLocal += value; }
|
||||||
remove { _UpdateLocal -= value; }
|
remove { _UpdateLocal -= value; }
|
||||||
@ -42,12 +45,18 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update () {
|
void Update () {
|
||||||
if (skeleton == null)
|
if (!valid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (layerMixModes.Length != animator.layerCount) {
|
||||||
|
System.Array.Resize<MixMode>(ref layerMixModes, animator.layerCount);
|
||||||
|
}
|
||||||
|
|
||||||
skeleton.Update(Time.deltaTime);
|
skeleton.Update(Time.deltaTime);
|
||||||
|
|
||||||
//apply
|
//apply
|
||||||
@ -64,22 +73,79 @@ public class SkeletonAnimator : SkeletonRenderer, ISkeletonAnimation {
|
|||||||
var nextStateInfo = animator.GetNextAnimatorStateInfo(i);
|
var nextStateInfo = animator.GetNextAnimatorStateInfo(i);
|
||||||
var nextClipInfo = animator.GetNextAnimationClipState(i);
|
var nextClipInfo = animator.GetNextAnimationClipState(i);
|
||||||
|
|
||||||
foreach (var info in clipInfo) {
|
MixMode mode = layerMixModes[i];
|
||||||
float weight = info.weight * layerWeight;
|
|
||||||
if (weight == 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
float time = stateInfo.normalizedTime * info.clip.length;
|
if (mode == MixMode.AlwaysMix) {
|
||||||
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null, weight);
|
//always use Mix instead of Applying the first non-zero weighted clip
|
||||||
}
|
foreach (var info in clipInfo) {
|
||||||
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
foreach (var info in nextClipInfo) {
|
float time = stateInfo.normalizedTime * info.clip.length;
|
||||||
float weight = info.weight * layerWeight;
|
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null, weight);
|
||||||
if (weight == 0)
|
}
|
||||||
continue;
|
|
||||||
|
|
||||||
float time = nextStateInfo.normalizedTime * info.clip.length;
|
foreach (var info in nextClipInfo) {
|
||||||
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null, weight);
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float time = nextStateInfo.normalizedTime * info.clip.length;
|
||||||
|
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null, weight);
|
||||||
|
}
|
||||||
|
} else if (mode >= MixMode.MixNext) {
|
||||||
|
//apply first non-zero weighted clip
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
for (; c < clipInfo.Length; c++) {
|
||||||
|
var info = clipInfo[c];
|
||||||
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float time = stateInfo.normalizedTime * info.clip.length;
|
||||||
|
animationTable[info.clip.name].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mix the rest
|
||||||
|
for (; c < clipInfo.Length; c++) {
|
||||||
|
var info = clipInfo[c];
|
||||||
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float time = stateInfo.normalizedTime * info.clip.length;
|
||||||
|
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, stateInfo.loop, null, weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
c = 0;
|
||||||
|
|
||||||
|
//apply next clip directly instead of mixing (ie: no crossfade, ignores mecanim transition weights)
|
||||||
|
if (mode == MixMode.SpineStyle) {
|
||||||
|
for (; c < nextClipInfo.Length; c++) {
|
||||||
|
var info = nextClipInfo[c];
|
||||||
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float time = nextStateInfo.normalizedTime * info.clip.length;
|
||||||
|
animationTable[info.clip.name].Apply(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//mix the rest
|
||||||
|
for (; c < nextClipInfo.Length; c++) {
|
||||||
|
var info = nextClipInfo[c];
|
||||||
|
float weight = info.weight * layerWeight;
|
||||||
|
if (weight == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
float time = nextStateInfo.normalizedTime * info.clip.length;
|
||||||
|
animationTable[info.clip.name].Mix(skeleton, Mathf.Max(0, time - deltaTime), time, nextStateInfo.loop, null, weight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user