public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
 {
   if ((Object) this.eventCamera == (Object) null)
     return;
   Ray ray = this.eventCamera.ScreenPointToRay((Vector3) eventData.position);
   float distance = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;
   RaycastHit2D[] raycastHit2DArray = Physics2D.RaycastAll((Vector2) ray.origin, (Vector2) ray.direction, distance, this.finalEventMask);
   if (raycastHit2DArray.Length == 0)
     return;
   int index = 0;
   for (int length = raycastHit2DArray.Length; index < length; ++index)
   {
     SpriteRenderer component = raycastHit2DArray[index].collider.gameObject.GetComponent<SpriteRenderer>();
     RaycastResult raycastResult = new RaycastResult()
     {
       gameObject = raycastHit2DArray[index].collider.gameObject,
       module = (BaseRaycaster) this,
       distance = Vector3.Distance(this.eventCamera.transform.position, raycastHit2DArray[index].transform.position),
       worldPosition = (Vector3) raycastHit2DArray[index].point,
       worldNormal = (Vector3) raycastHit2DArray[index].normal,
       screenPosition = eventData.position,
       index = (float) resultAppendList.Count,
       sortingLayer = !((Object) component != (Object) null) ? 0 : component.sortingLayerID,
       sortingOrder = !((Object) component != (Object) null) ? 0 : component.sortingOrder
     };
     resultAppendList.Add(raycastResult);
   }
 }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.EventSystems.RaycastResult o;
         o = new UnityEngine.EventSystems.RaycastResult();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Esempio n. 3
0
        public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            if (eventCamera == null)
                return;

            var ray = eventCamera.ScreenPointToRay(eventData.position);

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics2D.GetRayIntersectionAll(ray, dist, finalEventMask);

            if (hits.Length != 0)
            {
                eventData.worldPosition = hits[0].point;
                eventData.worldNormal = hits[0].normal;
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject = hits[b].collider.gameObject,
                        module = this,
                        distance = Vector3.Distance(eventCamera.transform.position, hits[b].transform.position),
                        index = resultAppendList.Count
                    };
                    resultAppendList.Add(result);
                }
            }
        }
Esempio n. 4
0
 public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
 {
     if (this.eventCamera != null)
     {
         Ray ray = this.eventCamera.ScreenPointToRay((Vector3) eventData.position);
         float distance = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;
         RaycastHit2D[] hitdArray = Physics2D.RaycastAll(ray.origin, ray.direction, distance, base.finalEventMask);
         if (hitdArray.Length != 0)
         {
             int index = 0;
             int length = hitdArray.Length;
             while (index < length)
             {
                 SpriteRenderer component = hitdArray[index].collider.gameObject.GetComponent<SpriteRenderer>();
                 RaycastResult item = new RaycastResult {
                     gameObject = hitdArray[index].collider.gameObject,
                     module = this,
                     distance = Vector3.Distance(this.eventCamera.transform.position, hitdArray[index].transform.position),
                     worldPosition = (Vector3) hitdArray[index].point,
                     worldNormal = (Vector3) hitdArray[index].normal,
                     screenPosition = eventData.position,
                     index = resultAppendList.Count,
                     sortingLayer = (component == null) ? 0 : component.sortingLayerID,
                     sortingOrder = (component == null) ? 0 : component.sortingOrder
                 };
                 resultAppendList.Add(item);
                 index++;
             }
         }
     }
 }
Esempio n. 5
0
    //Reset the Positions of the UI Elements on both Start and Quit
    void Start() {
      if (ButtonFace != null) {
        if (Shadow != null) {
          MaxShadowOpacity = Shadow.color.a;
          Shadow.color = new Color(Shadow.color.r, Shadow.color.g, Shadow.color.b, 0f);
        }

        body = ButtonFace.GetComponent<Rigidbody>();
        SpringJoint = ButtonFace.GetComponent<SpringJoint>();
        InitialLocalPosition = ButtonFace.localPosition;

        pointerEvent = new PointerEventData(EventSystem.current);
        pointerEvent.button = PointerEventData.InputButton.Left;
        RaycastResult result = new RaycastResult();
        result.gameObject = gameObject;
        pointerEvent.pointerCurrentRaycast = result;
        pointerEvent.pointerPress = gameObject;
        pointerEvent.rawPointerPress = gameObject;
        ButtonFace.localPosition = new Vector3(InitialLocalPosition.x, InitialLocalPosition.y, SpringJoint.connectedAnchor.z);
        PhysicsPosition = transform.TransformPoint(new Vector3(InitialLocalPosition.x, InitialLocalPosition.y, SpringJoint.connectedAnchor.z));
        body.position = PhysicsPosition;
      } else {
        Debug.LogWarning("Ensure that you have a UI Element allotted in the Layer Transform!");
      }
    }
Esempio n. 6
0
 public void OnClick(UnityEngine.EventSystems.RaycastResult result)
 {
     if (SceneManager.GetActiveScene().name != "Menu")
     {
         GameManager.Instance.OnClick(result);
     }
 }
Esempio n. 7
0
 public void OnClick(UnityEngine.EventSystems.RaycastResult result)
 {
     if (SceneManager.GetActiveScene().name == "Game")
     {
         GameManager.Game.OnClick(result);
     }
 }
Esempio n. 8
0
        public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            if (eventCamera == null)
                return;

            var ray = eventCamera.ScreenPointToRay(eventData.position);

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics2D.RaycastAll(ray.origin, ray.direction, dist, finalEventMask);

            if (hits.Length != 0)
            {
                eventData.worldPosition = hits[0].point;
                eventData.worldNormal = hits[0].normal;
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    SpriteRenderer sr = hits[b].collider.gameObject.GetComponent<SpriteRenderer>();

                    var result = new RaycastResult
                    {
                        gameObject = hits[b].collider.gameObject,
                        module = this,
                        distance = Vector3.Distance(eventCamera.transform.position, hits[b].transform.position),
                        index = resultAppendList.Count,
                        sortingLayer =  sr != null ? sr.sortingLayerID : 0,
                        sortingOrder = sr != null ? sr.sortingOrder : 0
                    };
                    resultAppendList.Add(result);
                }
            }
        }
