Exemplo n.º 1
0
 private void OnEnable()
 {
     distanceGrabbable = GetComponent <OculusSampleFramework.DistanceGrabbable>();
     playerVision      = GetComponentInChildren <Figurine_PlayerVision>();
     figurineTransform = GetComponent <Transform>();
     oldPos            = figurineTransform.position;
 }
Exemplo n.º 2
0
        void Update()
        {
            Debug.DrawRay(transform.position, transform.forward, Color.red, 0.1f);

            DistanceGrabbable target;
            Collider          targetColl;

            FindTarget(out target, out targetColl);

            if (target != m_target)
            {
                if (m_target != null)
                {
                    m_target.Targeted = m_otherHand.m_target == m_target;
                }
                if (m_target != null)
                {
                    m_target.ClearColor();
                }
                if (target != null)
                {
                    target.SetColor(m_focusColor);
                }
                m_target         = target;
                m_targetCollider = targetColl;
                if (m_target != null)
                {
                    m_target.Targeted = true;
                }
            }
        }
Exemplo n.º 3
0
        public override void Update()
        {
            base.Update();

            Debug.DrawRay(transform.position, transform.forward, Color.red, 0.1f);

            DistanceGrabbable target;
            Collider          targetColl;

            FindTarget(out target, out targetColl);

            if (target != m_target)
            {
                if (m_target != null)
                {
                    m_target.Targeted = m_otherHand.m_target == m_target;
                }
                m_target         = target;
                m_targetCollider = targetColl;
                if (m_target != null)
                {
                    m_target.Targeted = true;
                }
            }
        }
