mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +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)) {
|
||||
state.ClearTrack(0);
|
||||
} 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>
|
||||
public bool loop;
|
||||
|
||||
@ -153,27 +147,25 @@ namespace Spine.Unity {
|
||||
return;
|
||||
|
||||
state = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
if (!string.IsNullOrEmpty(_animationName)) {
|
||||
if (Application.isPlaying) {
|
||||
TrackEntry startingTrack = TrySetAnimation(_animationName, loop);
|
||||
if (startingTrack != null)
|
||||
Update(0);
|
||||
} else {
|
||||
// Assume SkeletonAnimation is valid for skeletonData and skeleton. Checked above.
|
||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(_animationName);
|
||||
if (animationObject != null)
|
||||
animationObject.PoseSkeleton(skeleton, 0f);
|
||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(_animationName);
|
||||
if (animationObject != null) {
|
||||
animationObject.PoseSkeleton(skeleton, 0f);
|
||||
skeleton.UpdateWorldTransform();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (Application.isPlaying) {
|
||||
#endif
|
||||
|
||||
// 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 () {
|
||||
|
||||
@ -166,7 +166,8 @@ namespace Spine.Unity {
|
||||
/// <summary>
|
||||
/// Clears the previously generated mesh and resets the skeleton's pose.</summary>
|
||||
public virtual void ClearState () {
|
||||
meshFilter.sharedMesh = null;
|
||||
var meshFilter = GetComponent<MeshFilter>();
|
||||
if (meshFilter != null) meshFilter.sharedMesh = null;
|
||||
currentInstructions.Clear();
|
||||
if (skeleton != null) skeleton.SetToSetupPose();
|
||||
}
|
||||
@ -193,7 +194,7 @@ namespace Spine.Unity {
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!skeletonDataAsset) {
|
||||
if (skeletonDataAsset == null) {
|
||||
if (logErrors) Debug.LogError("Missing SkeletonData asset.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -244,24 +244,24 @@ namespace Spine.Unity {
|
||||
if (!string.IsNullOrEmpty(initialSkinName))
|
||||
skeleton.SetSkin(initialSkinName);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!string.IsNullOrEmpty(startingAnimation)) {
|
||||
if (Application.isPlaying) {
|
||||
state.SetAnimation(0, startingAnimation, startingLoop);
|
||||
} else {
|
||||
// Assume SkeletonAnimation is valid for skeletonData and skeleton. Checked above.
|
||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);
|
||||
if (animationObject != null)
|
||||
animationObject.PoseSkeleton(skeleton, 0);
|
||||
var animationObject = skeletonDataAsset.GetSkeletonData(false).FindAnimation(startingAnimation);
|
||||
if (animationObject != null) {
|
||||
animationObject.PoseSkeleton(skeleton, 0f);
|
||||
skeleton.UpdateWorldTransform();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
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 () {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user