void EvaluateFlags () {
		utilityBone = (SkeletonUtilityBone)target;
		skeletonUtility = utilityBone.skeletonUtility;

		if (Selection.objects.Length == 1) {
			containsFollows = utilityBone.mode == SkeletonUtilityBone.Mode.Follow;
			containsOverrides = utilityBone.mode == SkeletonUtilityBone.Mode.Override;
		} else {
			int boneCount = 0;
			foreach (Object o in Selection.objects) {
				if (o is GameObject) {
					GameObject go = (GameObject)o;
					SkeletonUtilityBone sub = go.GetComponent<SkeletonUtilityBone>();
					if (sub != null) {
						boneCount++;
						if (sub.mode == SkeletonUtilityBone.Mode.Follow)
							containsFollows = true;
						if (sub.mode == SkeletonUtilityBone.Mode.Override)
							containsOverrides = true;
					}
				}
			}
			
			if (boneCount > 1)
				multiObject = true;
		}
	}
	public static void AttachIcon(SkeletonUtilityBone utilityBone){
		Skeleton skeleton = utilityBone.skeletonUtility.skeletonRenderer.skeleton;
		Texture2D icon;
		if(utilityBone.bone.Data.Length == 0)
			icon = SpineEditorUtilities.Icons.nullBone;
		else
			icon = SpineEditorUtilities.Icons.boneNib;
		
		foreach(IkConstraint c in skeleton.IkConstraints){
			if(c.Target == utilityBone.bone){
				icon = SpineEditorUtilities.Icons.constraintNib;
				break;
			}
		}
		
		
		
		typeof(EditorGUIUtility).InvokeMember("SetIconForObject", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[2]{ utilityBone.gameObject, icon});
	}
    public GameObject SpawnBone(Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca)
    {
        GameObject go = new GameObject(bone.Data.Name);

        go.transform.parent = parent;

        SkeletonUtilityBone b = go.AddComponent <SkeletonUtilityBone>();

        b.skeletonUtility = this;
        b.position        = pos;
        b.rotation        = rot;
        b.scale           = sca;
        b.mode            = mode;
        b.zPosition       = true;
        b.Reset();
        b.bone     = bone;
        b.boneName = bone.Data.Name;
        b.valid    = true;

        if (mode == SkeletonUtilityBone.Mode.Override)
        {
            if (rot)
            {
                go.transform.localRotation = Quaternion.Euler(0, 0, b.bone.RotationIK);
            }

            if (pos)
            {
                go.transform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0);
            }

            go.transform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
        }

        return(go);
    }
Exemplo n.º 4
0
 public void UnregisterBone(SkeletonUtilityBone bone)
 {
     utilityBones.Remove(bone);
 }
    static void AttachRigidbody(SkeletonUtilityBone utilBone)
    {
        if (utilBone.GetComponent<Collider>() == null) {
            if (utilBone.bone.Data.Length == 0) {
                SphereCollider sphere = utilBone.gameObject.AddComponent<SphereCollider>();
                sphere.radius = 0.1f;
            } else {
                float length = utilBone.bone.Data.Length;
                BoxCollider box = utilBone.gameObject.AddComponent<BoxCollider>();
                box.size = new Vector3(length, length / 3, 0.2f);
                box.center = new Vector3(length / 2, 0, 0);
            }
        }

        utilBone.gameObject.AddComponent<Rigidbody>();
    }
Exemplo n.º 6
0
 protected virtual void OnEnable()
 {
     this.utilBone        = base.GetComponent <SkeletonUtilityBone>();
     this.skeletonUtility = SkeletonUtility.GetInParent <SkeletonUtility>(base.get_transform());
     this.skeletonUtility.RegisterConstraint(this);
 }
