コード例 #1
0
        override public void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_RecordProperty);

            Transform targetTransform = null;

            if (m_Ik2D.target)
            {
                targetTransform = m_Ik2D.target.transform;
            }

            EditorGUI.BeginChangeCheck();

            Transform newTargetTransform = EditorGUILayout.ObjectField(new GUIContent("Target"), targetTransform, typeof(Transform), true) as Transform;

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(m_Ik2D, "set target");

                if (newTargetTransform && !newTargetTransform.GetComponent <Bone2D>())
                {
                    newTargetTransform = null;
                }

                if (newTargetTransform != targetTransform)
                {
                    m_TargetTransformProperty.objectReferenceValue = newTargetTransform;
                    IkUtils.InitializeIk2D(serializedObject);
                    EditorUpdater.SetDirty("set target");
                }
            }

            /*
             * EditorGUI.BeginChangeCheck();
             *
             * EditorGUILayout.PropertyField(m_TargetTransformProperty);
             *
             * if(EditorGUI.EndChangeCheck())
             * {
             *      IkUtils.InitializeIk2D(serializedObject);
             *
             *      DoUpdateIK();
             * }
             */

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.Slider(m_WeightProperty, 0f, 1f);
            EditorGUILayout.PropertyField(m_RestorePoseProperty);
            EditorGUILayout.PropertyField(m_OrientChildProperty);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUpdater.SetDirty(Undo.GetCurrentGroupName());
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #2
0
        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");
        }
コード例 #3
0
        void OnSceneGUI()
        {
            if (Tools.current == Tool.Move)
            {
                Tools.hidden = true;

                float size = HandleUtility.GetHandleSize(m_Bone.transform.position) / 5f;

                Quaternion rotation = m_Bone.transform.rotation;

                EditorGUI.BeginChangeCheck();

                Quaternion cameraRotation = Camera.current.transform.rotation;

                if (Event.current.type == EventType.Repaint)
                {
                    Camera.current.transform.rotation = m_Bone.transform.rotation;
                }

#if UNITY_5_6_OR_NEWER
                Vector3 newPosition = Handles.FreeMoveHandle(m_Bone.transform.position, rotation, size, Vector3.zero,
                                                             Handles.RectangleHandleCap);
#else
                Vector3 newPosition =
                    Handles.FreeMoveHandle(m_Bone.transform.position, rotation, size, Vector3.zero, Handles.RectangleCap);
#endif

                if (Event.current.type == EventType.Repaint)
                {
                    Camera.current.transform.rotation = cameraRotation;
                }

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(m_Bone.transform, "Move");

                    m_Bone.transform.position = newPosition;

                    BoneUtils.OrientToChild(m_Bone.parentBone, Event.current.shift, Undo.GetCurrentGroupName(), true);

                    EditorUtility.SetDirty(m_Bone.transform);

                    EditorUpdater.SetDirty("Move");
                }
            }
            else
            {
                Tools.hidden = false;
            }
        }
コード例 #4
0
ファイル: IkCCD2DEditor.cs プロジェクト: chav0/cockroach
        override public void OnInspectorGUI()
        {
            IkCCD2D ikCCD2D = target as IkCCD2D;

            base.OnInspectorGUI();

            SerializedProperty numBonesProp   = serializedObject.FindProperty("m_NumBones");
            SerializedProperty iterationsProp = serializedObject.FindProperty("iterations");
            SerializedProperty dampingProp    = serializedObject.FindProperty("damping");

            Bone2D targetBone = ikCCD2D.target;

            serializedObject.Update();

            EditorGUI.BeginDisabledGroup(!targetBone);

            EditorGUI.BeginChangeCheck();

            int chainLength = 0;

            if (targetBone)
            {
                chainLength = targetBone.chainLength;
            }

            EditorGUILayout.IntSlider(numBonesProp, 0, chainLength);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RegisterCompleteObjectUndo(ikCCD2D, "Set num bones");

                IkUtils.InitializeIk2D(serializedObject);
                EditorUpdater.SetDirty("Set num bones");
            }

            EditorGUI.EndDisabledGroup();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(iterationsProp);
            EditorGUILayout.PropertyField(dampingProp);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUpdater.SetDirty(Undo.GetCurrentGroupName());
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #5
0
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            SerializedProperty flipProp = serializedObject.FindProperty("flip");

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(flipProp);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUpdater.SetDirty("Flip");
            }

            serializedObject.ApplyModifiedProperties();
        }
