Ejemplo n.º 1
0
        /// <summary>
        /// Called every frame while grabbing is active
        /// </summary>
        /// <param name="grabber"></param>
        protected virtual void OnGrabStay(Grabber grabber)
        {
            transform.position = grabber.transform.position;
            transform.rotation = grabber.transform.rotation;

            if (Rigidbody != null)
            {
                Rigidbody.isKinematic = true;
            }
        }
        protected override void DetachGrabber(Grabber grabber)
        {
            base.DetachGrabber(grabber);
            SpringJoint joint = GetComponent <SpringJoint>();

            if (joint != null)
            {
                joint.connectedBody = null;
                StartCoroutine(DestroyJointAfterDelay(joint));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Base method for start grabbing.
        /// </summary>
        /// <param name="grabber">The current grabber.</param>
        public virtual void StartGrabbing(Grabber grabber)
        {
            Grabber = grabber;
            State   = GrabbingState.SimpleGrab;

            AttachGrabber(grabber);
            if (OnGrabbed != null)
            {
                OnGrabbed(this);
            }
            SetColor(_grabbedColor);
        }
        protected override void AttachGrabber(Grabber grabber)
        {
            base.AttachGrabber(grabber);
            FixedJoint joint = GetComponent <FixedJoint>();

            if (joint == null)
            {
                joint = gameObject.AddComponent <FixedJoint>();
            }
            joint.connectedBody = grabber.GetComponent <Rigidbody>();
            var anchor = grabber.transform.position - transform.position;

            joint.anchor      = anchor;
            joint.breakForce  = BreakForce;
            joint.breakTorque = BreakTorque;
        }
        protected override void AttachGrabber(Grabber grabber)
        {
            base.AttachGrabber(grabber);
            SpringJoint joint = GetComponent <SpringJoint>();

            if (joint == null)
            {
                joint = gameObject.AddComponent <SpringJoint>();
            }
            joint.connectedBody = grabber.GetComponent <Rigidbody>();
            var anchor = grabber.transform.position - transform.position;

            joint.anchor          = anchor;
            joint.axis            = Vector3.one;
            joint.breakForce      = BreakForce;
            joint.breakTorque     = BreakTorque;
            joint.spring          = Spring;
            joint.damper          = Damper;
            joint.massScale       = MassScale;
            joint.enableCollision = true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called on grabbing stopped
        /// </summary>
        /// <param name="grabber"></param>
        public virtual void StopGrabbing(Grabber grabber)
        {
            grabber.StopGrabbing();
            State   = GrabbingState.Normal;
            Grabber = null;
            DetachGrabber(grabber);
            if (OnReleased != null)
            {
                OnReleased(this);
            }

            if (Rigidbody != null)
            {
                Rigidbody.isKinematic = false;
            }

            if (InputInstance.FocusedObject.GameObject != gameObject)
            {
                SetColor(_normalColor);
            }
        }
        protected override void AttachGrabber(Grabber grabber)
        {
            base.AttachGrabber(grabber);
            HingeJoint joint = GetComponent <HingeJoint>();

            if (joint == null)
            {
                joint = gameObject.AddComponent <HingeJoint>();
            }
            joint.connectedBody = grabber.GetComponent <Rigidbody>();
            var anchor = grabber.transform.position - transform.position;

            joint.anchor      = anchor;
            joint.axis        = Vector3.one;
            joint.breakForce  = BreakForce;
            joint.breakTorque = BreakTorque;
            joint.useLimits   = true;
            var limits = joint.limits;

            limits.min   = MinDistance;
            limits.max   = MaxDistance;
            joint.limits = limits;
        }
 protected override void OnGrabStay(Grabber grabber)
 {
     transform.position = Vector3.Lerp(transform.position, grabber.GrabHandle.position, Time.deltaTime * _lerpSpeed);
 }
 protected override void DetachGrabber(Grabber grabber)
 {
     base.DetachGrabber(grabber);
     Rigidbody.useGravity = true;
     State = GrabbingState.Normal;
 }
 protected override void AttachGrabber(Grabber grabber)
 {
     base.AttachGrabber(grabber);
     Rigidbody.useGravity = false;
     State = GrabbingState.AttachedGrab;
 }
 protected override void OnGrabStay(Grabber grabber)
 {
     // Do nothing, because physic engine will do for us
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Base method for deattaching grabber to rigidbody
 /// his is only used by joint and lerped based grabbing
 /// </summary>
 /// <param name="grabber"></param>
 protected virtual void DetachGrabber(Grabber grabber)
 {
 }