Exemplo n.º 7
0
        void OnEnable()
        {
            mode            = this.serializedObject.FindProperty("mode");
            boneName        = this.serializedObject.FindProperty("boneName");
            zPosition       = this.serializedObject.FindProperty("zPosition");
            position        = this.serializedObject.FindProperty("position");
            rotation        = this.serializedObject.FindProperty("rotation");
            scale           = this.serializedObject.FindProperty("scale");
            overrideAlpha   = this.serializedObject.FindProperty("overrideAlpha");
            hierarchy       = this.serializedObject.FindProperty("hierarchy");
            hierarchyLabel  = new GUIContent("Skeleton Utility Parent");
            parentReference = this.serializedObject.FindProperty("parentReference");

            utilityBone     = (SkeletonUtilityBone)target;
            skeletonUtility = utilityBone.hierarchy;
            EvaluateFlags();

            if (!utilityBone.valid && skeletonUtility != null && skeletonUtility.skeletonRenderer != null)
            {
                skeletonUtility.skeletonRenderer.Initialize(false);
            }

            canCreateHingeChain = CanCreateHingeChain();
            boundingBoxTable.Clear();

            if (multiObject)
            {
                return;
            }
            if (utilityBone.bone == null)
            {
                return;
            }

            var  skeleton  = utilityBone.bone.Skeleton;
            int  slotCount = skeleton.Slots.Count;
            Skin skin      = skeleton.Skin;

            if (skeleton.Skin == null)
            {
                skin = skeleton.Data.DefaultSkin;
            }

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = skeletonUtility.skeletonRenderer.skeleton.Slots.Items[i];
                if (slot.Bone == utilityBone.bone)
                {
                    var slotAttachments = new List <Skin.SkinEntry>();
                    int slotIndex       = skeleton.FindSlotIndex(slot.Data.Name);
                    skin.GetAttachments(slotIndex, slotAttachments);

                    var boundingBoxes = new List <BoundingBoxAttachment>();
                    foreach (var att in slotAttachments)
                    {
                        var boundingBoxAttachment = att.Attachment as BoundingBoxAttachment;
                        if (boundingBoxAttachment != null)
                        {
                            boundingBoxes.Add(boundingBoxAttachment);
                        }
                    }

                    if (boundingBoxes.Count > 0)
                    {
                        boundingBoxTable.Add(slot, boundingBoxes);
                    }
                }
            }
        }
Exemplo n.º 8
0
 public void CollectBones()
 {
     if (this.skeletonRenderer.skeleton == null)
     {
         return;
     }
     if (this.boneRoot != null)
     {
         List <string> list = new List <string>();
         ExposedList <IkConstraint> ikConstraints = this.skeletonRenderer.skeleton.IkConstraints;
         int i     = 0;
         int count = ikConstraints.Count;
         while (i < count)
         {
             list.Add(ikConstraints.Items[i].Target.Data.Name);
             i++;
         }
         using (List <SkeletonUtilityBone> .Enumerator enumerator = this.utilityBones.GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 SkeletonUtilityBone current = enumerator.get_Current();
                 if (current.bone == null)
                 {
                     return;
                 }
                 if (current.mode == SkeletonUtilityBone.Mode.Override)
                 {
                     this.hasTransformBones = true;
                 }
                 if (list.Contains(current.bone.Data.Name))
                 {
                     this.hasUtilityConstraints = true;
                 }
             }
         }
         if (this.utilityConstraints.get_Count() > 0)
         {
             this.hasUtilityConstraints = true;
         }
         if (this.skeletonAnimation != null)
         {
             this.skeletonAnimation.UpdateWorld    -= new UpdateBonesDelegate(this.UpdateWorld);
             this.skeletonAnimation.UpdateComplete -= new UpdateBonesDelegate(this.UpdateComplete);
             if (this.hasTransformBones || this.hasUtilityConstraints)
             {
                 this.skeletonAnimation.UpdateWorld += new UpdateBonesDelegate(this.UpdateWorld);
             }
             if (this.hasUtilityConstraints)
             {
                 this.skeletonAnimation.UpdateComplete += new UpdateBonesDelegate(this.UpdateComplete);
             }
         }
         this.needToReprocessBones = false;
     }
     else
     {
         this.utilityBones.Clear();
         this.utilityConstraints.Clear();
     }
 }
		void EvaluateFlags () {
			utilityBone = (SkeletonUtilityBone)target;
			skeletonUtility = utilityBone.skeletonUtility;

			if (Selection.objects.Length == 1) {
				containsFollows = utilityBone.mode == SkeletonUtilityBone.Mode.Follow;
				containsOverrides = utilityBone.mode == SkeletonUtilityBone.Mode.Override;
			} else {
				int boneCount = 0;
				foreach (Object o in Selection.objects) {
					var go = o as GameObject;
					if (go != null) {
						SkeletonUtilityBone sub = go.GetComponent<SkeletonUtilityBone>();
						if (sub != null) {
							boneCount++;
							containsFollows |= (sub.mode == SkeletonUtilityBone.Mode.Follow);
							containsOverrides |= (sub.mode == SkeletonUtilityBone.Mode.Override);
						}
					}
				}

				multiObject |= (boneCount > 1);
			}
		}
 protected virtual void OnEnable()
 {
     utilBone        = GetComponent <SkeletonUtilityBone>();
     skeletonUtility = SkeletonUtility.GetInParent <SkeletonUtility>(transform);
     skeletonUtility.RegisterConstraint(this);
 }