Esempio n. 9
0
 static public int set_index(IntPtr l)
 {
     UnityEngine.EventSystems.RaycastResult o = (UnityEngine.EventSystems.RaycastResult)checkSelf(l);
     System.Single v;
     checkType(l, 2, out v);
     o.index = v;
     setBack(l, o);
     return(0);
 }
Esempio n. 10
0
 public static void PointerEnter(GameObject obj)
 {
     print("PointerEnter " + obj.name);
     PointerEventData pEvent = new PointerEventData(_singleton.eventSystem);
     pEvent.pointerEnter = obj;
     RaycastResult rcr = new RaycastResult() { worldPosition = cursorPosition };
     pEvent.pointerCurrentRaycast = rcr;
     ExecuteEvents.Execute(obj, pEvent, ExecuteEvents.pointerEnterHandler);
 }
Esempio n. 11
0
 static public int set_depth(IntPtr l)
 {
     UnityEngine.EventSystems.RaycastResult o = (UnityEngine.EventSystems.RaycastResult)checkSelf(l);
     System.Int32 v;
     checkType(l, 2, out v);
     o.depth = v;
     setBack(l, o);
     return(0);
 }
Esempio n. 12
0
 static public int set_gameObject(IntPtr l)
 {
     UnityEngine.EventSystems.RaycastResult o = (UnityEngine.EventSystems.RaycastResult)checkSelf(l);
     UnityEngine.GameObject v;
     checkType(l, 2, out v);
     o.gameObject = v;
     setBack(l, o);
     return(0);
 }
Esempio n. 13
0
 static public int set_module(IntPtr l)
 {
     UnityEngine.EventSystems.RaycastResult o = (UnityEngine.EventSystems.RaycastResult)checkSelf(l);
     UnityEngine.EventSystems.BaseRaycaster v;
     checkType(l, 2, out v);
     o.module = v;
     setBack(l, o);
     return(0);
 }
Esempio n. 14
0
 void RefreshCursor(UnityEngine.EventSystems.RaycastResult raycastResult)
 {
     if (raycastResult.gameObject != null)
     {
         dot.GetComponent <SpriteRenderer>().DOFade(1, 0.5f);
     }
     else
     {
         dot.GetComponent <SpriteRenderer>().DOFade(0, 0.5f);
     }
 }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.EventSystems.RaycastResult o;
			o=new UnityEngine.EventSystems.RaycastResult();
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.EventSystems.RaycastResult o;
         o = new UnityEngine.EventSystems.RaycastResult();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        private List<RaycastResult> CheckRaycasts(VRTK_UIPointer pointer)
        {
            var raycastResult = new RaycastResult();
            raycastResult.worldPosition = pointer.transform.position;
            raycastResult.worldNormal = pointer.transform.forward;

            pointer.pointerEventData.pointerCurrentRaycast = raycastResult;

            List<RaycastResult> raycasts = new List<RaycastResult>();
            eventSystem.RaycastAll(pointer.pointerEventData, raycasts);
            return raycasts;
        }
Esempio n. 18
0
        /// <summary>
        /// Will fill the list with UI elements from EventSystem raycast.
        /// </summary>
        /// <param name="focusedItems">The list to be filled.</param>
        /// <returns>Did the raycast hit anything.</returns>
        private bool GetUIRaycasts(ref List <FocusInfo> focusedItems)
        {
            bool hit = false;

            // Get UI raycasts
            m_UIRaycastResults.Clear();
            if (EventSystem.current != null)
            {
                EventSystem.current.RaycastAll(GetPointerData(), m_UIRaycastResults);
                hit = hit ? hit : (m_UIRaycastResults != null && m_UIRaycastResults.Count > 0);

                if (hit)
                {
                    // Add UI hits
                    for (int i = 0; i < m_UIRaycastResults.Count; ++i)
                    {
                        UnityEngine.EventSystems.RaycastResult raycastResult = m_UIRaycastResults[i];

                        float distance = raycastResult.distance;

                        if (distance <= FocusManager.Instance.MaxGazeDistance)
                        {
                            FocusInfo focusInfo = m_FocusInfoPool.GetObject();
                            focusInfo.SetUI(raycastResult.gameObject, true, raycastResult.index, distance, TargetOrigin + (TargetDirection.normalized * distance), -raycastResult.gameObject.transform.forward, raycastResult.gameObject.transform, Vector2.zero, raycastResult);
                            focusedItems.Add(focusInfo);
                        }
                    }

                    // Sort via render order
                    focusedItems.Sort((FocusInfo a, FocusInfo b) => {
                        if (a.raycastResult.sortingLayer != b.raycastResult.sortingLayer)
                        {
                            return(a.raycastResult.sortingLayer.CompareTo(b.raycastResult.sortingLayer));
                        }

                        if (a.raycastResult.sortingOrder != b.raycastResult.sortingOrder)
                        {
                            return(b.raycastResult.sortingOrder.CompareTo(a.raycastResult.sortingOrder));
                        }

                        bool distanceSimilar = Mathf.Approximately(a.distance, b.distance);
                        if (distanceSimilar)
                        {
                            return(a.raycastResult.index.CompareTo(b.raycastResult.index));
                        }
                        return(a.distance.CompareTo(b.distance));
                    });
                }
            }

            return(hit);
        }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.EventSystems.RaycastResult o;
         o=new UnityEngine.EventSystems.RaycastResult();
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
Esempio n. 20
0
    private static IMenuItem GetClickedMenuItem()
    {
        GvrBasePointer pointer = GvrPointerInputModule.Pointer;

        UnityEngine.EventSystems.RaycastResult currentRaycastResult = pointer.CurrentRaycastResult;
        GameObject clickedObject = currentRaycastResult.gameObject;

        if (clickedObject != null & clickedObject.GetComponent <IMenuItem>() != null)
        {
            return(clickedObject.GetComponent <IMenuItem>());
        }
        return(null);
    }
