private void RotationPropertyField(GUIContent content)
        {
            Transform  transform     = (Transform)targets[0];
            Quaternion localRotation = transform.localRotation;

            foreach (Object t in targets)
            {
                if (!SameRotation(localRotation, ((Transform)t).localRotation))
                {
                    EditorGUI.showMixedValue = true;
                    break;
                }
            }
            using (var changeScope = new EditorGUI.ChangeCheckScope())
            {
                Vector3 eulerAngles = EditorGUILayout.Vector3Field(content, TransformUtils.GetInspectorRotation(transform));
                if (changeScope.changed)
                {
                    Undo.RecordObjects(targets, "Rotation Changed");
                    foreach (Object obj in targets)
                    {
                        Transform t = (Transform)obj;
                        TransformUtils.SetInspectorRotation(t, eulerAngles);
                    }
                    rotationProperty.serializedObject.SetIsDifferentCacheDirty();
                }
            }
            EditorGUI.showMixedValue = false;
        }
        private static void MutateAnimationToSnapshotAllChildrenOf(AnimationClip mutatedClip, Transform thatObject, string hierarchyPath)
        {
            var position = thatObject.localPosition;
            var euler    = TransformUtils.GetInspectorRotation(thatObject);
            var scale    = thatObject.localScale;

            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalPosition.x", new AnimationCurve(new Keyframe(0, position.x)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalPosition.y", new AnimationCurve(new Keyframe(0, position.y)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalPosition.z", new AnimationCurve(new Keyframe(0, position.z)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "localEulerAnglesRaw.x", new AnimationCurve(new Keyframe(0, euler.x)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "localEulerAnglesRaw.y", new AnimationCurve(new Keyframe(0, euler.y)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "localEulerAnglesRaw.z", new AnimationCurve(new Keyframe(0, euler.z)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalScale.x", new AnimationCurve(new Keyframe(0, scale.x)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalScale.y", new AnimationCurve(new Keyframe(0, scale.y)));
            mutatedClip.SetCurve(hierarchyPath, typeof(Transform), "m_LocalScale.z", new AnimationCurve(new Keyframe(0, scale.z)));

            var isRootNode = hierarchyPath == "";

            if (!isRootNode)
            {
                mutatedClip.SetCurve(hierarchyPath, typeof(GameObject), "m_IsActive", new AnimationCurve(new Keyframe(0, thatObject.gameObject.activeSelf ? 1 : 0)));
            }

            foreach (Transform child in thatObject)
            {
                MutateAnimationToSnapshotAllChildrenOf(mutatedClip, child, ChildPath(hierarchyPath, child));
            }
        }
Exemplo n.º 3
0
    /// <summary>
    /// 回転のUIを描画
    /// </summary>
    private void DrawRotationUI()
    {
        var new_value  = Vector3.zero;
        var transforms = targets.Cast <Transform>().ToList();

        EditorGUI.BeginChangeCheck();

        using (new EditorGUILayout.HorizontalScope())
        {
            var current_value                = TransformUtils.GetInspectorRotation(m_transform);
            var is_pushed_reset_button       = GUILayout.Button("R", RESET_BUTTON_WIDTH);
            var contain_difference_rotations = containDifferenceRotationsInSelectedObjects(transforms, current_value);

            if (contain_difference_rotations)
            {
                EditorGUI.showMixedValue = true;
            }
            var field_value = EditorGUILayout.Vector3Field(string.Empty, current_value, VALUE_FIELD_HEIGHT);
            if (contain_difference_rotations)
            {
                EditorGUI.showMixedValue = false;
            }

            new_value = is_pushed_reset_button ? Vector3.zero : field_value;
        }

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObjects(targets, "Inspector");
            transforms.ForEach(transform => TransformUtils.SetInspectorRotation(transform, new_value));
        }
    }
Exemplo n.º 4
0
    private void RotationPropertyField(SerializedProperty rotationProperty, GUIContent content)
    {
        Transform  transform     = (Transform)targets[0];
        Quaternion localRotation = transform.localRotation;

        foreach (Object t in targets)
        {
            if (!SameRotation(localRotation, ((Transform)t).localRotation))
            {
                EditorGUI.showMixedValue = true;
                break;
            }
        }

        EditorGUI.BeginChangeCheck();

        Vector3 eulerAngles = EditorGUILayout.Vector3Field(content.text, TransformUtils.GetInspectorRotation(transform));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObjects(targets, "Rotation Changed");
            foreach (Object obj in targets)
            {
                Transform t = (Transform)obj;
                eulerAngles = FixIfNaN(eulerAngles);
                TransformUtils.SetInspectorRotation(t, eulerAngles);
            }
            rotationProperty.serializedObject.SetIsDifferentCacheDirty();
        }

        EditorGUI.showMixedValue = false;
    }
