public void Clicked(BaseEventData baseEventData) { if (!preventClick) { //Debug.Log(nameof(Clicked)); PointerEventData ped = (PointerEventData)baseEventData; List <RaycastResult> result = new List <RaycastResult>(); trainRaycaster.Raycast(ped, result); //Debug.Log($"Hitted {result.Count}"); if (result.Count > 0) { RaycastResult firstHit = result[0]; var et = firstHit.gameObject.GetComponent <EventTrigger>(); et.OnPointerClick(ped); } } preventClick = false; }
private void EventsUI_() { //Check if the left Mouse button is clicked //if (Input.GetKey(KeyCode.Mouse0)) //{ //Set up the new Pointer Event //var m_Raycaster = GetComponent<Physics2DRaycaster>(); if (m_Raycaster == null || m_EventSystem == null) { Debug.Log("####### EventsU MAP ### m_Raycaster==null"); return; } m_PointerEventData = new PointerEventData(m_EventSystem); if (m_PointerEventData == null) { Debug.Log("####### EventsU MAP ### PointerEventData==null"); return; } //Set the Pointer Event Position to that of the mouse position //m_PointerEventData.position = Input.mousePosition; //cameraMap = Storage.PlayerController.CameraMap; //m_PointerEventData.position = cameraMap.ScreenToWorldPoint(Input.mousePosition); //Create a list of Raycast Results List <RaycastResult> results = new List <RaycastResult>(); //Raycast using the Graphics Raycaster and mouse click position m_Raycaster.Raycast(m_PointerEventData, results); //For every result returned, output the name of the GameObject on the Canvas hit by the Ray foreach (RaycastResult result in results) { //Storage.Events.ListLogAdd = "Event 4. MAP Raycaster event"; Debug.Log(">>>>>>>>>> Hit MAP Raycaster event ### " + result.gameObject.name); } //Debug.Log(">>>>>>>>>> Hit MAP ### Not result...."); //} }
public static int Raycast(IntPtr l) { int result; try { Physics2DRaycaster physics2DRaycaster = (Physics2DRaycaster)LuaObject.checkSelf(l); PointerEventData eventData; LuaObject.checkType <PointerEventData>(l, 2, out eventData); List <RaycastResult> resultAppendList; LuaObject.checkType <List <RaycastResult> >(l, 3, out resultAppendList); physics2DRaycaster.Raycast(eventData, resultAppendList); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
void IsInside()//获取鼠标位置下的物体列表 { GameObject raycaster = GameObject.Find("Main Camera"); PointerEventData pointerEventData = new PointerEventData(EventSystem.current); pointerEventData.position = Input.mousePosition; Physics2DRaycaster pr = raycaster.GetComponent <Physics2DRaycaster>(); List <RaycastResult> resultlist = new List <RaycastResult>(); pr.Raycast(pointerEventData, resultlist); if (resultlist.Count != 0) { Count = resultlist.Count; if (Count > 10) { Count = 10; } for (int i = 0; i < Count; ++i) { Targetlist[i] = resultlist[i].gameObject; } } }
private void Update() { pointerEventData.position = Input.mousePosition; raycasterUI.Raycast(pointerEventData, resultsUI); raycaster2D.Raycast(pointerEventData, results2D); if (results2D.Count > 0) { if (results2D[0].gameObject.CompareTag(tagMagnifier)) { SetCursorMagnifier(); } else if (results2D[0].gameObject.CompareTag(tagLeft)) { SetCursorLeft(); } else if (results2D[0].gameObject.CompareTag(tagRight)) { SetCursorRight(); } else if (results2D[0].gameObject.CompareTag(tagForward)) { SetCursorForward(); } else if (results2D[0].gameObject.CompareTag(tagBackward)) { SetCursorBackward(); } else if (results2D[0].gameObject.CompareTag(tagOpen)) { SetCursorOpen(); } else { SetCursorMain(); } } else { SetCursorMain(); } if (resultsUI.Count > 0) { if (resultsUI[0].gameObject.CompareTag(tagLeft)) { SetCursorLeft(); } else if (resultsUI[0].gameObject.CompareTag(tagRight)) { SetCursorRight(); } else if (resultsUI[0].gameObject.CompareTag(tagForward)) { SetCursorForward(); } else if (resultsUI[0].gameObject.CompareTag(tagBackward)) { SetCursorBackward(); } else if (resultsUI[0].gameObject.CompareTag(tagTake)) { SetCursorTake(); } else { SetCursorMain(); } } resultsUI.Clear(); results2D.Clear(); }