Esempio n. 21
0
 static public int Clear(IntPtr l)
 {
     try{
         UnityEngine.EventSystems.RaycastResult self = (UnityEngine.EventSystems.RaycastResult)checkSelf(l);
         self.Clear();
         setBack(l, self);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Esempio n. 22
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.EventSystems.RaycastResult o;
         o = new UnityEngine.EventSystems.RaycastResult();
         pushValue(l, o);
         return(1);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
        protected override MouseState GetMousePointerEventData(int id)
        {
            // Populate the left button...
            PointerEventData leftData;
            var created = GetPointerData(kMouseLeftId, out leftData, true);

            leftData.Reset();

            if (created)
                leftData.position = Input.mousePosition;

            Vector2 pos = Input.mousePosition;
            leftData.delta = pos - leftData.position;
            leftData.position = pos;
            leftData.scrollDelta = Input.mouseScrollDelta;
            leftData.button = PointerEventData.InputButton.Left;

            if (Switch.Phase[0] == 2)
            {
                RaycastResult result = new RaycastResult();
                result.gameObject = Switch.GameObject[0];
                Switch.GameObject[0] = null;
                m_RaycastResultCache.Add(result);
            }
            else
            {
                eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            }

            var raycast = FindFirstRaycast(m_RaycastResultCache);
            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            // copy the apropriate data into right and middle slots
            PointerEventData rightData;
            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            PointerEventData middleData;
            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;

            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, SwitchStateForMouseButton(0), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, SwitchStateForMouseButton(1), rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, SwitchStateForMouseButton(2), middleData);

            return m_MouseState;
        }
 // Update is called once per frame
 void Update()
 {
     if (GvrControllerInput.ClickButtonUp)
     {
         GvrBasePointer pointer = GvrPointerInputModule.Pointer;
         UnityEngine.EventSystems.RaycastResult currentRaycastResult = pointer.CurrentRaycastResult;
         if (currentRaycastResult.gameObject == floor)
         {
             float xPosition = currentRaycastResult.worldPosition.x;
             float zPosition = currentRaycastResult.worldPosition.z;
             teleport(xPosition, zPosition);
         }
     }
 }
Esempio n. 25
0
 void HandleLook()
 {
     if (pointerEventData == null)
     {
         pointerEventData = new PointerEventData(eventSystem);
     }
     // fake a pointer always being at the center of the screen
     pointerEventData.position = new Vector2(Screen.width/2, Screen.height/2);
     pointerEventData.delta = Vector2.zero;
     List<RaycastResult> raycastResults = new List<RaycastResult>();
     eventSystem.RaycastAll(pointerEventData, raycastResults);
     CurrentRaycast = pointerEventData.pointerCurrentRaycast = FindFirstRaycast(raycastResults);
     ProcessMove(pointerEventData);
 }
Esempio n. 26
0
    static int QPYX_get_pointerPressRaycast_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.EventSystems.PointerEventData QPYX_obj_YXQP = (UnityEngine.EventSystems.PointerEventData)QPYX_o_YXQP;
            UnityEngine.EventSystems.RaycastResult QPYX_ret_YXQP = QPYX_obj_YXQP.pointerPressRaycast;
            ToLua.PushValue(L_YXQP, QPYX_ret_YXQP);
            return(1);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index pointerPressRaycast on a nil value"));
        }
    }
    private void Update()
    {
        if (GvrControllerInput.ClickButtonUp)
        {
            GvrBasePointer pointer = GvrPointerInputModule.Pointer;
            UnityEngine.EventSystems.RaycastResult currentRaycastResult = pointer.CurrentRaycastResult;
            GameObject clickedObject = currentRaycastResult.gameObject;
            IFlippable flipTarget    = clickedObject != null?clickedObject.GetComponent <IFlippable>() : null;

            if (flipTarget != null)
            {
                flipTarget.flip(force, currentRaycastResult.worldPosition);
            }
        }
    }