Exemplo n.º 5
0
    /// <summary>
    /// 選択したオブジェクトに異なる回転が含まれているか判別する値を取得
    /// </summary>
    private bool containDifferenceRotationsInSelectedObjects(IList <Transform> transforms, Vector3 current_value)
    {
        if (transforms.Count <= 1)
        {
            return(false);
        }

        return(transforms.Any(transform => current_value != TransformUtils.GetInspectorRotation(transform)));
    }
        private void AutoDetect(ModelRenderer target)
        {
            var skinnedMesh = target.transform.GetComponentInChildren <SkinnedMeshRenderer>();

            if (skinnedMesh == null)
            {
                Debug.LogError("Cannot find SkinnedMeshRenderer in " + target.name);
                return;
            }
            target.Hand = skinnedMesh.gameObject;
            // set finger bones
            SetBone(target, "wrist", 0, 1);
            SetBone(target, "thumb", 1, 4);
            SetBone(target, "index", 5, 4);
            SetBone(target, "middle", 9, 4);
            SetBone(target, "ring", 13, 4);
            SetBone(target, "pinky", 17, 4);

            // check left or right
            int leftCount  = CountName(target, "l_", "_l", "_left", "left_");
            int rightCount = CountName(target, "r_", "_r", "_right", "right_");

            if (leftCount == rightCount)
            {
                Debug.LogErrorFormat("Cannot determine left/right for {0}, use current: {1}",
                                     target.name, target.IsLeft ? "left" : "right");
            }
            else
            {
                target.IsLeft = leftCount > rightCount;
            }

            // set initial rotation
            var upDir    = target.Nodes[9].position - target.Nodes[0].position;
            var indexDir = target.Nodes[5].position - target.Nodes[0].position;
            var palmDir  = target.IsLeft ? Vector3.Cross(indexDir, upDir) : Vector3.Cross(upDir, indexDir);
            var rotation = Quaternion.FromToRotation(upDir, Vector3.up);
            var frontDir = rotation * palmDir;
            var angle    = Vector3.Angle(frontDir, Vector3.forward);
            var sign     = Mathf.Sign(Vector3.Dot(Vector3.up, Vector3.Cross(frontDir, Vector3.forward)));

            rotation = Quaternion.AngleAxis(sign * angle, Vector3.up) * rotation * target.transform.rotation;

            var eulerAngles = rotation.eulerAngles;

            eulerAngles.x = ParseAngle(eulerAngles.x);
            eulerAngles.y = ParseAngle(eulerAngles.y);
            eulerAngles.z = ParseAngle(eulerAngles.z);
            TransformUtils.SetInspectorRotation(target.transform, eulerAngles);
            target.initialRotation = TransformUtils.GetInspectorRotation(target.transform);
        }
Exemplo n.º 7
0
    private Vector3 GetWorldRotation()
    {
        Transform temp          = m_transform;
        Vector3   worldRotation = TransformUtils.GetInspectorRotation(temp);

        while (temp.parent != null)
        {
            var parent = temp.parent;
            worldRotation += TransformUtils.GetInspectorRotation(parent);
            temp           = parent;
        }

        return(worldRotation);
    }
Exemplo n.º 8
0
        void SnapRotation(Transform t)
        {
            if (!snapRotation)
            {
                return;
            }

            Vector3 inspectorRotation = TransformUtils.GetInspectorRotation(t);

            Vector3 newVector = new Vector3(
                (float)SnapTo(inspectorRotation.x, rotationStep),
                (float)SnapTo(inspectorRotation.y, rotationStep),
                (float)SnapTo(inspectorRotation.z, rotationStep)
                );

            t.localEulerAngles = newVector;
            TransformUtils.SetInspectorRotation(t, newVector);
        }
Exemplo n.º 9
0
        public override void Capture(TweenRotation tween)
        {
            if (tween.Mode == TweenRotation.RotationMode.Quaternion)
            {
                tween.Capture();
                return;
            }

            if (tween.IsLocal)
            {
                tween.Value = TransformUtils.GetInspectorRotation(tween.State.Group.GameObject.transform);
            }
            else
            {
                tween.Value = tween.State.Group.GameObject.transform.eulerAngles;
            }

            Debug.Log("Rotation tween capturing");
        }
