浏览代码

Initialize skeleton on start.

NathanSweet 12 年之前
父节点
当前提交
5070b21341
共有 3 个文件被更改,包括 12 次插入10 次删除
  1. 10 8
      spine-tk2d/Code/tk2dSpineSkeleton.cs
  2. 二进制
      spine-tk2d/Example/Example.unity
  3. 2 2
      spine-tk2d/Example/Scripts/tk2dSpineboy.cs

+ 10 - 8
spine-tk2d/Code/tk2dSpineSkeleton.cs

@@ -29,9 +29,12 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
 		vertexPositions = new float[8];
 	}
 	
+	void Start () {
+		Initialize();
+	}
+	
 	void Update () {
-		SkeletonData skeletonData = (skeletonDataAsset != null) ? skeletonDataAsset.GetSkeletonData() : null;
-		
+		SkeletonData skeletonData = skeletonDataAsset == null ? null : skeletonDataAsset.GetSkeletonData();
 		if (skeletonData == null) {
 			Clear();
 			return;
@@ -46,6 +49,7 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
 	}
 	
 	private void Clear() {
+		Debug.Log("clear?!");
 		GetComponent<MeshFilter>().mesh = null;
 		DestroyImmediate(mesh);
 		mesh = null;
@@ -161,14 +165,12 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor
 	
 	private void UpdateAnimation() {
 		// Check if we need to stop current animation
-		if(state.Animation != null && animationName == null) {
+		if (state.Animation != null && animationName == null) {
 			state.ClearAnimation();
-		}
-		
-		// Check for different animation name or animation end
-		else if(state.Animation == null || animationName != state.Animation.Name) {
+		} else if (state.Animation == null || animationName != state.Animation.Name) {
+			// Check for different animation name or animation end
 			Spine.Animation animation = skeleton.Data.FindAnimation(animationName);
-			if(animation != null) state.SetAnimation(animation,loop);
+			if (animation != null) state.SetAnimation(animation,loop);
 		}
 		
 		state.Loop = loop;

二进制
spine-tk2d/Example/Example.unity


+ 2 - 2
spine-tk2d/Example/Scripts/tk2dSpineboy.cs

@@ -18,9 +18,9 @@ public class tk2dSpineboy : MonoBehaviour {
 	/*
 	 */
 	void Update() {
-		if(skeleton.loop) return;
+		if (skeleton.loop) return;
 		
-		if(skeleton.state.Time >= skeleton.state.Animation.Duration - 0.25) {
+		if (skeleton.state.Animation != null && skeleton.state.Time >= skeleton.state.Animation.Duration - 0.25) {
 			skeleton.animationName = "walk";
 			skeleton.loop = true;
 		}