Esempio n. 1
0
        static void BuildIkList(Bone2D bone, List <Bone2D> boneList, List <Ik2D> ikList)
        {
            if (!bone)
            {
                return;
            }

            if (boneList.Contains(bone))
            {
                return;
            }

            boneList.Add(bone);

            Ik2D ik2D = bone.attachedIK;

            List <Bone2D> childBones = new List <Bone2D>(25);

            if (ik2D)
            {
                if (!ikList.Contains(ik2D))
                {
                    ikList.Add(ik2D);
                }

                for (int i = 0; i < ik2D.solver.solverPoses.Count; i++)
                {
                    IkSolver2D.SolverPose pose = ik2D.solver.solverPoses [i];

                    if (pose.bone)
                    {
                        pose.bone.GetComponentsInChildren <Bone2D>(childBones);

                        for (int j = 0; j < childBones.Count; j++)
                        {
                            Bone2D l_bone = childBones[j];

                            if (l_bone && !boneList.Contains(l_bone))
                            {
                                BuildIkList(l_bone, boneList, ikList);
                            }
                        }
                    }
                }
            }
            else
            {
                bone.GetComponentsInChildren <Bone2D>(childBones);

                for (int j = 0; j < childBones.Count; j++)
                {
                    Bone2D l_bone = childBones[j];

                    if (l_bone && !boneList.Contains(l_bone))
                    {
                        BuildIkList(l_bone, boneList, ikList);
                    }
                }
            }
        }
Esempio n. 2
0
        public static void UpdateIK(Bone2D bone, string undoName)
        {
            List <Bone2D> boneList = new List <Bone2D>(25);
            List <Ik2D>   ikList   = new List <Ik2D>(25);

            BuildIkList(bone, boneList, ikList);

            for (int i = 0; i < ikList.Count; i++)
            {
                Ik2D l_ik2D = ikList[i];

                if (l_ik2D && l_ik2D.isActiveAndEnabled)
                {
                    for (int j = 0; j < l_ik2D.solver.solverPoses.Count; j++)
                    {
                        IkSolver2D.SolverPose pose = l_ik2D.solver.solverPoses [j];
                        if (pose.bone)
                        {
                            Undo.RecordObject(pose.bone.transform, undoName);
                        }
                    }

                    l_ik2D.solver.RestoreDefaultPoses();
                    l_ik2D.UpdateIK();
                }
            }
        }
        static void UpdateIkList(List <Ik2D> ikList, string undoName, bool recordObject)
        {
            for (int i = 0; i < ikList.Count; i++)
            {
                Ik2D l_ik2D = ikList[i];

                if (l_ik2D && l_ik2D.isActiveAndEnabled)
                {
                    if (!string.IsNullOrEmpty(undoName))
                    {
                        for (int j = 0; j < l_ik2D.solver.solverPoses.Count; j++)
                        {
                            IkSolver2D.SolverPose pose = l_ik2D.solver.solverPoses [j];
                            if (pose.bone)
                            {
                                if (recordObject)
                                {
                                    Undo.RecordObject(pose.bone.transform, undoName);
                                }
                                else
                                {
                                    Undo.RegisterCompleteObjectUndo(pose.bone.transform, undoName);
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(undoName) &&
                        l_ik2D.orientChild &&
                        l_ik2D.target &&
                        l_ik2D.target.child)
                    {
                        if (recordObject)
                        {
                            Undo.RecordObject(l_ik2D.target.child.transform, undoName);
                        }
                        else
                        {
                            Undo.RegisterCompleteObjectUndo(l_ik2D.target.child.transform, undoName);
                        }
                    }

                    l_ik2D.UpdateIK();

                    for (int j = 0; j < l_ik2D.solver.solverPoses.Count; j++)
                    {
                        IkSolver2D.SolverPose pose = l_ik2D.solver.solverPoses [j];
                        if (pose.bone)
                        {
                            BoneUtils.FixLocalEulerHint(pose.bone.transform);
                        }

                        if (l_ik2D.orientChild && l_ik2D.target.child)
                        {
                            BoneUtils.FixLocalEulerHint(l_ik2D.target.child.transform);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        void SetAttachedIK(Ik2D ik2D)
        {
            for (int i = 0; i < solver.solverPoses.Count; i++)
            {
                IkSolver2D.SolverPose pose = solver.solverPoses[i];

                if (pose.bone)
                {
                    pose.bone.attachedIK = ik2D;
                }
            }
        }
Esempio n. 5
0
        public static void UpdateAttachedIKs(List <Ik2D> Ik2Ds)
        {
            for (int i = 0; i < Ik2Ds.Count; i++)
            {
                Ik2D ik2D = Ik2Ds[i];

                if (ik2D)
                {
                    for (int j = 0; j < ik2D.solver.solverPoses.Count; j++)
                    {
                        IkSolver2D.SolverPose pose = ik2D.solver.solverPoses[j];

                        if (pose.bone)
                        {
                            pose.bone.attachedIK = ik2D;
                        }
                    }
                }
            }
        }