Exemplo n.º 10
0
        private Axes CheckDifference(Transform t, Vector3 original)
        {
            //Vector3 next = t.localEulerAngles;
            Vector3 next = TransformUtils.GetInspectorRotation(t);

            Axes axes = Axes.None;

            if (Differs(next.x, original.x))
            {
                axes |= Axes.X;
            }
            if (Differs(next.y, original.y))
            {
                axes |= Axes.Y;
            }
            if (Differs(next.z, original.z))
            {
                axes |= Axes.Z;
            }

            return(axes);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Defines the rotation elements in the inspector.
        /// </summary>
        private void RotationInspector()
        {
            // Rotation Label - Adjusts to whether or not the inspector is in wide mode
            if (EditorGUIUtility.wideMode)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("Rotation", GUILayout.MinWidth(90), GUILayout.ExpandHeight(false));
            }
            else
            {
                GUILayout.Label("Rotation", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
            }

            // Making the  RotationVector3 Boxes in thier colours
            EditorGUIUtility.labelWidth = 15;
            EditorGUILayout.BeginHorizontal();
            EditorGUI.BeginChangeCheck();


            // Hotfix 2 - try to stop the 90/270 issue
            Vector3 _newRot = TransformUtils.GetInspectorRotation(_t);

            if (EditorPrefs.GetBool("CarterGames-TransformColours-Use2D"))
            {
                //// Rotation X - Red
                GUI.backgroundColor = _hidden;
                _newRot.x           = EditorGUILayout.FloatField(new GUIContent("X"), _newRot.x, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));

                //// Rotation Y - Green
                _newRot.y           = EditorGUILayout.FloatField(new GUIContent("Y"), _newRot.y, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
                GUI.backgroundColor = Color.white;

                //// Rotation Z - Blue
                GUI.backgroundColor = Color.blue;
                _newRot.z           = EditorGUILayout.FloatField(new GUIContent("Z"), _newRot.z, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
                GUI.backgroundColor = Color.white;
            }
            else
            {
                //// Rotation X - Red
                GUI.backgroundColor = Color.red;
                _newRot.x           = EditorGUILayout.FloatField(new GUIContent("X"), _newRot.x, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
                GUI.backgroundColor = Color.white;

                //// Rotation Y - Green
                GUI.backgroundColor = Color.green;
                _newRot.y           = EditorGUILayout.FloatField(new GUIContent("Y"), _newRot.y, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
                GUI.backgroundColor = Color.white;

                //// Rotation Z - Blue
                GUI.backgroundColor = Color.blue;
                _newRot.z           = EditorGUILayout.FloatField(new GUIContent("Z"), _newRot.z, GUILayout.Width(70), GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(false));
                GUI.backgroundColor = Color.white;
            }


            EditorGUILayout.EndHorizontal();


            // Hotfix 2 - try to stop the 90/270 issue
            TransformUtils.SetInspectorRotation(_t, _newRot);


            // Runs if a edit was made to one of the fields above
            if (EditorGUI.EndChangeCheck())
            {
                _rotChange = true;
            }


            // Adjusts the editor Hoz grouping so the label shows above the boxes if the inspector is not in wide mode
            if (EditorGUIUtility.wideMode)
            {
                EditorGUILayout.EndHorizontal();
            }
        }
Exemplo n.º 12
0
    public override VisualElement CreateInspectorGUI()
    {
        var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/CustomTransformInspector.uxml");

        root = visualTree.CloneTree();

        var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/CustomTransformInspector.uss");

        root.styleSheets.Add(styleSheet);

        Vector3Field localPosField   = root.Q <Vector3Field>("Vector3Position");
        Vector3Field localRotField   = root.Q <Vector3Field>("Vector3Rotation");
        Vector3Field localScaleField = root.Q <Vector3Field>("Vector3Scale");

        Vector3Field worldPosField   = root.Q <Vector3Field>("Vector3WorldPosition");
        Vector3Field worldRotField   = root.Q <Vector3Field>("Vector3WorldRotation");
        Vector3Field worldScaleField = root.Q <Vector3Field>("Vector3WorldScale");

        localPosField.value   = m_transform.localPosition;
        localRotField.value   = TransformUtils.GetInspectorRotation(m_transform);
        localScaleField.value = m_transform.localScale;

        worldPosField.value   = m_transform.position;
        worldScaleField.value = m_transform.lossyScale;
        worldRotField.value   = GetWorldRotation();

        worldPosField.SetEnabled(false);
        worldRotField.SetEnabled(false);
        worldScaleField.SetEnabled(false);


        localPosField.RegisterValueChangedCallback(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            m_transform.localPosition = localPosField.value;
        });
        localRotField.RegisterValueChangedCallback(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            TransformUtils.SetInspectorRotation(m_transform, localRotField.value);
        });
        localScaleField.RegisterValueChangedCallback(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            m_transform.localScale = localScaleField.value;
        });

        //전체 리셋
        root.Q <Button>("LocalReset").RegisterCallback <MouseUpEvent>(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            ResetPositionField(localPosField);
            ResetRotationField(localRotField);
            ResetScaleField(localScaleField);
        });

        //개별 리셋
        root.Q <Button>("RB").RegisterCallback <MouseUpEvent>(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            ResetPositionField(localPosField);
        });
        root.Q <Button>("GB").RegisterCallback <MouseUpEvent>(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            ResetRotationField(localRotField);
        });
        root.Q <Button>("BB").RegisterCallback <MouseUpEvent>(evt =>
        {
            Undo.RecordObject(m_transform, m_transform.name);
            ResetScaleField(localScaleField);
        });

        // 스케쥴러
        var scheduledAction = root.schedule.Execute(() =>
        {
            localPosField.value   = m_transform.localPosition;
            localRotField.value   = TransformUtils.GetInspectorRotation(m_transform);
            localScaleField.value = m_transform.localScale;

            worldPosField.value   = m_transform.position;
            worldScaleField.value = m_transform.lossyScale;
            worldRotField.value   = GetWorldRotation();
        });

        scheduledAction.Every(100);
        return(root);
    }