Exemplo n.º 11
0
	public GameObject SpawnBone(Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){
		GameObject go = new GameObject(bone.Data.Name);
		go.transform.parent = parent;
		
		SkeletonUtilityBone b = go.AddComponent<SkeletonUtilityBone>();
		b.skeletonUtility = this;
		b.position = pos;
		b.rotation = rot;
		b.scale = sca;
		b.mode = mode;
		b.zPosition = true;
		b.Reset();
		b.bone = bone;
		b.boneName = bone.Data.Name;
		b.valid = true;

		if(mode == SkeletonUtilityBone.Mode.Override){
			if(rot)
				go.transform.localRotation = Quaternion.Euler(0, 0, b.bone.RotationIK);
			
			if(pos)
				go.transform.localPosition = new Vector3(b.bone.X, b.bone.Y, 0);
			
			go.transform.localScale = new Vector3(b.bone.scaleX, b.bone.scaleY, 0);
		}

		return go;
	}
Exemplo n.º 12
0
	public GameObject SpawnBoneRecursively(Bone bone, Transform parent, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){
		GameObject go = SpawnBone(bone, parent, mode, pos, rot, sca);

		foreach(Bone child in bone.Children){
			SpawnBoneRecursively(child, go.transform, mode, pos, rot, sca);
		}

		return go;
	}
Exemplo n.º 13
0
	public GameObject SpawnHierarchy(SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca){
		GetBoneRoot();

		Skeleton skeleton = this.skeletonRenderer.skeleton;

		GameObject go = SpawnBoneRecursively(skeleton.RootBone, boneRoot, mode, pos, rot, sca);

		CollectBones();

		return go;
	}
Exemplo n.º 14
0
	public void UnregisterBone(SkeletonUtilityBone bone){
		utilityBones.Remove(bone);
	}
Exemplo n.º 15
0
	public void RegisterBone(SkeletonUtilityBone bone){
		if(utilityBones.Contains(bone))
			return;
		else{
			utilityBones.Add(bone);
			needToReprocessBones = true;
		}
	}
	void SpawnHierarchyButton (string label, string tooltip, SkeletonUtilityBone.Mode mode, bool pos, bool rot, bool sca, params GUILayoutOption[] options) {
		GUIContent content = new GUIContent(label, tooltip);
		if (GUILayout.Button(content, options)) {
			if (skeletonUtility.skeletonRenderer == null)
				skeletonUtility.skeletonRenderer = skeletonUtility.GetComponent<SkeletonRenderer>();

			if (skeletonUtility.boneRoot != null) {
				return;
			}

			skeletonUtility.SpawnHierarchy(mode, pos, rot, sca);

			SkeletonUtilityBone[] boneComps = skeletonUtility.GetComponentsInChildren<SkeletonUtilityBone>();
			foreach (SkeletonUtilityBone b in boneComps) 
				AttachIcon(b);
		}
	}
