Ejemplo n.º 1
0
        void OnTouchCursorDown(Vector3 cursorPos)
        {
            UnitTower tower = GameControl.Select(cursorPos);

            if (tower != null)
            {
                SelectTower(tower);
                UIBuildButton.Hide();
            }
            else
            {
                if (selectedTower != null)
                {
                    ClearSelectedTower();
                    return;
                }

                if (!UseDragNDrop())
                {
                    if (BuildManager.CheckBuildPoint(cursorPos) == _TileStatus.Available)
                    {
                        UIBuildButton.Show();
                    }
                    else
                    {
                        UIBuildButton.Hide();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void OnCursorDown(Vector3 cursorPos)
        {
            UnitTower tower = GameControl.Select(cursorPos);

            GameControl.SelectTower(tower);

            if (tower != null)
            {
                if (!BuildManager.UseDragNDrop())
                {
                    UIBuildButton.Hide();
                }
                if (autoCenterCamera)
                {
                    CameraControl.SetPosition(tower.thisT.position);
                }

                UITowerView.Show(tower);
            }
            else
            {
                UITowerView.Hide();

                if (!BuildManager.UseDragNDrop())
                {
                    BuildInfo buildInfo = BuildManager.CheckBuildPoint(cursorPos);
                    UIBuildButton.Show(buildInfo);
                    if (buildInfo.status == _TileStatus.Available && autoCenterCamera)
                    {
                        CameraControl.SetPosition(buildInfo.position);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // Update is called once per frame
        void Update()
        {
            if (GameControl.GetGameState() == _GameState.Over)
            {
                return;
            }

            if (UIUtilities.IsCursorOnUI())
            {
                return;
            }

            if (!UseDragNDrop() && !UIBuildButton.isOn)
            {
                BuildManager.SetIndicator(Input.mousePosition);
            }

            if (Input.GetMouseButtonDown(0))
            {
                UnitTower tower = GameControl.Select(Input.mousePosition);

                if (tower != null)
                {
                    SelectTower(tower);
                    UIBuildButton.Hide();
                }
                else
                {
                    if (selectedTower != null)
                    {
                        ClearSelectedTower();
                        return;
                    }

                    if (!UseDragNDrop())
                    {
                        if (BuildManager.CheckBuildPoint(Input.mousePosition) == _TileStatus.Available)
                        {
                            UIBuildButton.Show();
                        }
                        else
                        {
                            UIBuildButton.Hide();
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public IEnumerator DragNDropRoutine(int pointerID = -1)
        {
            GameControl.SelectTower(this);
            yield return(null);

            Vector3 cursorPos = Vector3.zero;

            TDTK.OnDragNDrop(true);
            inDragNDropRoutine = true;

            while (inDragNDropRoutine)
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    break;
                }

                bool invalidCursor = false;

                if (pointerID < 0)
                {
                    cursorPos = Input.mousePosition;
                }
                else
                {
                    cursorPos = TDTK.GetTouchPosition(pointerID);
                }

                if (cursorPos.magnitude < 0)
                {
                    invalidCursor = true;
                }

                BuildInfo buildInfo = null;

                if (!invalidCursor)
                {
                    buildInfo = BuildManager.CheckBuildPoint(cursorPos, prefabID);

                    if (buildInfo.status == _TileStatus.NoPlatform)
                    {
                        Ray        ray = Camera.main.ScreenPointToRay(cursorPos);
                        RaycastHit hit;
                        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                        {
                            thisT.position = hit.point;
                        }
                        else
                        {
                            thisT.position = ray.GetPoint(30);                          //this there is no collier, randomly place it 30unit from camera
                        }
                    }
                    else
                    {
                        thisT.position = buildInfo.position;
                        thisT.rotation = buildInfo.platform.thisT.rotation;
                    }

                    IndicatorControl.SetBuildTileIndicator(buildInfo);
                }

                bool cursorOnUI = UI.IsCursorOnUI(pointerID);

                if (pointerID < 0)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        if (cursorOnUI)
                        {
                            break;
                        }
                        string exception = BuildManager._BuildTower(srcTower, buildInfo);
                        if (exception != "")
                        {
                            TDTK.OnGameMessage(exception);
                        }
                        break;
                    }
                    if (Input.GetMouseButtonDown(1))
                    {
                        break;
                    }
                }
                else
                {
                    if (TDTK.IsTouchEnding(pointerID))
                    {
                        if (cursorOnUI)
                        {
                            break;
                        }
                        string exception = BuildManager._BuildTower(srcTower, buildInfo);
                        if (exception != "")
                        {
                            TDTK.OnGameMessage(exception);
                        }
                        break;
                    }
                }

                yield return(null);
            }

            inDragNDropRoutine = false;

            TDTK.OnDragNDrop(false);
            IndicatorControl.SetDragNDropPhase(false);
            thisObj.SetActive(false);
        }
Ejemplo n.º 5
0
        public IEnumerator DragNDropRoutine()
        {
            GameControl.SelectTower(this);
            yield return(null);

#if (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY) && !UNITY_EDITOR
            _TileStatus status = _TileStatus.NoPlatform;
            while (Input.touchCount >= 1)
            {
                Vector3 pos = Input.touches[0].position;

                status = BuildManager.CheckBuildPoint(pos, -1, prefabID);

                if (status == _TileStatus.Available)
                {
                    BuildInfo buildInfo = BuildManager.GetBuildInfo();
                    thisT.position = buildInfo.position;
                    thisT.rotation = buildInfo.platform.thisT.rotation;
                }
                else
                {
                    Ray        ray = Camera.main.ScreenPointToRay(pos);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                    {
                        thisT.position = hit.point;
                    }
                    //this there is no collier, randomly place it 30unit from camera
                    else
                    {
                        thisT.position = ray.GetPoint(30);
                    }
                }

                if (Input.touches[0].phase == TouchPhase.Ended)
                {
                    //if current mouse point position is valid, build the tower
                    if (status == _TileStatus.Available)
                    {
                        bool exception = BuildManager.BuildTower(srcTower);
                        if (exception == false)
                        {
                            GameControl.DisplayMessage("Can't build tower");
                        }
                    }
                    else
                    {
                        BuildManager.ClearBuildPoint();
                    }
                    break;
                }

                yield return(null);
            }
            GameControl.ClearSelectedTower();
#else
            while (true)
            {
                Vector3     pos    = Input.mousePosition;
                _TileStatus status = BuildManager.CheckBuildPoint(pos, -1, prefabID);
                if (status == _TileStatus.Available)
                {
                    BuildInfo buildInfo = BuildManager.GetBuildInfo();
                    thisT.position = buildInfo.position;
                    thisT.rotation = buildInfo.platform.thisT.rotation;
                }
                else
                {
                    Ray        ray = Camera.main.ScreenPointToRay(pos);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                    {
                        thisT.position = hit.point;
                    }
                    //this there is no collier, randomly place it 30unit from camera
                    else
                    {
                        thisT.position = ray.GetPoint(30);
                    }
                }

                //left-click, build
                if (Input.GetMouseButtonDown(0) && !UIUtilities.IsCursorOnUI())
                {
                    //if current mouse point position is valid, build the tower
                    if (status == _TileStatus.Available)
                    {
                        bool exception = BuildManager.BuildTower(srcTower);
                        if (exception == false)
                        {
                            GameControl.DisplayMessage("Can't build tower");
                        }
                    }
                    else
                    {
                        BuildManager.ClearBuildPoint();
                    }
                    GameControl.ClearSelectedTower();
                    thisObj.SetActive(false);
                    break;
                }
                //right-click, cancel
                if (Input.GetMouseButtonDown(1) || GameControl.GetGameState() == _GameState.Over)
                {
                    GameControl.ClearSelectedTower();
                    BuildManager.ClearBuildPoint();
                    thisObj.SetActive(false);
                    break;
                }
                yield return(null);
            }
#endif
            thisObj.SetActive(false);
            thisT.position = new Vector3(0, 9999, 0);
            BuildManager.ShowPlatform(false);
        }
Ejemplo n.º 6
0
        public IEnumerator DragNDropRoutine()
        {
            GameControl.SelectTower(this);
            yield return(null);

            while (true)
            {
                Vector3 pos = Input.mousePosition;

                _TileStatus status = BuildManager.CheckBuildPoint(pos, -1, prefabID);

                if (status == _TileStatus.Available)
                {
                    BuildInfo buildInfo = BuildManager.GetBuildInfo();
                    thisT.position = buildInfo.position;
                    thisT.rotation = buildInfo.platform.thisT.rotation;
                }
                else
                {
                    Ray        ray = Camera.main.ScreenPointToRay(pos);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                    {
                        thisT.position = hit.point;
                    }
                    //this there is no collier, randomly place it 30unit from camera
                    else
                    {
                        thisT.position = ray.GetPoint(30);
                    }
                }


                //left-click, build
                if (Input.GetMouseButtonDown(0) && !UIUtilities.IsCursorOnUI())
                {
                    //if current mouse point position is valid, build the tower
                    if (status == _TileStatus.Available)
                    {
                        string exception = BuildManager.BuildTower(srcTower);
                        if (exception != "")
                        {
                            GameControl.DisplayMessage(exception);
                        }
                    }
                    else
                    {
                        BuildManager.ClearBuildPoint();
                    }
                    GameControl.ClearSelectedTower();
                    thisObj.SetActive(false);
                    break;
                }

                //right-click, cancel
                if (Input.GetMouseButtonDown(1) || GameControl.GetGameState() == _GameState.Over)
                {
                    GameControl.ClearSelectedTower();
                    BuildManager.ClearBuildPoint();
                    thisObj.SetActive(false);
                    break;
                }

                yield return(null);
            }

            thisT.position = new Vector3(0, 9999, 0);
        }