Exemplo n.º 13
0
        protected virtual void OnSceneGUI()
        {
            TransformController transformController   = (TransformController)target;
            Vector3             orientationCorrection = new Vector3(0, 0, 0);

            switch (transformController.FreeDOF)
            {
            case 4:
                angularLimitHandle.xMin           = transformController.LockMin;
                angularLimitHandle.xMax           = transformController.LockMax;
                angularLimitHandle.xRange         = new Vector2(-360, 360);
                angularLimitHandle.yMotion        = 0;
                angularLimitHandle.zMotion        = 0;
                transformController.initialOffset = TransformUtils.GetInspectorRotation(transformController.transform).x;
                break;

            case 5:
                angularLimitHandle.yMin           = transformController.LockMin;
                angularLimitHandle.yMax           = transformController.LockMax;
                angularLimitHandle.yRange         = new Vector2(-360, 360);
                angularLimitHandle.xMotion        = 0;
                angularLimitHandle.zMotion        = 0;
                orientationCorrection             = new Vector3(0, 90, 0);
                transformController.initialOffset = TransformUtils.GetInspectorRotation(transformController.transform).y;
                break;

            case 6:
                angularLimitHandle.zMin           = transformController.LockMin;
                angularLimitHandle.zMax           = transformController.LockMax;
                angularLimitHandle.zRange         = new Vector2(-360, 360);
                angularLimitHandle.xMotion        = 0;
                angularLimitHandle.yMotion        = 0;
                orientationCorrection             = new Vector3(0, 180, 90);
                transformController.initialOffset = TransformUtils.GetInspectorRotation(transformController.transform).z;
                break;

            default:
                // this is just for rotation (hinge) joints, if not one of these then return
                return;
            }

            // set the handle matrix to match the object's position/rotation with a uniform scale

            Matrix4x4 handleMatrix = Matrix4x4.TRS(
                transformController.transform.position,
                transformController.transform.parent.gameObject.transform.rotation * Quaternion.Euler(orientationCorrection),
                Vector3.one
                );

            EditorGUI.BeginChangeCheck();

            using (new Handles.DrawingScope(handleMatrix))
            {
                // maintain a constant screen-space size for the handle's radius based on the origin of the handle matrix
                // add 30% to avoid the handle getting lost behind the transform
                angularLimitHandle.radius = HandleUtility.GetHandleSize(Vector3.zero) * 1.3f;

                // draw the handle
                EditorGUI.BeginChangeCheck();
                angularLimitHandle.DrawHandle();
                if (EditorGUI.EndChangeCheck())
                {
                    // undone/redo
                    Undo.RecordObject(transformController, "Change transform lock angles");

                    // update JointController script
                    float[] validated = new float[2] {
                        0, 0
                    };
                    switch (transformController.FreeDOF)
                    {
                    case 4:
                        validated = LockCheckAngle(angularLimitHandle.xMin, angularLimitHandle.xMax);
                        break;

                    case 5:
                        validated = LockCheckAngle(angularLimitHandle.yMin, angularLimitHandle.yMax);
                        break;

                    case 6:
                        validated = LockCheckAngle(angularLimitHandle.zMin, angularLimitHandle.zMax);
                        break;

                    default:
                        // this is just for rotation (hinge) joints, if not one of these then do nothing
                        break;
                    }
                    transformController.LockMin = validated[0];
                    transformController.LockMax = validated[1];
                }
            }
        }
