Beispiel #1
0
 public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
 {
     if (eventData.GetHashCode() == pointerEventDataHashMask && InputPossible)
     {
         base.Raycast(eventData, resultAppendList);
     }
 }
Beispiel #2
0
        public override void Raycast(PointerEventData eventData, List <RaycastResult> resultAppendList)
        {
            Collider c = GetComponent <Collider>();

#if VRTK_VERSION_3_2_1_OR_NEWER
            RaycastResult current = eventData.pointerCurrentRaycast;
            RaycastResult press   = eventData.pointerPressRaycast;



            Ray rCurrent = new Ray(current.worldPosition, current.worldNormal);
            Ray rLast    = new Ray(vrtkLastPointerPos, vrtkLastPointerDir);
            Ray rPress   = new Ray(press.worldPosition, press.worldNormal);

            vrtkLastPointerPos = current.worldPosition == Vector3.zero ? vrtkLastPointerPos : current.worldPosition;
            vrtkLastPointerDir = current.worldNormal == Vector3.zero ? vrtkLastPointerDir : current.worldNormal;


            //make the canvas "valid" for VRTK_VRInputModule.ValidElement(...) method
            if (CanvasToProject.GetComponent <AnyUiFakeVRTKCanvas>() == null)
            {
                CanvasToProject.gameObject.AddComponent <AnyUiFakeVRTKCanvas>();
            }
#else
            Ray rCurrent = eventCamera.ScreenPointToRay(eventData.position);
            Ray rLast    = eventCamera.ScreenPointToRay(eventData.position - eventData.delta);
            Ray rPress   = eventCamera.ScreenPointToRay(eventData.pressPosition);
#endif
            RaycastHit i;

            receiver.InputPossible = false;
            //perform raycast against this object, append results
            if (rCurrent.direction != Vector3.zero && c.Raycast(rCurrent, out i, float.MaxValue))
            {
                //hit, tell canvas
                receiver.InputPossible = true;

                PointerEventData pData = eventData;

                Vector2 guiPos      = i.textureCoord;
                Vector3 screenPoint = receiver.eventCamera.ViewportToScreenPoint(guiPos);
                //update hover position
                pData.position = new Vector2(screenPoint.x, screenPoint.y);

                //update  delta
                if (rLast.direction != Vector3.zero && c.Raycast(rLast, out i, float.MaxValue))
                {
                    guiPos = i.textureCoord;
                    Vector3 lastScreenPoint = receiver.eventCamera.ViewportToScreenPoint(guiPos);
                    pData.delta = new Vector2(screenPoint.x - lastScreenPoint.x, screenPoint.y - lastScreenPoint.y);
                    //Debug.Log(pData.delta);
                }

                //update press position
                if (rPress.direction != Vector3.zero && c.Raycast(rPress, out i, float.MaxValue))
                {
                    guiPos              = i.textureCoord;
                    screenPoint         = receiver.eventCamera.ViewportToScreenPoint(guiPos);
                    pData.pressPosition = new Vector2(screenPoint.x, screenPoint.y);
                }

                List <RaycastResult> results = new List <RaycastResult>();
                receiver.setPointerEventDataHashMask(pData.GetHashCode());
                //continue raycast on GUI
                receiver.Raycast(pData, results);
                resultAppendList.AddRange(results);
            }
        }