Esempio n. 28
0
 static int ToString(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.EventSystems.RaycastResult obj = (UnityEngine.EventSystems.RaycastResult)ToLua.CheckObject(L, 1, typeof(UnityEngine.EventSystems.RaycastResult));
         string o = obj.ToString();
         LuaDLL.lua_pushstring(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Esempio n. 29
0
 static int Clear(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.EventSystems.RaycastResult obj = (UnityEngine.EventSystems.RaycastResult)ToLua.CheckObject(L, 1, typeof(UnityEngine.EventSystems.RaycastResult));
         obj.Clear();
         ToLua.SetBack(L, 1, obj);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    private void Update()
    {
        if (GvrControllerInput.ClickButtonUp)
        {
            GvrBasePointer pointer = GvrPointerInputModule.Pointer;
            UnityEngine.EventSystems.RaycastResult currentRaycastResult = pointer.CurrentRaycastResult;
            GameObject    clickedObject      = currentRaycastResult.gameObject;
            IInteractable interactableObject = clickedObject != null?clickedObject.GetComponent <IInteractable>() : null;

            if (interactableObject != null)
            {
                interactableObject.interact(holdSpot);
            }
        }
    }
Esempio n. 31
0
    public void OnClick(UnityEngine.EventSystems.RaycastResult ray)
    {
        if (ray.module.name == "PauseCanvas")
        {
            return;
        }
        switch (state)
        {
        case GameState.Story:
            GameUI.StoryManager.OnClick();
            break;

        case GameState.Game:
            break;
        }
    }
Esempio n. 32
0
    static int QPYX_set_pointerPressRaycast_YXQP(IntPtr L_YXQP)
    {
        object QPYX_o_YXQP = null;

        try
        {
            QPYX_o_YXQP = ToLua.ToObject(L_YXQP, 1);                        UnityEngine.EventSystems.PointerEventData QPYX_obj_YXQP = (UnityEngine.EventSystems.PointerEventData)QPYX_o_YXQP;
            UnityEngine.EventSystems.RaycastResult QPYX_arg0_YXQP = StackTraits <UnityEngine.EventSystems.RaycastResult> .Check(L_YXQP, 2);

            QPYX_obj_YXQP.pointerPressRaycast = QPYX_arg0_YXQP;
            return(0);
        }
        catch (Exception QPYX_e_YXQP)            {
            return(LuaDLL.toluaL_exception(L_YXQP, QPYX_e_YXQP, QPYX_o_YXQP, "attempt to index pointerPressRaycast on a nil value"));
        }
    }
 static int _get_this(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
         int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
         UnityEngine.EventSystems.RaycastResult o = obj[arg0];
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int Add(IntPtr L)
    {
        try
        {
            ToLua.CheckArgsCount(L, 2);
            System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
            UnityEngine.EventSystems.RaycastResult arg0 = StackTraits <UnityEngine.EventSystems.RaycastResult> .Check(L, 2);

            obj.Add(arg0);
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
 static int FindLast(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
         System.Predicate <UnityEngine.EventSystems.RaycastResult> arg0 = (System.Predicate <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckDelegate <System.Predicate <UnityEngine.EventSystems.RaycastResult> >(L, 2);
         UnityEngine.EventSystems.RaycastResult o = obj.FindLast(arg0);
         ToLua.PushValue(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
    static int BinarySearch(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 2)
            {
                System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
                UnityEngine.EventSystems.RaycastResult arg0 = StackTraits <UnityEngine.EventSystems.RaycastResult> .Check(L, 2);

                int o = obj.BinarySearch(arg0);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 3)
            {
                System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
                UnityEngine.EventSystems.RaycastResult arg0 = StackTraits <UnityEngine.EventSystems.RaycastResult> .Check(L, 2);

                System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult> arg1 = (System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject <System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult> >(L, 3);
                int o = obj.BinarySearch(arg0, arg1);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else if (count == 5)
            {
                System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult> obj = (System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <UnityEngine.EventSystems.RaycastResult>));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                UnityEngine.EventSystems.RaycastResult arg2 = StackTraits <UnityEngine.EventSystems.RaycastResult> .Check(L, 4);

                System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult> arg3 = (System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult>)ToLua.CheckObject <System.Collections.Generic.IComparer <UnityEngine.EventSystems.RaycastResult> >(L, 5);
                int o = obj.BinarySearch(arg0, arg1, arg2, arg3);
                LuaDLL.lua_pushinteger(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: System.Collections.Generic.List<UnityEngine.EventSystems.RaycastResult>.BinarySearch"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Esempio n. 37
0
    static int get_distance(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.EventSystems.RaycastResult obj = (UnityEngine.EventSystems.RaycastResult)o;
            float ret = obj.distance;
            LuaDLL.lua_pushnumber(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index distance on a nil value"));
        }
    }
Esempio n. 38
0
    static int get_module(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.EventSystems.RaycastResult obj = (UnityEngine.EventSystems.RaycastResult)o;
            UnityEngine.EventSystems.BaseRaycaster ret = obj.module;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index module on a nil value"));
        }
    }
Esempio n. 39
0
    static int get_isValid(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.EventSystems.RaycastResult obj = (UnityEngine.EventSystems.RaycastResult)o;
            bool ret = obj.isValid;
            LuaDLL.lua_pushboolean(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index isValid on a nil value"));
        }
    }
    static int set_pointerPressRaycast(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.EventSystems.PointerEventData obj  = (UnityEngine.EventSystems.PointerEventData)o;
            UnityEngine.EventSystems.RaycastResult    arg0 = (UnityEngine.EventSystems.RaycastResult)ToLua.CheckObject(L, 2, typeof(UnityEngine.EventSystems.RaycastResult));
            obj.pointerPressRaycast = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index pointerPressRaycast on a nil value" : e.Message));
        }
    }
    static int get_pointerPressRaycast(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UnityEngine.EventSystems.PointerEventData obj = (UnityEngine.EventSystems.PointerEventData)o;
            UnityEngine.EventSystems.RaycastResult    ret = obj.pointerPressRaycast;
            ToLua.PushValue(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index pointerPressRaycast on a nil value" : e.Message));
        }
    }
		public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
		{
			Vector2 pos;
			if (letterBoxCamera == null)
				pos = new Vector2(eventData.position.x / Screen.width, eventData.position.y / Screen.height);
			else
				pos = letterBoxCamera.CachedCamera.ScreenToViewportPoint(eventData.position);

			if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
				return;

			int index = 0;
			foreach (GameObject target in targetObjectList)
			{
				RaycastResult result = new RaycastResult();
				result.distance = float.MaxValue;
				result.gameObject = target;
				result.index = index++;
				result.module = this;
				resultAppendList.Add(result);
			}
		}
        private void SetNearestRaycast(ref PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            RaycastResult? nearestRaycast = null;
            for (var index = 0; index < m_RaycastResults.Count; index++)
            {
                RaycastResult castResult = new RaycastResult();
                castResult.gameObject = m_RaycastResults[index].graphic.gameObject;
                castResult.module = this;
                castResult.distance = m_RaycastResults[index].distance;
                castResult.screenPosition = m_RaycastResults[index].pointerPosition;
                castResult.worldPosition = m_RaycastResults[index].position;
                castResult.index = resultAppendList.Count;
                castResult.depth = m_RaycastResults[index].graphic.depth;
                castResult.sortingLayer = canvas.sortingLayerID;
                castResult.sortingOrder = canvas.sortingOrder;
                if (!nearestRaycast.HasValue || castResult.distance < nearestRaycast.Value.distance)
                {
                    nearestRaycast = castResult;
                }
                resultAppendList.Add(castResult);
            }

            if (nearestRaycast.HasValue)
            {
                eventData.position = nearestRaycast.Value.screenPosition;
                eventData.delta = eventData.position - lastKnownPosition;
                lastKnownPosition = eventData.position;
                eventData.pointerCurrentRaycast = nearestRaycast.Value;
            }
        }
Esempio n. 44
0
        /// <summary>
        ///  Perform a Spherecast using the worldSpaceRay in eventData.
        /// </summary>
        /// <param name="eventData"></param>
        /// <param name="resultAppendList"></param>
        /// <param name="radius">Radius of the sphere</param>
        public void Spherecast(PointerEventData eventData, List<RaycastResult> resultAppendList, float radius)
        {
            if (eventCamera == null)
                return;

            OVRRayPointerEventData rayPointerEventData = eventData as OVRRayPointerEventData;
            if (rayPointerEventData == null)
                return;

            var ray = rayPointerEventData.worldSpaceRay;

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.SphereCastAll(ray, radius, dist, finalEventMask);

            if (hits.Length > 1)
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));

            if (hits.Length != 0)
            {
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject = hits[b].collider.gameObject,
                        module = this,
                        distance = hits[b].distance,
                        index = resultAppendList.Count,
                        worldPosition = hits[0].point,
                        worldNormal = hits[0].normal,
                    };
                    resultAppendList.Add(result);
                }
            }
        }
Esempio n. 45
0
        private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs)
        {
            if (lhs.module != rhs.module)
            {
                if (lhs.module.eventCamera != null && rhs.module.eventCamera != null && lhs.module.eventCamera.depth != rhs.module.eventCamera.depth)
                {
                    // need to reverse the standard compareTo
                    if (lhs.module.eventCamera.depth < rhs.module.eventCamera.depth)
                        return 1;
                    if (lhs.module.eventCamera.depth == rhs.module.eventCamera.depth)
                        return 0;

                    return -1;
                }

                if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority)
                    return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority);

                if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority)
                    return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority);
            }

            if (lhs.sortingLayer != rhs.sortingLayer)
            {
                // Uses the layer value to properly compare the relative order of the layers.
                var rid = SortingLayer.GetLayerValueFromID(rhs.sortingLayer);
                var lid = SortingLayer.GetLayerValueFromID(lhs.sortingLayer);
                return rid.CompareTo(lid);
            }


            if (lhs.sortingOrder != rhs.sortingOrder)
                return rhs.sortingOrder.CompareTo(lhs.sortingOrder);

            if (lhs.depth != rhs.depth)
                return rhs.depth.CompareTo(lhs.depth);

            if (lhs.distance != rhs.distance)
                return lhs.distance.CompareTo(rhs.distance);

            return lhs.index.CompareTo(rhs.index);
        }
Esempio n. 46
0
        public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            if (eventCamera == null)
                return;

            var ray = eventCamera.ScreenPointToRay(eventData.position);

            float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

            var hits = Physics.RaycastAll(ray, dist, finalEventMask);

            if (hits.Length > 1)
                System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));

            if (hits.Length != 0)
            {
                eventData.worldPosition = hits[0].point;
                eventData.worldNormal = hits[0].normal;
                for (int b = 0, bmax = hits.Length; b < bmax; ++b)
                {
                    var result = new RaycastResult
                    {
                        gameObject = hits[b].collider.gameObject,
                        module = this,
                        distance = hits[b].distance,
                        index = resultAppendList.Count,
                        sortingLayer = 0,
                        sortingOrder = 0
                    };
                    resultAppendList.Add(result);
                }
            }
        }