Exemplo n.º 14
0
        private void DrawRotation()
        {
            GUILayout.BeginHorizontal();
            {
                bool reset = GUILayout.Button("R", GUILayout.Width(20f));

                // Vector3 visible = (serializedObject.targetObject as Transform).localEulerAngles;
                Vector3 visible = TransformUtils.GetInspectorRotation(serializedObject.targetObject as Transform);

                visible.x = WrapAngle(visible.x);
                visible.y = WrapAngle(visible.y);
                visible.z = WrapAngle(visible.z);

                Axes changed = CheckDifference(mRot);
                Axes altered = Axes.None;

                GUILayoutOption opt = GUILayout.MinWidth(30f);

                if (FloatField("X", ref visible.x, (changed & Axes.X) != 0, false, opt))
                {
                    altered |= Axes.X;
                }
                if (FloatField("Y", ref visible.y, (changed & Axes.Y) != 0, false, opt))
                {
                    altered |= Axes.Y;
                }
                if (FloatField("Z", ref visible.z, (changed & Axes.Z) != 0, false, opt))
                {
                    altered |= Axes.Z;
                }

                if (reset)
                {
                    mRot.quaternionValue = Quaternion.identity;
                }
                else if (altered != Axes.None)
                {
                    RegisterUndo("Change Rotation", serializedObject.targetObjects);

                    foreach (Object obj in serializedObject.targetObjects)
                    {
                        Transform t = obj as Transform;
                        //Vector3 v = t.localEulerAngles;
                        Vector3 v = TransformUtils.GetInspectorRotation(t);

                        if ((altered & Axes.X) != 0)
                        {
                            v.x = visible.x;
                        }
                        if ((altered & Axes.Y) != 0)
                        {
                            v.y = visible.y;
                        }
                        if ((altered & Axes.Z) != 0)
                        {
                            v.z = visible.z;
                        }

                        //t.localEulerAngles = v;
                        TransformUtils.SetInspectorRotation(t, v);
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            bool isPlaying = Application.isPlaying;

#if UNITY_2018_2_OR_NEWER
            if (!serializedObject.isEditingMultipleObjects)
            {
                isPlaying = Application.IsPlaying(target);
            }
#endif
            GUI.enabled = !isPlaying;

            EditorGUILayout.PropertyField(rotationProp);
            EditorGUILayout.HelpBox("Initial Rotation should make sure palm faces forward, fingers points up in global axis.",
                                    MessageType.Info);
            EditorGUILayout.HelpBox("Global rotation of Transform component is locked to use value of Initial Rotation",
                                    MessageType.None);
            EditorGUILayout.PropertyField(isLeftProp);
            EditorGUILayout.PropertyField(collliderProp);
            EditorGUILayout.PropertyField(confidenceProp);
            EditorGUILayout.PropertyField(handProp);
            if (nodesProp.hasMultipleDifferentValues)
            {
                EditorGUILayout.LabelField("Nodes", "-");
            }
            else
            {
                showNodes.target = EditorGUILayout.Foldout(showNodes.target, "Nodes");
                if (EditorGUILayout.BeginFadeGroup(showNodes.faded))
                {
                    EditorGUI.indentLevel++;
                    for (int i = 0; i < 21; i++)
                    {
                        var element = nodesProp.GetArrayElementAtIndex(i);
                        element.objectReferenceValue =
                            EditorGUILayout.ObjectField(names[i], element.objectReferenceValue, typeof(Transform), true);
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUILayout.EndFadeGroup();
            }
            serializedObject.ApplyModifiedProperties();
            GUI.enabled = true;

            if (isPlaying)
            {
                return;
            }

            foreach (ModelRenderer target in targets)
            {
                TransformUtils.SetInspectorRotation(target.transform, target.initialRotation);
                target.initialRotation = TransformUtils.GetInspectorRotation(target.transform);
            }

            if (serializedObject.isEditingMultipleObjects)
            {
                return;
            }

            GUILayout.Space(5);
            if (GUILayout.Button("Auto detect properties"))
            {
                AutoDetect(target as ModelRenderer);
            }
            EditorGUILayout.HelpBox("Please manually check if auto detect set fields correctly. Please refer to help page for details.",
                                    MessageType.Info);
        }