Exemple #1
0
    protected override void MoveGrabbedObject(Vector3 pos, Quaternion rot, bool forceTeleport = false)
    {
        if (m_grabbedObj == null)
        {
            return;
        }

        Rigidbody  grabbedRigidbody  = m_grabbedObj.grabbedRigidbody;
        Vector3    grabbablePosition = pos + rot * m_grabbedObjectPosOff;
        Quaternion grabbableRotation = rot * m_grabbedObjectRotOff;

        // account for rigidbody rotation freezes
        Vector3 newRotationEuler         = grabbableRotation.eulerAngles;
        Vector3 originalRotationEuler    = grabbedRigidbody.transform.rotation.eulerAngles;
        RigidbodyConstraints constraints = grabbedRigidbody.constraints;

        grabbableRotation = Quaternion.Euler(
            constraints.HasFlag(RigidbodyConstraints.FreezeRotationX) ? originalRotationEuler.x : newRotationEuler.x,
            constraints.HasFlag(RigidbodyConstraints.FreezeRotationY) ? originalRotationEuler.y : newRotationEuler.y,
            constraints.HasFlag(RigidbodyConstraints.FreezeRotationZ) ? originalRotationEuler.z : newRotationEuler.z);

        if (forceTeleport)
        {
            if (!m_grabbedOVRCookedObj.FixedPosition)
            {
                grabbedRigidbody.transform.position = grabbablePosition;
            }
            grabbedRigidbody.transform.rotation = grabbableRotation;
        }
        else
        {
            if (!m_grabbedOVRCookedObj.FixedPosition)
            {
                grabbedRigidbody.MovePosition(grabbablePosition);
            }
            grabbedRigidbody.MoveRotation(grabbableRotation);
        }
    }
Exemple #2
0
        private void DisplayConstraintParam(ref RigidbodyConstraints combined, bool displayRotation = true)
        {
            GUIHelper.DisplayMessage("<b> Constraints </b>");
            GUILayout.BeginHorizontal(CurrentSettings.LabelMarginStyle);
            EditorGUILayout.LabelField("Position", CurrentSettings.LabelMarginStyle);

            var prevWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = prevWidth * 0.1f;

            var x = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezePositionX), new GUIContent("X"),
                                     "Button");

            ChangeFlag(x, ref combined, RigidbodyConstraints.FreezePositionX);

            var y = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezePositionY), "Y", "Button");

            ChangeFlag(y, ref combined, RigidbodyConstraints.FreezePositionY);

            var z = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezePositionZ), "Z", "Button");

            ChangeFlag(z, ref combined, RigidbodyConstraints.FreezePositionZ);

            EditorGUIUtility.labelWidth = prevWidth;

            GUILayout.EndHorizontal();

            if (!displayRotation)
            {
                return;
            }

            GUILayout.BeginHorizontal(CurrentSettings.LabelMarginStyle);
            EditorGUILayout.LabelField("Rotation", CurrentSettings.LabelMarginStyle);

            prevWidth = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = prevWidth * 0.1f;

            var rotX = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezeRotationX), "X", "Button");

            ChangeFlag(rotX, ref combined, RigidbodyConstraints.FreezeRotationX);

            var rotY = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezeRotationY), "Y", "Button");

            ChangeFlag(rotY, ref combined, RigidbodyConstraints.FreezeRotationY);

            var rotZ = GUILayout.Toggle(combined.HasFlag(RigidbodyConstraints.FreezeRotationZ), "Z", "Button");

            ChangeFlag(rotZ, ref combined, RigidbodyConstraints.FreezeRotationZ);

            EditorGUIUtility.labelWidth = prevWidth;

            GUILayout.EndHorizontal();
        }