コード例 #6
0
        public void OnSceneGUI()
        {
            switch (Tools.current)
            {
            case Tool.Move:
                var transform = (target as MonoBehaviour).transform;
                var size      = HandleUtility.GetHandleSize(transform.position) * 5.0f;

                EditorGUI.BeginChangeCheck();
                var newPosition = Handles.FreeMoveHandle(transform.position, transform.rotation, size, Vector3.zero, Handles.RectangleHandleCap);

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(transform, "Move");
                    transform.position = newPosition;
                    EditorUpdater.SetDirty();
                }
                break;
            }
        }
コード例 #7
0
        public static void OnSceneGUI(SceneView sceneview)
        {
            for (int i = 0; i < s_Bones.Count; i++)
            {
                Bone2D bone = s_Bones[i];

                if (bone && IsVisible(bone))
                {
                    int       controlID = GUIUtility.GetControlID("BoneHandle".GetHashCode(), FocusType.Passive);
                    EventType eventType = Event.current.GetTypeForControl(controlID);

                    if (!IsLocked(bone))
                    {
                        if (eventType == EventType.MouseDown)
                        {
                            if (HandleUtility.nearestControl == controlID &&
                                Event.current.button == 0)
                            {
                                GUIUtility.hotControl = controlID;
                                Event.current.Use();
                            }
                        }

                        if (eventType == EventType.MouseUp)
                        {
                            if (GUIUtility.hotControl == controlID &&
                                Event.current.button == 0)
                            {
                                if (EditorGUI.actionKey)
                                {
                                    List <Object> objects = new List <Object>(Selection.objects);
                                    objects.Add(bone.gameObject);
                                    Selection.objects = objects.ToArray();
                                }
                                else
                                {
                                    Selection.activeObject = bone;
                                }

                                GUIUtility.hotControl = 0;
                                Event.current.Use();
                            }
                        }

                        if (eventType == EventType.MouseDrag)
                        {
                            if (GUIUtility.hotControl == controlID &&
                                Event.current.button == 0)
                            {
                                Handles.matrix = bone.transform.localToWorldMatrix;
                                Vector3 position = HandlesExtra.GUIToWorld(Event.current.mousePosition);

                                BoneUtils.OrientToLocalPosition(bone, position, Event.current.shift, "Rotate", true);

                                EditorUpdater.SetDirty("Rotate");

                                GUI.changed = true;
                                Event.current.Use();
                            }
                        }
                    }

                    if (eventType == EventType.Repaint)
                    {
                        if ((HandleUtility.nearestControl == controlID && GUIUtility.hotControl == 0) ||
                            GUIUtility.hotControl == controlID ||
                            Selection.gameObjects.Contains(bone.gameObject))
                        {
                            Color color = Color.yellow;

                            float outlineSize = HandleUtility.GetHandleSize(bone.transform.position) * 0.015f * bone.color.a;
                            BoneUtils.DrawBoneOutline(bone, outlineSize, color);

                            Bone2D outlineBone = bone.child;
                            color.a *= 0.5f;

                            while (outlineBone)
                            {
                                if (Selection.gameObjects.Contains(outlineBone.gameObject))
                                {
                                    outlineBone = null;
                                }
                                else
                                {
                                    if (outlineBone.color.a == 0f)
                                    {
                                        outlineSize = HandleUtility.GetHandleSize(outlineBone.transform.position) * 0.015f * outlineBone.color.a;
                                        BoneUtils.DrawBoneOutline(outlineBone, outlineSize, color);
                                        outlineBone = outlineBone.child;
                                        color.a    *= 0.5f;
                                    }
                                    else
                                    {
                                        outlineBone = null;
                                    }
                                }
                            }
                        }

                        if (bone.parentBone && !bone.linkedParentBone)
                        {
                            Color color = bone.color;
                            color.a       *= 0.25f;
                            Handles.matrix = Matrix4x4.identity;
                            BoneUtils.DrawBoneBody(bone.transform.position, bone.parentBone.transform.position, BoneUtils.GetBoneRadius(bone), color);
                        }

                        BoneUtils.DrawBoneBody(bone);

                        Color innerColor = bone.color * 0.25f;

                        if (bone.attachedIK && bone.attachedIK.isActiveAndEnabled)
                        {
                            innerColor = new Color(0f, 0.75f, 0.75f, 1f);
                        }

                        innerColor.a = bone.color.a;

                        BoneUtils.DrawBoneCap(bone, innerColor);
                    }

                    if (!IsLocked(bone) && eventType == EventType.Layout)
                    {
                        HandleUtility.AddControl(controlID, HandleUtility.DistanceToLine(bone.transform.position, bone.endPosition));
                    }
                }
            }

            foreach (Control control in s_Controls)
            {
                if (control && control.isActiveAndEnabled && IsVisible(control.gameObject))
                {
                    Transform transform = control.transform;

                    if (Selection.activeTransform != transform)
                    {
                        if (!control.bone ||
                            (control.bone && !Selection.transforms.Contains(control.bone.transform)))
                        {
                            Handles.matrix = Matrix4x4.identity;
                            Handles.color  = control.color;

                            if (Tools.current == Tool.Move)
                            {
                                EditorGUI.BeginChangeCheck();

                                Quaternion cameraRotation = UnityEngine.Camera.current.transform.rotation;

                                if (Event.current.type == EventType.Repaint)
                                {
                                    UnityEngine.Camera.current.transform.rotation = transform.rotation;
                                }

                                float size = HandleUtility.GetHandleSize(transform.position) / 5f;
                                //Handles.DrawLine(transform.position + transform.rotation * new Vector3(size,0f,0f), transform.position + transform.rotation * new Vector3(-size,0f,0f));
                                //Handles.DrawLine(transform.position + transform.rotation * new Vector3(0f,size,0f), transform.position + transform.rotation * new Vector3(0f,-size,0f));

                                bool guiEnabled = GUI.enabled;
                                GUI.enabled = !IsLocked(control.gameObject);

#if UNITY_5_6_OR_NEWER
                                Vector3 newPosition = Handles.FreeMoveHandle(transform.position, transform.rotation, size, Vector3.zero, Handles.RectangleHandleCap);
#else
                                Vector3 newPosition = Handles.FreeMoveHandle(transform.position, transform.rotation, size, Vector3.zero, Handles.RectangleCap);
#endif

                                GUI.enabled = guiEnabled;

                                if (Event.current.type == EventType.Repaint)
                                {
                                    UnityEngine.Camera.current.transform.rotation = cameraRotation;
                                }

                                if (EditorGUI.EndChangeCheck())
                                {
                                    Undo.RecordObject(transform, "Move");
                                    transform.position = newPosition;

                                    if (control.bone)
                                    {
                                        Undo.RecordObject(control.bone.transform, "Move");

                                        control.bone.transform.position = newPosition;

                                        BoneUtils.OrientToChild(control.bone.parentBone, Event.current.shift, "Move", true);

                                        EditorUpdater.SetDirty("Move");
                                    }
                                }
                            }
                            else if (Tools.current == Tool.Rotate)
                            {
                                EditorGUI.BeginChangeCheck();

                                float size = HandleUtility.GetHandleSize(transform.position) * 0.5f;
                                //Handles.DrawLine(transform.position + transform.rotation * new Vector3(size,0f,0f), transform.position + transform.rotation * new Vector3(-size,0f,0f));
                                //Handles.DrawLine(transform.position + transform.rotation * new Vector3(0f,size,0f), transform.position + transform.rotation * new Vector3(0f,-size,0f));

                                bool guiEnabled = GUI.enabled;
                                GUI.enabled = !IsLocked(control.gameObject);

                                Quaternion newRotation = Handles.Disc(transform.rotation, transform.position, transform.forward, size, false, 0f);

                                GUI.enabled = guiEnabled;

                                if (EditorGUI.EndChangeCheck())
                                {
                                    Undo.RecordObject(transform, "Rotate");
                                    transform.rotation = newRotation;

                                    if (control.bone)
                                    {
                                        Undo.RecordObject(control.bone.transform, "Rotate");

                                        control.bone.transform.rotation = newRotation;

                                        EditorUpdater.SetDirty("Rotate");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
        public static void LoadPose(Pose pose, Transform root)
        {
            SerializedObject   poseSO      = new SerializedObject(pose);
            SerializedProperty entriesProp = poseSO.FindProperty("m_BoneEntries");

            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;
                }
            }

            /* 현재 불필요한 코드
             * 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;
             *              }
             *      }
             * }
             */



            SerializedProperty entriesProp1 = poseSO.FindProperty("m_IkEntries");

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

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

                if (ikTransform)
                {
                    Ik2D ikComponent = ikTransform.GetComponent <Ik2D>();

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

                    ikTransform.localPosition = element.FindPropertyRelative("localPosition").vector3Value;
                    /*아래 스케일과 로테이션은 테스트후 제거*/
                    ikTransform.localRotation = element.FindPropertyRelative("localRotation").quaternionValue;
                    ikTransform.localScale    = element.FindPropertyRelative("localScale").vector3Value;
                }
            }
            EditorUpdater.SetDirty("Load Pose");
        }