2022년 9월 27일 화요일

unity mouse on ui

 


public bool IsPointerOverUIElement()
    {
        return IsPointerOverUIElement(GetEventSystemRaycastResults());
    }
    private bool IsPointerOverUIElement(List<RaycastResult> eventSystemRaysastResults)
    {
        for (int index = 0; index < eventSystemRaysastResults.Count; index++)
        {
            RaycastResult curRaysastResult = eventSystemRaysastResults[index];
            if (curRaysastResult.gameObject.layer == 5)
                return true;
        }
        return false;
    }
    static List<RaycastResult> GetEventSystemRaycastResults()
    {
        PointerEventData eventData = new PointerEventData(EventSystem.current);
        eventData.position = Input.mousePosition;
        List<RaycastResult> raysastResults = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventData, raysastResults);
        return raysastResults;
    }

    void Update()
    {

        if (!PlayerCam.gameObject.activeSelf)
            return;

        if (IsPointerOverUIElement())
        {
            HidePointObject();
            return;
        }


클릭했을때 체크라서 땟을때(MouseUP)는 또 변수가 하나 더 필요하다



 if (IsPointerOverUIElement())
        {
            isOnUi = true;
            HidePointObject();
            return;
        }

       


        if (Input.GetMouseButton(0))
        {
            ///현재 부딛힌 객체 확인하기
            isOnUi = false;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {


                //Debug.Log("tag:" + hit.transform.tag);
                if (hit.transform.tag == "ClickableFloor")
                {
                    ShowPointObject();
                    if (PointObject.activeSelf)
                    {
                        PointObject.transform.position = new Vector3(hit.point.x, Player.transform.position.y+1.2f, hit.point.z); ;
                    }
                }
                else
                {
                    HidePointObject();
                }
            }
        }



        if (Input.GetMouseButtonUp(0) && !isOnUi)
        {

            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
            {
                if (hit.transform.tag == "ClickableFloor")
                {
                    isOnUi=false;
                    PlayerSmoothMove(new Vector3(PointObject.transform.position.x, Player.transform.position.y, PointObject.transform.position.z));
                }
            }
        }







댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...