Esempio n. 47
0
    private void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList, Ray ray, bool checkForBlocking)
    {
        //This function is closely based on
        //void GraphicRaycaster.Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)

        if (canvas == null)
            return;

        float hitDistance = float.MaxValue;

        if (checkForBlocking && blockingObjects != BlockingObjects.None)
        {
            float dist = eventCamera.farClipPlane;

            if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
            {
                var hits = Physics.RaycastAll(ray, dist, m_BlockingMask);

                if (hits.Length > 0 && hits[0].distance < hitDistance)
                {
                    hitDistance = hits[0].distance;
                }
            }

            if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
            {
                var hits = Physics2D.GetRayIntersectionAll(ray, dist, m_BlockingMask);

                if (hits.Length > 0 && hits[0].fraction * dist < hitDistance)
                {
                    hitDistance = hits[0].fraction * dist;
                }
            }
        }

        m_RaycastResults.Clear();

        GraphicRaycast(canvas, ray, m_RaycastResults);

        for (var index = 0; index < m_RaycastResults.Count; index++)
        {
            var go = m_RaycastResults[index].graphic.gameObject;
            bool appendGraphic = true;

            if (ignoreReversedGraphics)
            {
                // If we have a camera compare the direction against the cameras forward.
                var cameraFoward = ray.direction;
                var dir = go.transform.rotation * Vector3.forward;
                appendGraphic = Vector3.Dot(cameraFoward, dir) > 0;
            }

            // Ignore points behind us (can happen with a canvas pointer)
            if (eventCamera.transform.InverseTransformPoint(m_RaycastResults[index].worldPos).z <= 0)
            {
                appendGraphic = false;
            }

            if (appendGraphic)
            {
                float distance = Vector3.Distance(ray.origin, m_RaycastResults[index].worldPos);

                if (distance >= hitDistance)
                {
                    continue;
                }

                var castResult = new RaycastResult
                {
                    gameObject = go,
                    module = this,
                    distance = distance,
                    index = resultAppendList.Count,
                    depth = m_RaycastResults[index].graphic.depth,

                    worldPosition = m_RaycastResults[index].worldPos
                };
                resultAppendList.Add(castResult);
            }
        }
    }
Esempio n. 48
0
 private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs)
 {
   if ((UnityEngine.Object) lhs.module != (UnityEngine.Object) rhs.module)
   {
     if ((UnityEngine.Object) lhs.module.eventCamera != (UnityEngine.Object) null && (UnityEngine.Object) rhs.module.eventCamera != (UnityEngine.Object) null && (double) lhs.module.eventCamera.depth != (double) rhs.module.eventCamera.depth)
     {
       if ((double) lhs.module.eventCamera.depth < (double) rhs.module.eventCamera.depth)
         return 1;
       return (double) lhs.module.eventCamera.depth == (double) rhs.module.eventCamera.depth ? 0 : -1;
     }
     if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority)
       return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority);
     if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority)
       return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority);
   }
   if (lhs.sortingLayer != rhs.sortingLayer)
     return SortingLayer.GetLayerValueFromID(rhs.sortingLayer).CompareTo(SortingLayer.GetLayerValueFromID(lhs.sortingLayer));
   if (lhs.sortingOrder != rhs.sortingOrder)
     return rhs.sortingOrder.CompareTo(lhs.sortingOrder);
   if (lhs.depth != rhs.depth)
     return rhs.depth.CompareTo(lhs.depth);
   if ((double) lhs.distance != (double) rhs.distance)
     return lhs.distance.CompareTo(rhs.distance);
   return lhs.index.CompareTo(rhs.index);
 }
