Exemplo n.º 1
0
    LandProperty ConfirmTarget()
    {
#if UNITY_EDITOR
        if (EventSystem.current.IsPointerOverGameObject() == true)
        {
            return(null);
        }
#elif UNITY_IPHONE || UNITY_ANDROID
        if (Input.touchCount != 1)
        {
            return(null);
        }
        if (Input.touchCount == 1)
        {
            if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                return(null);
            }
        }
#endif

#if UNITY_EDITOR
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);        //从摄像机发出到点击坐标的射线
#elif UNITY_IPHONE || UNITY_ANDROID
        Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position); //从摄像机发出到点击坐标的射线
#endif
        RaycastHit hitInfo;
        LayerMask  mask = 1 << LayerMask.NameToLayer("TuDi");

        if (Physics.Raycast(ray, out hitInfo, 100000f, mask.value))
        {
#if UNITY_EDITOR
#elif UNITY_IPHONE || UNITY_ANDROID
            if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                MovingTime += Time.deltaTime;
                if (MovingTime > 0.1f)
                {
                    BenginTarget = null;
                    EndTarget    = null;
                }
                return(null);
            }
#endif


#if UNITY_EDITOR
            if (Input.GetMouseButtonDown(0))
#elif UNITY_IPHONE || UNITY_ANDROID
            if (Input.GetTouch(0).phase == TouchPhase.Began)
#endif
            {
                EndTarget  = null;
                MovingTime = 0;
                if (hitInfo.collider.gameObject.CompareTag("baoxiang"))
                {
                    Baoxiang.Invoke();
                }
                if (hitInfo.collider.gameObject.CompareTag("jinju"))
                {
                    LandProperty hitobj = ChoseParent(hitInfo.collider.gameObject);
                    BenginTarget = hitobj;
                }
                else
                {
                    BenginTarget = null;
                }
            }
#if UNITY_EDITOR
            if (Input.GetMouseButtonUp(0))
#elif UNITY_IPHONE || UNITY_ANDROID
            if (Input.GetTouch(0).phase == TouchPhase.Ended)
#endif
            {
                if (hitInfo.collider.gameObject.CompareTag("jinju"))
                {
                    LandProperty hitobj = ChoseParent(hitInfo.collider.gameObject);
                    EndTarget = hitobj;
                }
                else
                {
                    EndTarget = null;
                }
            }
        }
        else
        {
            EndTarget    = null;
            BenginTarget = null;
#if UNITY_EDITOR
            if (Input.GetMouseButtonDown(0))
#elif UNITY_IPHONE || UNITY_ANDROID
            if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
#endif
            {
#if UNITY_EDITOR
                if (!EventSystem.current.IsPointerOverGameObject() == true)
#elif UNITY_IPHONE || UNITY_ANDROID
                if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#endif
                {
                    Action.ResetAction();

                    ClickReset();
                }
            }
            return(null);
        }



        if (BenginTarget == EndTarget && (BenginTarget != null && EndTarget != null))
        {
            return(EndTarget);
        }
        else
        {
#if UNITY_EDITOR
            if (Input.GetMouseButtonDown(0))
#elif UNITY_IPHONE || UNITY_ANDROID
            if ((Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began))
#endif
            {
#if UNITY_EDITOR
                if (!EventSystem.current.IsPointerOverGameObject() == true)
#elif UNITY_IPHONE || UNITY_ANDROID
                if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#endif
                { ClickReset(); }
            }

            return(null);
        }
    }