Explorar o código

Added children List<Bone> to Bone.cs and populated it inside Skeleton.cs
Changed Bone class to implement IEnumerable to easily traverse the child list.

Fenrisul %!s(int64=11) %!d(string=hai) anos
pai
achega
14219d8462
Modificáronse 2 ficheiros con 43 adicións e 1 borrados
  1. 38 1
      spine-csharp/src/Bone.cs
  2. 5 0
      spine-csharp/src/Skeleton.cs

+ 38 - 1
spine-csharp/src/Bone.cs

@@ -29,14 +29,50 @@
  *****************************************************************************/
 
 using System;
+using System.Collections;
+using System.Collections.Generic;
 
 namespace Spine {
-	public class Bone {
+	public class Bone : IEnumerable {
+		private sealed class Enumerator : IEnumerator{
+			private int currentIndex = -1;
+			private Bone outer;
+
+			internal Enumerator(Bone outer){
+				this.outer = outer;
+			}
+
+			public bool MoveNext(){
+				int childCount = this.outer.children.Count;
+				return (++this.currentIndex < childCount);
+			}
+
+			public void Reset(){
+				this.currentIndex = -1;
+			}
+
+			public object Current{
+				get{
+					return this.outer.children[this.currentIndex];
+				}
+			}
+		}
+		public IEnumerator GetEnumerator ()
+		{
+			return new Enumerator(this);
+		}
+
+		public Bone this[int i]{
+			get{
+				return children[i];
+			}
+		}
 		static public bool yDown;
 
 		internal BoneData data;
 		internal Skeleton skeleton;
 		internal Bone parent;
+		internal List<Bone> children;
 		internal float x, y, rotation, rotationIK, scaleX, scaleY;
 		internal float m00, m01, m10, m11;
 		internal float worldX, worldY, worldRotation, worldScaleX, worldScaleY;
@@ -70,6 +106,7 @@ namespace Spine {
 			this.data = data;
 			this.skeleton = skeleton;
 			this.parent = parent;
+			this.children = new List<Bone>();
 			SetToSetupPose();
 		}
 

+ 5 - 0
spine-csharp/src/Skeleton.cs

@@ -77,6 +77,11 @@ namespace Spine {
 				bones.Add(new Bone(boneData, this, parent));
 			}
 
+			foreach(Bone b in bones){
+				if(b.Parent != null)
+					b.Parent.children.Add(b);
+			}
+
 			slots = new List<Slot>(data.slots.Count);
 			drawOrder = new List<Slot>(data.slots.Count);
 			foreach (SlotData slotData in data.slots) {