Exemplo n.º 1
0
 /// <summary> Remove the Rigidbody if one exists. </summary>
 public void TryRemoveRB()
 {
     SG_Util.TryRemoveRB(this.gameObject);
     this.physicsBody = null;
 }
Exemplo n.º 2
0
    /// <summary> Setup and/or change the tracking variables of this hand. </summary>
    /// <param name="newTarget"></param>
    /// <param name="trackType"></param>
    /// <param name="trackMethod"></param>
    /// <param name="rightHand"></param>
    protected virtual void SetupTracking(Transform newTarget, TrackingHardware trackType, TrackingMethod trackMethod, bool rightHand)
    {
        this.trackedObject    = newTarget;
        this.trackingHardware = trackType;
        this.trackingMethod   = trackMethod;

        //Calculate appropriate offsets
        if (trackedObject != null)
        {
            if (trackingHardware != TrackingHardware.Custom)
            {
                int        LR      = rightHand ? 1 : -1;
                Vector3    posOffs = Vector3.zero;
                Quaternion rotOffs = Quaternion.identity;
                if (trackingHardware == TrackingHardware.ViveTracker)
                {
                    posOffs = new Vector3(0.01f * LR, 0.04f, -0.085f);
                    rotOffs = Quaternion.Euler(0, -90, -90);
                    Debug.Log("Setting up right hand for Vive Tracker");
                }
                this.positionOffset = posOffs;
                this.rotationOffset = rotOffs;
            }
            else
            {
                SG_Util.CalculateOffsets(this.transform, this.trackedObject, out this.positionOffset, out this.rotationOffset);
            }
        }

        //Ignore collisions of the hand itself
        if (this.rigidBodyLayer != null)
        {
            if (this.physicsTrackingLayer != null)
            {
                this.rigidBodyLayer.SetIgnoreCollision(this.physicsTrackingLayer, true);
            }
            if (this.feedbackScript != null)
            {
                this.feedbackScript.SetIgnoreCollision(this.rigidBodyLayer, true);
            }
        }
        if (this.feedbackScript != null && this.physicsTrackingLayer != null)
        {
            this.feedbackScript.SetIgnoreCollision(this.physicsTrackingLayer, true);
        }

        //Apply the appropriate RB method
        if (trackingMethod == TrackingMethod.PhysicsBased && physicsTrackingLayer != null)
        {
            physicsTrackingLayer.RemoveRigidBodies();
            this.handRB     = SG_Util.TryAddRB(this.gameObject, false, false);
            ignoreGrabables = true;
            if (physicsTrackingLayer != null)
            {
                physicsTrackingLayer.gameObject.SetActive(true);
            }
        }
        else
        {
            ignoreGrabables = false;
            SG_Util.TryRemoveRB(this.gameObject); //should prevent calling OnCollisionEnter
            this.handRB = null;
            if (physicsTrackingLayer != null)
            {
                physicsTrackingLayer.gameObject.SetActive(false);
            }
        }
    }