Esempio n. 49
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TouchHit"/> struct.
 /// </summary>
 /// <param name="transform"> Target transform. </param>
 public TouchHit(Transform transform)
 {
     this.transform = transform;
     raycastHit = default(RaycastHit);
     raycastHit2D = default(RaycastHit2D);
     raycastResult = default(RaycastResult);
     type = TouchHitType.Hit3D;
 }
 public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
 {
   if ((UnityEngine.Object) this.canvas == (UnityEngine.Object) null)
     return;
   Vector2 vector2;
   if ((UnityEngine.Object) this.eventCamera == (UnityEngine.Object) null)
   {
     float width = (float) Screen.width;
     float height = (float) Screen.height;
     vector2 = new Vector2(eventData.position.x / width, eventData.position.y / height);
   }
   else
     vector2 = (Vector2) this.eventCamera.ScreenToViewportPoint((Vector3) eventData.position);
   if ((double) vector2.x < 0.0 || (double) vector2.x > 1.0 || ((double) vector2.y < 0.0 || (double) vector2.y > 1.0))
     return;
   float num1 = float.MaxValue;
   Ray ray = new Ray();
   if ((UnityEngine.Object) this.eventCamera != (UnityEngine.Object) null)
     ray = this.eventCamera.ScreenPointToRay((Vector3) eventData.position);
   if (this.canvas.renderMode != RenderMode.ScreenSpaceOverlay && this.blockingObjects != GraphicRaycaster.BlockingObjects.None)
   {
     float num2 = 100f;
     if ((UnityEngine.Object) this.eventCamera != (UnityEngine.Object) null)
       num2 = this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane;
     RaycastHit hitInfo;
     if ((this.blockingObjects == GraphicRaycaster.BlockingObjects.ThreeD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All) && Physics.Raycast(ray, out hitInfo, num2, (int) this.m_BlockingMask))
       num1 = hitInfo.distance;
     if (this.blockingObjects == GraphicRaycaster.BlockingObjects.TwoD || this.blockingObjects == GraphicRaycaster.BlockingObjects.All)
     {
       RaycastHit2D raycastHit2D = Physics2D.Raycast((Vector2) ray.origin, (Vector2) ray.direction, num2, (int) this.m_BlockingMask);
       if ((UnityEngine.Object) raycastHit2D.collider != (UnityEngine.Object) null)
         num1 = raycastHit2D.fraction * num2;
     }
   }
   this.m_RaycastResults.Clear();
   GraphicRaycaster.Raycast(this.canvas, this.eventCamera, eventData.position, this.m_RaycastResults);
   for (int index = 0; index < this.m_RaycastResults.Count; ++index)
   {
     GameObject gameObject = this.m_RaycastResults[index].gameObject;
     bool flag = true;
     if (this.ignoreReversedGraphics)
       flag = !((UnityEngine.Object) this.eventCamera == (UnityEngine.Object) null) ? (double) Vector3.Dot(this.eventCamera.transform.rotation * Vector3.forward, gameObject.transform.rotation * Vector3.forward) > 0.0 : (double) Vector3.Dot(Vector3.forward, gameObject.transform.rotation * Vector3.forward) > 0.0;
     if (flag)
     {
       float num2;
       if ((UnityEngine.Object) this.eventCamera == (UnityEngine.Object) null || this.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
       {
         num2 = 0.0f;
       }
       else
       {
         Transform transform = gameObject.transform;
         Vector3 forward = transform.forward;
         num2 = Vector3.Dot(forward, transform.position - ray.origin) / Vector3.Dot(forward, ray.direction);
         if ((double) num2 < 0.0)
           continue;
       }
       if ((double) num2 < (double) num1)
       {
         RaycastResult raycastResult = new RaycastResult() { gameObject = gameObject, module = (BaseRaycaster) this, distance = num2, screenPosition = eventData.position, index = (float) resultAppendList.Count, depth = this.m_RaycastResults[index].depth, sortingLayer = this.canvas.sortingLayerID, sortingOrder = this.canvas.sortingOrder };
         resultAppendList.Add(raycastResult);
       }
     }
   }
 }
Esempio n. 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TouchHit"/> struct from a UI raycast.
 /// </summary>
 /// <param name="value"> UI raycast value. </param>
 public TouchHit(RaycastResult value) :
     this(value.gameObject.transform)
 {
     raycastResult = value;
     type = TouchHitType.HitUI;
 }
Esempio n. 52
0
        public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            if (canvas == null)
                return;

            // Convert to view space
            Vector2 pos;
            if (eventCamera == null)
                pos = new Vector2(eventData.position.x / Screen.width, eventData.position.y / Screen.height);
            else
                pos = eventCamera.ScreenToViewportPoint(eventData.position);

            // If it's outside the camera's viewport, do nothing
            if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
                return;

            float hitDistance = float.MaxValue;

            if (canvas.renderMode != RenderMode.ScreenSpaceOverlay && blockingObjects != BlockingObjects.None)
            {
                var ray = eventCamera.ScreenPointToRay(eventData.position);
                float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics.RaycastAll(ray, dist, m_BlockingMask);

                    if (hits.Length > 0 && hits[0].distance < hitDistance)
                    {
                        hitDistance = hits[0].distance;
                    }
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    var hits = Physics2D.GetRayIntersectionAll(ray, dist, m_BlockingMask);

                    if (hits.Length > 0 && hits[0].fraction * dist < hitDistance)
                    {
                        hitDistance = hits[0].fraction * dist;
                    }
                }
            }

            m_RaycastResults.Clear();
            Raycast(canvas, eventCamera, eventData.position, m_RaycastResults);

            for (var index = 0; index < m_RaycastResults.Count; index++)
            {
                var go = m_RaycastResults[index].gameObject;
                bool appendGraphic = true;

                if (ignoreReversedGraphics)
                {
                    if (eventCamera == null)
                    {
                        // If we dont have a camera we know that we should always be facing forward
                        var dir = go.transform.rotation * Vector3.forward;
                        appendGraphic = Vector3.Dot(Vector3.forward, dir) > 0;
                    }
                    else
                    {
                        // If we have a camera compare the direction against the cameras forward.
                        var cameraFoward = eventCamera.transform.rotation * Vector3.forward;
                        var dir = go.transform.rotation * Vector3.forward;
                        appendGraphic = Vector3.Dot(cameraFoward, dir) > 0;
                    }
                }

                if (appendGraphic)
                {
                    float distance = (eventCamera == null || canvas.renderMode == RenderMode.ScreenSpaceOverlay) ? 0 : Vector3.Distance(eventCamera.transform.position, canvas.transform.position);

                    if (distance >= hitDistance)
                        continue;

                    var castResult = new RaycastResult
                    {
                        gameObject = go,
                        module = this,
                        distance = distance,
                        index = resultAppendList.Count,
                        depth = m_RaycastResults[index].depth
                    };
                    resultAppendList.Add(castResult);
                }
            }
        }
