コード例 #1
0
        /// <summary>
        /// It is called when this pickable object is released by the picker.
        /// </summary>
        /// <remarks>
        /// Note it is a little different from the implementation of <see cref="Pickable"/>. It does
        /// not need to change the rigidbody properties, since all the movement has been defined
        /// in <see cref="MoveTowardsTargetWithConstraint"/>.
        /// </remarks>
        /// <param name="picker">The picker that releases it.</param>
        public override void OnReleased(IPicker picker)
        {
            Rigidbody activeRb = GetActiveRb();

            // Need to update pickable mapping whenever a pickable object is released.
            PickableMapping.UpdatePickableMapping(activeRb, false, picker);
            // Send PickedRelease event
            OnReleasedEvent(picker);
        }
コード例 #2
0
 /// <summary>
 /// Modify the properties the associated rigidbody so it will follow the movement
 /// of the picker later.
 /// </summary>
 /// <param name="rb">The associated rigidbody.</param>
 /// <param name="picker">The picker that picks this object up.</param>
 protected void PutRbUnderControlState(Rigidbody rb, IPicker picker)
 {
     //if (GameController.Instance.AllowPassThrough)
     //{
     //    rb.isKinematic = true;
     //}
     //else
     //{
     //    rb.useGravity = false;
     //}
     rb.isKinematic = true;
     PickableMapping.UpdatePickableMapping(rb, true, picker);
     _rbOriginalConstraints = rb.constraints;
     //rb.constraints = RigidbodyConstraints.None;
 }
コード例 #3
0
        /// <summary>
        /// Restore the properties of the associated rigidbody when this object is released.
        /// </summary>
        /// <param name="rb">The associated rigidbody.</param>
        /// <param name="picker">The picker that releases this picable object.</param>
        protected void ReleaseRbFromControlState(Rigidbody rb, IPicker picker)
        {
            //if (GameController.Instance.AllowPassThrough)
            //{
            //    rb.isKinematic = false;
            //}
            //else
            //{
            //    rb.useGravity = true;
            //}

            rb.isKinematic = false;
            rb.constraints = _rbOriginalConstraints;
            // Unregister the relation between the picker and this rigidbody.
            PickableMapping.UpdatePickableMapping(rb, false, picker);
        }
コード例 #4
0
        /// <summary>
        /// It is called when this object is just picked up. It records some initial
        /// position and rotation offset with the picker, which will be used later.
        /// </summary>
        /// <remarks>
        /// Note that the implementation of this function is a little different from
        /// that of <see cref="Pickable"/>. Here it does not need to change the rigidbody properties
        /// to kinematic in order to follow the movement of the picker. Its movement
        /// is entirely defined in function <see cref="MoveTowardsTargetWithConstraint"/>.
        /// </remarks>
        /// <param name="picker">The picker that picks it up.</param>
        public override void OnPickedInit(IPicker picker)
        {
            Rigidbody activeRb = GetActiveRb();

            // Need to update the pickable mapping whenever a new object is picked up.
            PickableMapping.UpdatePickableMapping(activeRb, true, picker);
            PickerDexmo pickerDexmo     = picker as PickerDexmo;
            Transform   pickerReference = picker.Transform;

            if (pickerDexmo != null)
            {
                Transform handRootTransform = pickerDexmo.HandRootTransform;
                if (_pickerDexmoConstrainPart == PickerDexmoConstrainPartType.PalmCenter)
                {
                    pickerReference = pickerDexmo.PalmCenter;
                }
                HandRootPositionRelativeToPicker =
                    pickerReference.InverseTransformPoint(handRootTransform.position);
                HandRootRotationRelativeToPicker =
                    Quaternion.Inverse(pickerReference.rotation) * handRootTransform.rotation;
            }
            if (_constrainPositionReference != null)
            {
                PickerFixedDisplacementWrtConstrainPoint = pickerReference.position -
                                                           _constrainPositionReference.position;
            }
            if (_constrainRotationReference != null)
            {
                PickerFixedAngleDisplacementWrtConstrainPoint =
                    Quaternion.Inverse(_constrainRotationReference.rotation) *
                    pickerReference.rotation;
            }
            InitialPickerRotation = pickerReference.rotation;
            // Send the PickedInit event.
            OnPickedInitEvent(picker);
        }