Exemple #1
0
        public static void SetIKs(SpineArmatureEditor armatureEditor)
        {
            if (armatureEditor.armatureData.iks != null)
            {
                int len = armatureEditor.armatureData.iks.Length;
                for (int i = 0; i < len; ++i)
                {
                    SpineData.IKData   ikData      = armatureEditor.armatureData.iks[i];
                    Transform          targetIK    = armatureEditor.bonesKV[ikData.target];
                    Transform          startBone   = armatureEditor.bonesKV[ikData.bones[0]];
                    SpineData.BoneData endBoneData = armatureEditor.bonesDataKV[ikData.bones[ikData.bones.Length - 1]];
                    Transform          endBone     = armatureEditor.bonesKV[ikData.bones[ikData.bones.Length - 1]];
                    BoneIK             bi          = startBone.gameObject.AddComponent <BoneIK>();

                    Vector3 v = Vector3.right * endBoneData.length * armatureEditor.unit;
                    v = endBone.TransformPoint(v);
                    GameObject go = new GameObject(ikData.name);
                    go.transform.parent        = endBone;
                    go.transform.position      = v;
                    go.transform.localRotation = Quaternion.identity;
                    go.transform.localScale    = Vector3.zero;

                    bi.damping      = ikData.mix;
                    bi.endTransform = go.transform;
                    bi.targetIK     = targetIK;
                    bi.iterations   = 20;
                    bi.bendPositive = ikData.bendPositive;
                    bi.rootBone     = armatureEditor.armature;
                }
            }
        }
 private static void ParseIKs(SpineArmatureEditor armatureEditor, Bones2D.JSONClass armtureObj)
 {
     if (armtureObj.ContainKey("ik"))
     {
         Bones2D.JSONArray  iks     = armtureObj["ik"].AsArray;
         SpineData.IKData[] ikDatas = new SpineData.IKData[iks.Count];
         for (int i = 0; i < iks.Count; ++i)
         {
             Bones2D.JSONClass ikObj  = iks[i].AsObject;
             SpineData.IKData  ikData = new SpineData.IKData();
             ikData.name   = ikObj["name"].ToString();
             ikData.target = ikObj["target"].ToString();
             if (ikObj.ContainKey("bones"))
             {
                 Bones2D.JSONArray bones = ikObj["bones"].AsArray;
                 ikData.bones = new string[bones.Count];
                 for (int j = 0; j < bones.Count; ++j)
                 {
                     ikData.bones[j] = bones[j];
                 }
             }
             if (ikObj.ContainKey("mix"))
             {
                 ikData.mix = ikObj["mix"].AsFloat;
             }
             if (ikObj.ContainKey("bendPositive"))
             {
                 ikData.bendPositive = ikObj["bendPositive"].AsBool;
             }
             ikDatas[i] = ikData;
         }
         armatureEditor.armatureData.iks = ikDatas;
     }
 }