Esempio n. 53
0
    // use screen midpoint as locked pointer location, enabling look location to be the "mouse"
    private PointerEventData GetLookPointerEventData()
    {
        VRCursorController cursor= VRCursorController.GetInstance();
        Vector3 lookPosition = cursor.GetCursorRaycastPosition(RAYCAST_OFFSET);
        RaycastHit testRayResult = new RaycastHit();

        if (m_hoverData == null)
        {
            m_hoverData = new PointerEventData(eventSystem);
        }

        m_hoverData.Reset();
        m_hoverData.delta = Vector2.zero;
        m_hoverData.position = lookPosition;
        m_hoverData.scrollDelta = Vector2.zero;

        Vector3 lookDirection = cursor.GetCursorRaycastDirection();
        Ray testRay = new Ray(lookPosition, lookDirection);

        RaycastResult raycastResult = new RaycastResult();
        raycastResult.Clear();

        if (Physics.Raycast(testRay, out testRayResult, RAYCAST_OFFSET+10.0f, UI_COLLISION_LAYER_MASK))
        {
            raycastResult.gameObject = testRayResult.collider.gameObject;
            raycastResult.depth = 0;
            raycastResult.distance = testRayResult.distance;
        }

        m_hoverData.pointerCurrentRaycast = raycastResult;

        if (m_hoverData.pointerCurrentRaycast.gameObject != null)
        {
            m_guiRaycastHit = true;
        }
        else
        {
            m_guiRaycastHit = false;
        }

        return m_hoverData;
    }
Esempio n. 54
0
 void ProcessRayCastResult(RaycastResult rayCastResult) {
     Debug.Log(string.Format("rayCast hit: {0}", rayCastResult));
     if(rayCastResult.gameObject != null && rayCastResult.gameObject.Equals(mMenuBackground)) {
         StartGame();
     }
 }
Esempio n. 55
0
        public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
        {
            if (canvas == null)
                return;

            // Convert to view space
            Vector2 pos;
            if (eventCamera == null)
                pos = new Vector2(eventData.position.x / Screen.width, eventData.position.y / Screen.height);
            else
                pos = eventCamera.ScreenToViewportPoint(eventData.position);

            // If it's outside the camera's viewport, do nothing
            if (pos.x < 0f || pos.x > 1f || pos.y < 0f || pos.y > 1f)
                return;

            float hitDistance = float.MaxValue;

            Ray ray = new Ray();

            if (eventCamera != null)
                ray = eventCamera.ScreenPointToRay(eventData.position);

            if (canvas.renderMode != RenderMode.ScreenSpaceOverlay && blockingObjects != BlockingObjects.None)
            {
                float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

                if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
                {
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, dist, m_BlockingMask))
                    {
                        hitDistance = hit.distance;
                    }
                }

                if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
                {
                    RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, dist, m_BlockingMask);

                    if (hit.collider != null)
                    {
                        hitDistance = hit.fraction * dist;
                    }
                }
            }

            m_RaycastResults.Clear();
            Raycast(canvas, eventCamera, eventData.position, m_RaycastResults);

            for (var index = 0; index < m_RaycastResults.Count; index++)
            {
                var go = m_RaycastResults[index].gameObject;
                bool appendGraphic = true;

                if (ignoreReversedGraphics)
                {
                    if (eventCamera == null)
                    {
                        // If we dont have a camera we know that we should always be facing forward
                        var dir = go.transform.rotation * Vector3.forward;
                        appendGraphic = Vector3.Dot(Vector3.forward, dir) > 0;
                    }
                    else
                    {
                        // If we have a camera compare the direction against the cameras forward.
                        var cameraFoward = eventCamera.transform.rotation * Vector3.forward;
                        var dir = go.transform.rotation * Vector3.forward;
                        appendGraphic = Vector3.Dot(cameraFoward, dir) > 0;
                    }
                }

                if (appendGraphic)
                {
                    float distance = 0;

                    if (eventCamera == null || canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                        distance = 0;
                    else
                    {
                        // http://geomalgorithms.com/a06-_intersect-2.html
                        distance = (Vector3.Dot(go.transform.forward, go.transform.position - ray.origin) / Vector3.Dot(go.transform.forward, ray.direction));

                        // Check to see if the go is behind the camera.
                        if (distance < 0)
                            continue;
                    }

                    if (distance >= hitDistance)
                        continue;

                    var castResult = new RaycastResult
                    {
                        gameObject = go,
                        module = this,
                        distance = distance,
                        index = resultAppendList.Count,
                        depth = m_RaycastResults[index].depth,
                        sortingLayer =  canvas.sortingLayerID,
                        sortingOrder = canvas.sortingOrder
                    };
                    resultAppendList.Add(castResult);
                }
            }
        }
  public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList) {
    if (eventCamera == null) {
      return;
    }

    if (!IsPointerAvailable()) {
      return;
    }

    Ray ray = GetRay();
    float dist = eventCamera.farClipPlane - eventCamera.nearClipPlane;

    RaycastHit[] hits = Physics.RaycastAll(ray, dist, finalEventMask);

    if (hits.Length > 1) {
      System.Array.Sort(hits, (r1, r2) => r1.distance.CompareTo(r2.distance));
    }

    if (hits.Length != 0) {
      for (int b = 0, bmax = hits.Length; b < bmax; ++b) {
        RaycastResult result = new RaycastResult
          {
            gameObject = hits[b].collider.gameObject,
            module = this,
            distance = hits[b].distance,
            worldPosition = hits[b].point,
            worldNormal = hits[b].normal,
            screenPosition = eventData.position,
            index = resultAppendList.Count,
            sortingLayer = 0,
            sortingOrder = 0
          };
        resultAppendList.Add(result);
      }
    }
  }