Exemplo n.º 17
0
    private void Start()
    {
        this.shadowRoot = Object.Instantiate <GameObject>(base.get_gameObject());
        if (this.hideShadow)
        {
            this.shadowRoot.set_hideFlags(1);
        }
        if (this.parent == null)
        {
            this.shadowRoot.get_transform().set_parent(base.get_transform().get_root());
        }
        else
        {
            this.shadowRoot.get_transform().set_parent(this.parent);
        }
        this.shadowTable = new Dictionary <Transform, Transform>();
        Object.Destroy(this.shadowRoot.GetComponent <SkeletonUtilityKinematicShadow>());
        this.shadowRoot.get_transform().set_position(base.get_transform().get_position());
        this.shadowRoot.get_transform().set_rotation(base.get_transform().get_rotation());
        Vector3 vector = base.get_transform().TransformPoint(Vector3.get_right());
        float   num    = Vector3.Distance(base.get_transform().get_position(), vector);

        this.shadowRoot.get_transform().set_localScale(Vector3.get_one());
        Joint[] componentsInChildren = this.shadowRoot.GetComponentsInChildren <Joint>();
        Joint[] array = componentsInChildren;
        for (int i = 0; i < array.Length; i++)
        {
            Joint joint    = array[i];
            Joint expr_116 = joint;
            expr_116.set_connectedAnchor(expr_116.get_connectedAnchor() * num);
        }
        Joint[] componentsInChildren2 = base.GetComponentsInChildren <Joint>();
        Joint[] array2 = componentsInChildren2;
        for (int j = 0; j < array2.Length; j++)
        {
            Joint joint2 = array2[j];
            Object.Destroy(joint2);
        }
        Rigidbody[] componentsInChildren3 = base.GetComponentsInChildren <Rigidbody>();
        Rigidbody[] array3 = componentsInChildren3;
        for (int k = 0; k < array3.Length; k++)
        {
            Rigidbody rigidbody = array3[k];
            Object.Destroy(rigidbody);
        }
        Collider[] componentsInChildren4 = base.GetComponentsInChildren <Collider>();
        Collider[] array4 = componentsInChildren4;
        for (int l = 0; l < array4.Length; l++)
        {
            Collider collider = array4[l];
            Object.Destroy(collider);
        }
        SkeletonUtilityBone[] componentsInChildren5 = this.shadowRoot.GetComponentsInChildren <SkeletonUtilityBone>();
        SkeletonUtilityBone[] componentsInChildren6 = base.GetComponentsInChildren <SkeletonUtilityBone>();
        SkeletonUtilityBone[] array5 = componentsInChildren6;
        for (int m = 0; m < array5.Length; m++)
        {
            SkeletonUtilityBone skeletonUtilityBone = array5[m];
            if (!(skeletonUtilityBone.get_gameObject() == base.get_gameObject()))
            {
                SkeletonUtilityBone[] array6 = componentsInChildren5;
                for (int n = 0; n < array6.Length; n++)
                {
                    SkeletonUtilityBone skeletonUtilityBone2 = array6[n];
                    if (!(skeletonUtilityBone2.GetComponent <Rigidbody>() == null))
                    {
                        if (skeletonUtilityBone2.boneName == skeletonUtilityBone.boneName)
                        {
                            this.shadowTable.Add(skeletonUtilityBone2.get_transform(), skeletonUtilityBone.get_transform());
                            break;
                        }
                    }
                }
            }
        }
        SkeletonUtilityBone[] array7 = componentsInChildren5;
        for (int num2 = 0; num2 < array7.Length; num2++)
        {
            SkeletonUtilityBone skeletonUtilityBone3 = array7[num2];
            Object.Destroy(skeletonUtilityBone3);
        }
    }
	protected virtual void OnEnable () {
		utilBone = GetComponent<SkeletonUtilityBone>();
		skeletonUtility = SkeletonUtility.GetInParent<SkeletonUtility>(transform);
		skeletonUtility.RegisterConstraint(this);
	}