Exemplo n.º 4
0
        protected override void GrabBegin()
        {
            DistanceGrabbable closestGrabbable         = m_target;
            Collider          closestGrabbableCollider = m_targetCollider;

            GrabVolumeEnable(false);

            if (closestGrabbable != null)
            {
                if (closestGrabbable.isGrabbed)
                {
                    ((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable);
                }

                m_grabbedObj = closestGrabbable;
                m_grabbedObj.GrabBegin(this, closestGrabbableCollider);
                SetPlayerIgnoreCollision(m_grabbedObj.gameObject, true);

                m_movingObjectToHand = true;
                m_lastPos            = transform.position;
                m_lastRot            = transform.rotation;

                // If it's within a certain distance respect the no-snap.
                Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
                if (!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold)
                {
                    Vector3 relPos = m_grabbedObj.transform.position - transform.position;
                    m_movingObjectToHand = false;
                    relPos = Quaternion.Inverse(transform.rotation) * relPos;
                    m_grabbedObjectPosOff = relPos;
                    Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation;
                    m_grabbedObjectRotOff = relOri;
                }
                else
                {
                    // Set up offsets for grabbed object desired position relative to hand.
                    m_grabbedObjectPosOff = m_gripTransform.localPosition;
                    if (m_grabbedObj.snapOffset)
                    {
                        Vector3 snapOffset = m_grabbedObj.snapOffset.position;
                        if (m_controller == OVRInput.Controller.LTouch)
                        {
                            snapOffset.x = -snapOffset.x;
                        }
                        m_grabbedObjectPosOff += snapOffset;
                    }

                    m_grabbedObjectRotOff = m_gripTransform.localRotation;
                    if (m_grabbedObj.snapOffset)
                    {
                        m_grabbedObjectRotOff = m_grabbedObj.snapOffset.rotation * m_grabbedObjectRotOff;
                        if (m_controller == OVRInput.Controller.LTouch)
                        {
                            m_grabbedObjectRotOff = Quaternion.Euler(m_grabbedObj.transform.rotation.x, m_grabbedObj.transform.rotation.y - 90f, m_grabbedObj.transform.rotation.z - 90f);
                        }
                    }
                }
            }
        }
        protected override void GrabBegin()
        {
            DistanceGrabbable closestGrabbable         = m_target;
            Collider          closestGrabbableCollider = m_targetCollider;

            GrabVolumeEnable(false);

            if (closestGrabbable != null)
            {
                if (closestGrabbable.isGrabbed)
                {
                    ((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable);
                }

                m_grabbedObj = closestGrabbable;
                m_grabbedObj.GrabBegin(this, closestGrabbableCollider);

                m_movingObjectToHand = true;
                m_lastPos            = transform.position;
                m_lastRot            = transform.rotation;

                // Here it Trigger Once*********************************************************************************************************************************************************
                // Debug.Log(m_grabbedObj.name + "     Grab Begin");
                // FindObjectOfType<AudioManager>().Play("Drag"); // play the loop sound Drag

                // If it's within a certain distance respect the no-snap.
                Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
                if (!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold)
                {
                    Vector3 relPos = m_grabbedObj.transform.position - transform.position;
                    m_movingObjectToHand = false;
                    relPos = Quaternion.Inverse(transform.rotation) * relPos;
                    m_grabbedObjectPosOff = relPos;
                    Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation;
                    m_grabbedObjectRotOff = relOri;
                }
                else
                {
                    // Set up offsets for grabbed object desired position relative to hand.
                    m_grabbedObjectPosOff = m_gripTransform.localPosition;
                    if (m_grabbedObj.snapOffset)
                    {
                        Vector3 snapOffset = m_grabbedObj.snapOffset.position;
                        if (m_controller == OVRInput.Controller.LTouch)
                        {
                            snapOffset.x = -snapOffset.x;
                        }
                        m_grabbedObjectPosOff += snapOffset;
                    }

                    m_grabbedObjectRotOff = m_gripTransform.localRotation;
                    if (m_grabbedObj.snapOffset)
                    {
                        m_grabbedObjectRotOff = m_grabbedObj.snapOffset.rotation * m_grabbedObjectRotOff;
                    }
                }
            }
        }
Exemplo n.º 6
0
        void OnTriggerExit(Collider otherCollider)
        {
            DistanceGrabbable dg = otherCollider.GetComponentInChildren <DistanceGrabbable>();

            if (dg)
            {
                dg.InRange = false;
            }
        }
Exemplo n.º 7
0
        void OnTriggerEnter(Collider otherCollider)
        {
            DistanceGrabbable dg = otherCollider.GetComponentInParent <DistanceGrabbable>();

            if (dg)
            {
                dg.InRange = true;
            }
        }
Exemplo n.º 8
0
        void OnTriggerExit(Collider otherCollider)
        {
            DistanceGrabbable dg = GetGrabbable(otherCollider);

            if (dg)
            {
                dg.InRange = false;
            }
        }
Exemplo n.º 9
0
        void OnTriggerEnter(Collider otherCollider)
        {
            DistanceGrabbable dg = GetGrabbable(otherCollider);

            if (dg)
            {
                dg.InRange = true;
            }
        }
        protected bool FindTargetWithSpherecast(out DistanceGrabbable dgOut, out Collider collOut)
        {
            dgOut   = null;
            collOut = null;
            Ray        ray = new Ray(m_gripTransform.position, m_gripTransform.forward);
            RaycastHit hitInfo;

            // If no objects in grab volume, raycast.
            // Potential optimization:
            // In DistanceGrabbable.RefreshCrosshairs, we could move the object between collision layers.
            // If it's in range, it would move into the layer DistanceGrabber.m_grabObjectsInLayer,
            // and if out of range, into another layer so it's ignored by DistanceGrabber's SphereCast.
            // However, we're limiting the SphereCast by m_maxGrabDistance, so the optimization doesn't seem
            // essential.
            int layer = (m_grabObjectsInLayer == -1) ? ~0 : 1 << m_grabObjectsInLayer;

            if (Physics.SphereCast(ray, m_spherecastRadius, out hitInfo, m_maxGrabDistance, layer))
            {
                DistanceGrabbable grabbable   = null;
                Collider          hitCollider = null;
                if (hitInfo.collider != null)
                {
                    grabbable   = hitInfo.collider.gameObject.GetComponentInParent <DistanceGrabbable>();
                    hitCollider = grabbable == null ? null : hitInfo.collider;
                    if (grabbable)
                    {
                        dgOut   = grabbable;
                        collOut = hitCollider;
                    }
                }

                if (grabbable != null && m_preventGrabThroughWalls)
                {
                    // Found a valid hit. Now test to see if it's blocked by collision.
                    RaycastHit obstructionHitInfo;
                    ray.direction = hitInfo.point - m_gripTransform.position;

                    dgOut   = grabbable;
                    collOut = hitCollider;
                    if (Physics.Raycast(ray, out obstructionHitInfo, 1 << m_obstructionLayer))
                    {
                        DistanceGrabbable obstruction = null;
                        if (hitInfo.collider != null)
                        {
                            obstruction = obstructionHitInfo.collider.gameObject.GetComponentInParent <DistanceGrabbable>();
                        }
                        if (obstruction != grabbable && obstructionHitInfo.distance < hitInfo.distance)
                        {
                            dgOut   = null;
                            collOut = null;
                        }
                    }
                }
            }
            return(dgOut != null);
        }
Exemplo n.º 11
0
        void OnTriggerEnter(Collider otherCollider)
        {
            DistanceGrabbable dg = otherCollider.GetComponentInChildren <DistanceGrabbable>();

            if (dg)
            {
                dg.InRange = true;
                //dg.SetColor(OutlineColorInRange);
            }
        }
Exemplo n.º 12
0
        void Update()
        {
            Debug.DrawRay(transform.position, transform.forward, Color.red, 0.1f);

            DistanceGrabbable target;
            Collider          targetColl;

            FindTarget(out target, out targetColl);

            if (!m_canScaleObjects)
            {
                m_debounceTime -= Time.fixedDeltaTime;
            }

            if (m_debounceTime < 0.0f)
            {
                m_debounceTime    = 0.1f;
                m_canScaleObjects = true;
            }

            if (target != m_target)
            {
                if (m_target != null)
                {
                    m_target.Targeted = m_otherHand.m_target == m_target;
                }
                if (m_target != null)
                {
                    m_target.ClearColor();
                }
                if (target != null)
                {
                    target.SetColor(m_focusColor);
                }
                m_target         = target;
                m_targetCollider = targetColl;
                if (m_target != null)
                {
                    m_target.Targeted = true;
                }
            }
        }
Exemplo n.º 13
0
        protected override void GrabBegin()
        {
            DistanceGrabbable closestGrabbable         = m_target;
            Collider          closestGrabbableCollider = m_targetCollider;

            GrabVolumeEnable(false);

            if (closestGrabbable != null)
            {
                if (closestGrabbable.isGrabbed)
                {
                    ((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable);
                }

                m_grabbedObj = closestGrabbable;
                m_grabbedObj.GrabBegin(this, closestGrabbableCollider);

                m_movingObjectToHand = true;
                m_lastPos            = transform.position;
                m_lastRot            = transform.rotation;

                // If it's within a certain distance respect the no-snap.
                Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
                if (!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold)
                {
                    Vector3 relPos = m_grabbedObj.transform.position - transform.position;
                    m_movingObjectToHand = false;
                    relPos = Quaternion.Inverse(transform.rotation) * relPos;
                    m_grabbedObjectPosOff = relPos;
                    Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation;
                    m_grabbedObjectRotOff = relOri;
                }
                else
                {
                    SetOffsetPositions();
                }
            }
        }
Exemplo n.º 14
0
 //bool particle_on = false;
 //ParticleSystem ps;
 private void Awake()
 {
     grabState = this.GetComponent <OculusSampleFramework.DistanceGrabbable>();
     //Get component of the OVRGrabbable
     //ps = particle.GetComponent<ParticleSystem>();
 }
Exemplo n.º 15
0
        void OnTriggerExit(Collider otherCollider)
        {
            DistanceGrabbable dg = otherCollider.GetComponentInParent <DistanceGrabbable>();

            dg.InRange = false;
        }
Exemplo n.º 16
0
        protected override void GrabBegin()
        {
            DistanceGrabbable closestGrabbable         = m_target;
            Collider          closestGrabbableCollider = m_targetCollider;

            GrabVolumeEnable(false);

            if (closestGrabbable != null)
            {
                if (closestGrabbable.isGrabbed)
                {
                    ((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable);
                }

                m_grabbedObj = closestGrabbable;
                m_grabbedObj.GrabBegin(this, closestGrabbableCollider);
                SetPlayerIgnoreCollision(m_grabbedObj.gameObject, true);

                // added here to save original transform of old object

                // CHANGED HERE MADE FALSE
                m_movingObjectToHand   = true;
                m_moveableObjectEnable = false; // changed to false
                m_lastPos = transform.position;
                m_lastRot = transform.rotation;

                //failed
                //Vector3 grabOffset = m_grabbedObj.transform.position;


                // If it's within a certain distance respect the no-snap.
                Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
                if (!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold)
                {
                    Vector3 relPos = m_grabbedObj.transform.position - transform.position;
                    m_movingObjectToHand = false;
                    relPos = Quaternion.Inverse(transform.rotation) * relPos;
                    m_grabbedObjectPosOff = relPos;
                    Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation;
                    m_grabbedObjectRotOff = relOri;
                    // added
                    m_moveableObjectEnable = false;
                }
                else
                {
                    // NEED CHANGE HERE FOR GRABBING FAR FROM HAND


                    // need to change so that the distance is the same when u grab object

                    // commented out so maybe wont go to hand
                    //OLD
                    //m_grabbedObjectPosOff = m_gripTransform.localPosition;

                    // Set up offsets for grabbed object desired position relative to hand.
                    // position should be changed?
                    m_grabbedObjectPosOff = m_gripTransform.localPosition;

                    if (m_grabbedObj.snapOffset)
                    {
                        Vector3 snapOffset = m_grabbedObj.snapOffset.position;
                        if (m_controller == OVRInput.Controller.LTouch)
                        {
                            snapOffset.x = -snapOffset.x;
                        }
                        m_grabbedObjectPosOff += snapOffset;
                    }



                    m_grabbedObjectRotOff = m_gripTransform.localRotation;

                    if (m_grabbedObj.snapOffset)
                    {
                        m_grabbedObjectRotOff = m_grabbedObj.snapOffset.rotation * m_grabbedObjectRotOff;
                    }

                    MoveGrabbedObject(m_lastPos, m_lastRot, true);
                }
            }
        }
Exemplo n.º 17
0
        protected bool FindTarget(out DistanceGrabbable dgOut, out Collider collOut)
        {
            dgOut   = null;
            collOut = null;
            float closestMagSq = float.MaxValue;

            // First test for objects within the grab volume, if we're using those.
            // (Some usage of DistanceGrabber will not use grab volumes, and will only
            // use spherecasts, and that's supported.)
            foreach (OVRGrabbable cg in m_grabCandidates.Keys)
            {
                DistanceGrabbable grabbable = cg as DistanceGrabbable;
                bool canGrab = grabbable != null && grabbable.InRange && !(grabbable.isGrabbed && !grabbable.allowOffhandGrab);
                if (!canGrab)
                {
                    continue;
                }

                for (int j = 0; j < grabbable.grabPoints.Length; ++j)
                {
                    Collider grabbableCollider = grabbable.grabPoints[j];
                    // Store the closest grabbable
                    Vector3 closestPointOnBounds = grabbableCollider.ClosestPointOnBounds(m_gripTransform.position);
                    float   grabbableMagSq       = (m_gripTransform.position - closestPointOnBounds).sqrMagnitude;
                    if (grabbableMagSq < closestMagSq)
                    {
                        bool accept = true;
                        if (m_preventGrabThroughWalls)
                        {
                            // NOTE: if this raycast fails, ideally we'd try other rays near the edges of the object, especially for large objects.
                            // NOTE 2: todo optimization: sort the objects before performing any raycasts.
                            Ray ray = new Ray();
                            ray.direction = grabbable.transform.position - m_gripTransform.position;
                            ray.origin    = m_gripTransform.position;
                            RaycastHit obstructionHitInfo;
                            Debug.DrawRay(ray.origin, ray.direction, Color.red, 0.1f);

                            if (Physics.Raycast(ray, out obstructionHitInfo, m_maxGrabDistance, 1 << m_obstructionLayer))
                            {
                                float distToObject = (grabbableCollider.ClosestPointOnBounds(m_gripTransform.position) - m_gripTransform.position).magnitude;
                                if (distToObject > obstructionHitInfo.distance * 1.1)
                                {
                                    accept = false;
                                }
                            }
                        }
                        if (accept)
                        {
                            closestMagSq = grabbableMagSq;
                            dgOut        = grabbable;
                            collOut      = grabbableCollider;
                        }
                    }
                }
            }

            if (dgOut == null && m_useSpherecast)
            {
                return(FindTargetWithSpherecast(out dgOut, out collOut));
            }
            return(dgOut != null);
        }
Exemplo n.º 18
0
 public void SetTarget(DistanceGrabbable t)
 {
     m_target         = t;
     m_targetCollider = t.GetComponent <SphereCollider>();
 }