Kaynağa Gözat

[Unity] 3.1.05 compatibility and cleanup for SkeletonExtensions.

pharan 9 yıl önce
ebeveyn
işleme
7a3c24b4fb

+ 13 - 17
spine-unity/Assets/spine-unity/SkeletonExtensions.cs

@@ -126,11 +126,12 @@ namespace Spine.Unity {
 		/// <summary>Resets the DrawOrder to the Setup Pose's draw order</summary>
 		public static void SetDrawOrderToSetupPose (this Skeleton skeleton) {
 			var slotsItems = skeleton.slots.Items;
-			var drawOrder = skeleton.drawOrder;
+			int n = skeleton.slots.Count;
 
+			var drawOrder = skeleton.drawOrder;
 			drawOrder.Clear(false);
-			for (int i = 0, n = skeleton.slots.Count; i < n; i++)
-				drawOrder.Add(slotsItems[i]);
+			drawOrder.GrowIfNeeded(n);
+			System.Array.Copy(slotsItems, drawOrder.Items, n);
 		}
 
 		/// <summary>Resets the color of a slot to Setup Pose value.</summary>
@@ -160,14 +161,12 @@ namespace Spine.Unity {
 			for (int i = 0, n = timelinesItems.Length; i < n; i++)
 				timelinesItems[i].SetToSetupPose(skeleton);
 		}
-
-		// For each timeline type.
-		// Timelines know how to apply themselves based on skeleton data; They should know how to reset the skeleton back to skeleton data?
+			
 		public static void SetToSetupPose (this Timeline timeline, Skeleton skeleton) {
 			if (timeline != null) {
 				// sorted according to assumed likelihood here
 
-				// Bone stuff
+				// Bone
 				if (timeline is RotateTimeline) {
 					var bone = skeleton.bones.Items[((RotateTimeline)timeline).boneIndex];
 					bone.rotation = bone.data.rotation;
@@ -181,13 +180,12 @@ namespace Spine.Unity {
 					bone.scaleY = bone.data.scaleY;
 
 
-				// Attachment stuff. How do you reset FFD?
-				} else if (timeline is FFDTimeline) {
-					var slot = skeleton.slots.Items[((FFDTimeline)timeline).slotIndex];
-					slot.attachmentVerticesCount = 0;	// This causes (Weighted)MeshAttachment.ComputeWorldVertices to use its internal(stateless) vertex array.
-					//slot.attachmentTime = bone.skeleton.time; // Currently inconsequential. (Spine 3.1)
+				// Attachment
+				} else if (timeline is FfdTimeline) {
+					var slot = skeleton.slots.Items[((FfdTimeline)timeline).slotIndex];
+					slot.attachmentVerticesCount = 0;
 				
-				// Slot stuff. This is heavy to do every frame. Maybe not do it?
+				// Slot
 				} else if (timeline is AttachmentTimeline) {
 					skeleton.SetSlotAttachmentToSetupPose(((AttachmentTimeline)timeline).slotIndex);
 
@@ -195,7 +193,7 @@ namespace Spine.Unity {
 					skeleton.slots.Items[((ColorTimeline)timeline).slotIndex].SetColorToSetupPose();
 
 
-				// Constraint Stuff
+				// Constraint
 				} else if (timeline is IkConstraintTimeline) {
 					var ikTimeline = (IkConstraintTimeline)timeline;
 					var ik = skeleton.ikConstraints.Items[ikTimeline.ikConstraintIndex];
@@ -203,16 +201,14 @@ namespace Spine.Unity {
 					ik.bendDirection = data.bendDirection;
 					ik.mix = data.mix;
 
-				// Skeleton stuff. Skeleton.SetDrawOrderToSetupPose. This is heavy to do every frame. Maybe not do it?
+				// Skeleton
 				} else if (timeline is DrawOrderTimeline) {
 					skeleton.SetDrawOrderToSetupPose();
 
-
 				}
 
 			}
 
-
 		}
 		#endregion
 	}