mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-25 11:11:24 +08:00
[unity] Prevent initialize from triggering first AnimationState update. + Cleanup.
This commit is contained in:
parent
3e997a2765
commit
b190af431c
@ -97,19 +97,13 @@ namespace Spine.Unity {
|
|||||||
if (string.IsNullOrEmpty(value)) {
|
if (string.IsNullOrEmpty(value)) {
|
||||||
state.ClearTrack(0);
|
state.ClearTrack(0);
|
||||||
} else {
|
} else {
|
||||||
TrySetAnimation(value, loop);
|
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(value);
|
||||||
|
if (animationObject != null)
|
||||||
|
state.SetAnimation(0, animationObject, loop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackEntry TrySetAnimation (string animationName, bool animationLoop) {
|
|
||||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(animationName);
|
|
||||||
if (animationObject != null)
|
|
||||||
return state.SetAnimation(0, animationObject, animationLoop);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Whether or not <see cref="AnimationName"/> should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.</summary>
|
/// <summary>Whether or not <see cref="AnimationName"/> should loop. This only applies to the initial animation specified in the inspector, or any subsequent Animations played through .AnimationName. Animations set through state.SetAnimation are unaffected.</summary>
|
||||||
public bool loop;
|
public bool loop;
|
||||||
|
|
||||||
@ -154,26 +148,24 @@ namespace Spine.Unity {
|
|||||||
|
|
||||||
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
|
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (!string.IsNullOrEmpty(_animationName)) {
|
if (!string.IsNullOrEmpty(_animationName)) {
|
||||||
if (Application.isPlaying) {
|
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(_animationName);
|
||||||
TrackEntry startingTrack = TrySetAnimation(_animationName, loop);
|
if (animationObject != null) {
|
||||||
if (startingTrack != null)
|
animationObject.PoseSkeleton(skeleton, 0f);
|
||||||
Update(0);
|
skeleton.UpdateWorldTransform();
|
||||||
} else {
|
|
||||||
// Assume SkeletonAnimation is valid for skeletonData and skeleton. Checked above.
|
#if UNITY_EDITOR
|
||||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(_animationName);
|
if (Application.isPlaying) {
|
||||||
if (animationObject != null)
|
#endif
|
||||||
animationObject.PoseSkeleton(skeleton, 0f);
|
|
||||||
|
// Make this block not run in Unity Editor edit mode.
|
||||||
|
state.SetAnimation(0, animationObject, loop);
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (!string.IsNullOrEmpty(_animationName)) {
|
|
||||||
TrackEntry startingTrack = TrySetAnimation(_animationName, loop);
|
|
||||||
if (startingTrack != null)
|
|
||||||
Update(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update () {
|
void Update () {
|
||||||
|
|||||||
@ -166,7 +166,8 @@ namespace Spine.Unity {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears the previously generated mesh and resets the skeleton's pose.</summary>
|
/// Clears the previously generated mesh and resets the skeleton's pose.</summary>
|
||||||
public virtual void ClearState () {
|
public virtual void ClearState () {
|
||||||
meshFilter.sharedMesh = null;
|
var meshFilter = GetComponent<MeshFilter>();
|
||||||
|
if (meshFilter != null) meshFilter.sharedMesh = null;
|
||||||
currentInstructions.Clear();
|
currentInstructions.Clear();
|
||||||
if (skeleton != null) skeleton.SetToSetupPose();
|
if (skeleton != null) skeleton.SetToSetupPose();
|
||||||
}
|
}
|
||||||
@ -193,7 +194,7 @@ namespace Spine.Unity {
|
|||||||
valid = false;
|
valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skeletonDataAsset) {
|
if (skeletonDataAsset == null) {
|
||||||
if (logErrors) Debug.LogError("Missing SkeletonData asset.", this);
|
if (logErrors) Debug.LogError("Missing SkeletonData asset.", this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -244,24 +244,24 @@ namespace Spine.Unity {
|
|||||||
if (!string.IsNullOrEmpty(initialSkinName))
|
if (!string.IsNullOrEmpty(initialSkinName))
|
||||||
skeleton.SetSkin(initialSkinName);
|
skeleton.SetSkin(initialSkinName);
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
if (!string.IsNullOrEmpty(startingAnimation)) {
|
if (!string.IsNullOrEmpty(startingAnimation)) {
|
||||||
if (Application.isPlaying) {
|
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);
|
||||||
state.SetAnimation(0, startingAnimation, startingLoop);
|
if (animationObject != null) {
|
||||||
} else {
|
animationObject.PoseSkeleton(skeleton, 0f);
|
||||||
// Assume SkeletonAnimation is valid for skeletonData and skeleton. Checked above.
|
skeleton.UpdateWorldTransform();
|
||||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);
|
|
||||||
if (animationObject != null)
|
#if UNITY_EDITOR
|
||||||
animationObject.PoseSkeleton(skeleton, 0);
|
if (Application.isPlaying) {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Make this block not run in Unity Editor edit mode.
|
||||||
|
state.SetAnimation(0, animationObject, startingLoop);
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
Update(0);
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (!string.IsNullOrEmpty(startingAnimation)) {
|
|
||||||
state.SetAnimation(0, startingAnimation, startingLoop);
|
|
||||||
Update(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateMesh () {
|
public void UpdateMesh () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user