Ejemplo n.º 1
0
 //not compatible with PointNBuild mode
 void OnMouseEnter()
 {
     if (UIUtilities.IsCursorOnUI())
     {
         return;
     }
     if (AbilityManager.InTargetSelectMode())
     {
         return;
     }
     BuildManager.ShowIndicator(this);
 }
Ejemplo n.º 2
0
        // Update is called once per frame
        void Update()
        {
            if (GameControl.GetGameState() == _GameState.Over)
            {
                return;
            }

            if (FPSControl.IsOn())
            {
                return;
            }

            if (abilityTargetSelecting)
            {
                return;
            }

                        #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8
            if (Input.touchCount == 1)
            {
                Touch touch = Input.touches[0];

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

                if (!UseDragNDrop() && !UIBuildButton.isOn)
                {
                    BuildManager.SetIndicator(touch.position);
                }

                if (touch.phase == TouchPhase.Began)
                {
                    OnTouchCursorDown(touch.position);
                }
            }
            else
            {
                UpdateMouse();
            }
                        #else
            UpdateMouse();
                        #endif
        }
Ejemplo n.º 3
0
        void UpdateMouse()
        {
            if (UIUtilities.IsCursorOnUI())
            {
                return;
            }

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

            if (Input.GetMouseButtonDown(0))
            {
                OnTouchCursorDown(Input.mousePosition);
            }
            if (Input.GetMouseButtonDown(1))
            {
                OnRightClickCursorDown(Input.mousePosition);
            }
        }
Ejemplo n.º 4
0
        public IEnumerator DragNDropRoutine()
        {
            GameControl.SelectTower(this);
            yield return(null);


#if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY
            _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)
                {
                    string exception = BuildManager.BuildTower(srcTower);
                    if (exception != "")
                    {
                        GameControl.DisplayMessage(exception);
                    }
                    else
                    {
                        BuildManager.ClearBuildPoint();
                    }
                    break;
                }

                yield return(null);
            }

            //if(status==_TileStatus.Available){
            //	string exception=BuildManager.BuildTower(srcTower);
            //	if(exception!="") GameControl.DisplayMessage(exception);
            //}
            //else{
            //	GameControl.DisplayMessage("cancelled");
            //	BuildManager.ClearBuildPoint();
            //}

            GameControl.ClearSelectedTower();
            thisObj.SetActive(false);
#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)
                    {
                        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);
            }
#endif

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