FixLocalEulerHint() публичный статический Метод

public static FixLocalEulerHint ( Transform transform ) : void
transform Transform
Результат void
Пример #1
0
        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);
                        }
                    }
                }
            }
        }
        public static void LoadPose(Pose pose, Transform root)
        {
            SerializedObject   poseSO      = new SerializedObject(pose);
            SerializedProperty entriesProp = poseSO.FindProperty("m_PoseEntries");

            List <Ik2D> iks = new List <Ik2D>();

            for (int i = 0; i < entriesProp.arraySize; i++)
            {
                SerializedProperty element = entriesProp.GetArrayElementAtIndex(i);

                Transform boneTransform = root.Find(element.FindPropertyRelative("path").stringValue);

                if (boneTransform)
                {
                    Bone2D boneComponent = boneTransform.GetComponent <Bone2D>();

                    if (boneComponent && boneComponent.attachedIK && !iks.Contains(boneComponent.attachedIK))
                    {
                        iks.Add(boneComponent.attachedIK);
                    }

                    Undo.RecordObject(boneTransform, "Load Pose");

                    boneTransform.localPosition = element.FindPropertyRelative("localPosition").vector3Value;
                    boneTransform.localRotation = element.FindPropertyRelative("localRotation").quaternionValue;
                    boneTransform.localScale    = element.FindPropertyRelative("localScale").vector3Value;
                    BoneUtils.FixLocalEulerHint(boneTransform);
                }
            }

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

                if (ik && ik.target)
                {
                    Undo.RecordObject(ik.transform, "Load Pose");

                    ik.transform.position = ik.target.endPosition;

                    if (ik.orientChild && ik.target.child)
                    {
                        ik.transform.rotation = ik.target.child.transform.rotation;
                        BoneUtils.FixLocalEulerHint(ik.transform);
                    }
                }
            }

            EditorUpdater.SetDirty("Load Pose");
        }