Esempio n. 57
0
 private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs)
 {
     if (lhs.module != rhs.module)
     {
         if (((lhs.module.eventCamera != null) && (rhs.module.eventCamera != null)) && (lhs.module.eventCamera.depth != rhs.module.eventCamera.depth))
         {
             if (lhs.module.eventCamera.depth < rhs.module.eventCamera.depth)
             {
                 return 1;
             }
             if (lhs.module.eventCamera.depth == rhs.module.eventCamera.depth)
             {
                 return 0;
             }
             return -1;
         }
         if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority)
         {
             return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority);
         }
         if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority)
         {
             return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority);
         }
     }
     if (lhs.sortingLayer != rhs.sortingLayer)
     {
         int layerValueFromID = SortingLayer.GetLayerValueFromID(rhs.sortingLayer);
         int num2 = SortingLayer.GetLayerValueFromID(lhs.sortingLayer);
         return layerValueFromID.CompareTo(num2);
     }
     if (lhs.sortingOrder != rhs.sortingOrder)
     {
         return rhs.sortingOrder.CompareTo(lhs.sortingOrder);
     }
     if (lhs.depth != rhs.depth)
     {
         return rhs.depth.CompareTo(lhs.depth);
     }
     if (lhs.distance != rhs.distance)
     {
         return lhs.distance.CompareTo(rhs.distance);
     }
     return lhs.index.CompareTo(rhs.index);
 }
        protected new PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released)
        {
            PointerEventData pointerData;
            var created = GetPointerData(input.fingerId, out pointerData, true);

            pointerData.Reset();

            pressed = created || (input.phase == TouchPhase.Began);
            released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended);

            //Added
            if (Switch.Phase[input.fingerId] == 1)
            {
                released = true;
                pressed = false;
                Switch.Phase[input.fingerId] = 2;
            }
            else if (Switch.Phase[input.fingerId] == 2)
            {
                Switch.Phase[input.fingerId] = 3;
                released = false;
                pressed = true;
            }
            //End added

            if (created)
                pointerData.position = input.position;

            if (pressed)
                pointerData.delta = Vector2.zero;
            else
                pointerData.delta = input.position - pointerData.position;

            pointerData.position = input.position;

            pointerData.button = PointerEventData.InputButton.Left;

            Debug.Log(input.fingerId);

            if (Switch.Phase[input.fingerId] == 3)
            {
                Debug.Log("HERE");
                Switch.Phase[input.fingerId] = 0;
                RaycastResult result = new RaycastResult();
                result.gameObject = Switch.GameObject[input.fingerId];
                m_RaycastResultCache.Add(result);
                Switch.GameObject[input.fingerId] = null;
            }
            else
            {
                eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
            }

            var raycast = FindFirstRaycast(m_RaycastResultCache);
            pointerData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();
            return pointerData;
        }
 public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
 {
   if ((UnityEngine.Object) this.eventCamera == (UnityEngine.Object) null)
     return;
   RaycastHit[] array = Physics.RaycastAll(this.eventCamera.ScreenPointToRay((Vector3) eventData.position), this.eventCamera.farClipPlane - this.eventCamera.nearClipPlane, this.finalEventMask);
   if (array.Length > 1)
     Array.Sort<RaycastHit>(array, (Comparison<RaycastHit>) ((r1, r2) => r1.distance.CompareTo(r2.distance)));
   if (array.Length == 0)
     return;
   int index = 0;
   for (int length = array.Length; index < length; ++index)
   {
     RaycastResult raycastResult = new RaycastResult() { gameObject = array[index].collider.gameObject, module = (BaseRaycaster) this, distance = array[index].distance, worldPosition = array[index].point, worldNormal = array[index].normal, screenPosition = eventData.position, index = (float) resultAppendList.Count, sortingLayer = 0, sortingOrder = 0 };
     resultAppendList.Add(raycastResult);
   }
 }
Esempio n. 60
0
        private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs)
        {
            if (lhs.module != rhs.module)
            {
                if (lhs.module.eventCamera != null && rhs.module.eventCamera != null && lhs.module.eventCamera.depth != rhs.module.eventCamera.depth)
                {
                    // need to reverse the standard compareTo
                    if (lhs.module.eventCamera.depth < rhs.module.eventCamera.depth)
                        return 1;
                    if (lhs.module.eventCamera.depth == rhs.module.eventCamera.depth)
                        return 0;

                    return -1;
                }

                if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority)
                    return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority);

                if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority)
                    return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority);
            }

            if (lhs.sortingLayer != rhs.sortingLayer)
                return rhs.sortingLayer.CompareTo(lhs.sortingLayer);

            if (lhs.sortingOrder != rhs.sortingOrder)
                return rhs.sortingOrder.CompareTo(lhs.sortingOrder);

            if (lhs.depth != rhs.depth)
                return rhs.depth.CompareTo(lhs.depth);

            if (lhs.distance != rhs.distance)
                return lhs.distance.CompareTo(rhs.distance);

            return lhs.index.CompareTo(rhs.index);
        }