示例#1
0
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            if ((placeState == PlaceStateType.Wall) || (placeState == PlaceStateType.Tower))
            {
                Vector2    screenPos = Input.mousePosition;
                Vector3    worldPos  = mainCam.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 0));
                RaycastHit hitInfo;
                Ray        ray = mainCam.ScreenPointToRay(screenPos);
                if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, floorMask))
                {
                    if (placeState == PlaceStateType.Wall)
                    {
                        field.BuildAt(FieldManager.buildType.Wall, hitInfo.point);
                    }
                    if (placeState == PlaceStateType.Tower)
                    {
                        field.BuildAt(FieldManager.buildType.Tower, hitInfo.point);
                    }
                }
            }
            else if (placeState == PlaceStateType.Demolish)
            {
                Vector2    screenPos = Input.mousePosition;
                Vector3    worldPos  = mainCam.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 0));
                RaycastHit hitInfo;
                Ray        ray = mainCam.ScreenPointToRay(screenPos);
                if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, structureMask))
                {
                    field.BuildAt(FieldManager.buildType.Demolish, hitInfo.point);
                }
            }
        }
#else
        if (Input.touchCount > 0)
        {
            curTouch = Input.GetTouch(0);
            Vector2    screenPos = curTouch.position;
            Vector3    worldPos  = arCam.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, 0));
            RaycastHit hitInfo;
            Ray        ray = arCam.ScreenPointToRay(screenPos);
            if ((placeState == PlaceStateType.Wall) || (placeState == PlaceStateType.Tower))
            {
                if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, floorMask))
                {
                    if (placeState == PlaceStateType.Wall)
                    {
                        field.BuildAt(FieldManager.buildType.Wall, hitInfo.point);
                    }
                    if (placeState == PlaceStateType.Tower)
                    {
                        field.BuildAt(FieldManager.buildType.Tower, hitInfo.point);
                    }
                }
            }
            else if (placeState == PlaceStateType.Demolish)
            {
                if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, structureMask))
                {
                    field.BuildAt(FieldManager.buildType.Demolish, hitInfo.point);
                }
            }
        }
#endif
    }