Example #1
0
        public void Update()
        {
            Vector3 worldPos = Vector3.zero;

            if (Input.GetMouseButtonDown(1))
            {
                flag = !flag;
                _cameraManager.IsMoved = flag;
            }
            if (Input.GetMouseButtonDown(0))
            {
                _touchStart = _cameraManager.GetWorldPosition(Input.mousePosition, 0) - Vector3.one / 2;
            }
            if (Input.GetMouseButton(0))
            {
                worldPos = _cameraManager.GetWorldPosition(Input.mousePosition, 0) - Vector3.one / 2;
            }
            switch (BuildState)
            {
            case BUILD_STATE.Idle:
            {
                _uiManager.HidePopup <BuildingInfoPopup>();
                int i = IsHitedBuilding(new Vector2(_touchStart.x, _touchStart.z));
                if (i != -1)            //Клик на здание
                {
                    ChooseBuilding(i);
                }
                break;
            }

            case BUILD_STATE.BuildingChosen:
            {
                bool canBeInstalled = false;
                _cameraManager.IsMoved = true;
                int id = IsHitedBuilding(new Vector2(_touchStart.x, _touchStart.z));
                canBeInstalled = IsCanBuildOnPoint(BuildingViews[_chosenBuldingId].scriptObj, BuildingViews[_chosenBuldingId].PointOnPlane);
                if (canBeInstalled)
                {
                    PlaceChoosenBuilding();
                    if (id == -1)         //Клик на незанятое пространство
                    {
                        _chosenBuldingId = -1;
                        BuildState       = BUILD_STATE.Idle;
                        break;
                    }
                    else if (id != _chosenBuldingId)         //Клик на другое здание
                    {
                        ChooseBuilding(id);
                    }
                }
                if (Input.GetMouseButton(0) && !Input.GetMouseButtonDown(0))
                {
                    Debug.Log("Tuta");
                    BuildState = BUILD_STATE.MovingBuilding;
                }
                break;
            }

            case BUILD_STATE.MovingBuilding:
            {
                _cameraManager.IsMoved = false;
                if (Input.GetMouseButton(0))
                {
                    worldPos = _cameraManager.GetWorldPosition(Input.mousePosition, 0) - Vector3.one / 2;
                    MoveBuilding(new Vector2(worldPos.x, worldPos.z));
                }
                else         //Отпустили кнопку
                {
                    BuildState = BUILD_STATE.BuildingChosen;
                }

                break;
            }
            }
        }