Beispiel #1
0
        public void OnDragStarted(Vector2 point)
        {
            var tower = GetComponent <Tower>();

            if (tower != null && tower.OccupiedByEnemy)
            {
                return;
            }

            _dragArrow = UILevelControlsManager.Instance.GetControl <UIDragArrow>(UILevelControlsManager.LevelControl.DragArrow);
            if (UILevelControlsManager.Instance.IsSomeControlShown)
            {
                UILevelControlsManager.Instance.Clear();
            }

            var ownerBuilding = GetComponent <Building>();

            if (ownerBuilding != null && ownerBuilding.SoldiersCount <= 0)
            {
                _dragArrow.End();
                _dragArrow = null;
            }
            else
            {
                _dragArrow.Show(transform);
            }
        }
Beispiel #2
0
        public void OnDragEnded(Vector2 point)
        {
            if (_dragArrow != null)
            {
                int hits = Physics2D.RaycastNonAlloc(Camera.main.ScreenToWorldPoint(point),
                                                     Vector2.zero, results, Mathf.Infinity, dragEndFilter);

                if (hits > 0)
                {
                    var target = results[hits - 1].transform.gameObject;
                    if (target != null && target.GetInstanceID() != gameObject.GetInstanceID())
                    {
                        building = GetComponent <Building>();

                        targetTower = target.GetComponent <Tower>();
                        if (targetTower != null)
                        {
                            if (targetTower.OccupiedByEnemy)
                            {
                                if (building.SoldiersCount == 1)
                                {
                                    building.RemoveLastSoldier().FreedOccupiedTower(targetTower.GetComponent <OccupiedByEnemy>());
                                }
                                else
                                {
                                    var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(
                                        UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                    control.Show(building);
                                    control.GoButtonClickedEvent += OnGoButtonClicked;
                                    control.HiddenEvent          += OnControlHidden;
                                }
                                _dragArrow.End();
                                _dragArrow = null;
                                return;
                            }
                        }

                        targetBuilding = target.GetComponent <Building>();
                        if (targetBuilding != null)
                        {
                            if (targetBuilding.SoldiersCount >= targetBuilding.MaxSoldiersCount)
                            {
                                _dragArrow.End();
                                _dragArrow = null;
                                return;
                            }

                            if (building.SoldiersCount == 1)
                            {
                                targetBuilding.AddSoldier(building.RemoveLastSoldier());
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building, targetBuilding);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetWizard = target.GetComponent <Wizard>();
                        if (targetWizard != null)
                        {
                            if (building.SoldiersCount == 1)
                            {
                                building.UnloadLastSoldier().AttackWizard(targetWizard);
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetFood = target.GetComponent <Food>();
                        if (targetFood != null && !targetFood.SoldierAssigned)
                        {
                            if (building.SoldiersCount == 1)
                            {
                                building.UnloadLastSoldier().TakeFood(targetFood);
                            }
                            else
                            {
                                var control = UILevelControlsManager.Instance.GetControl <UISoldierChoiceMultiple>(
                                    UILevelControlsManager.LevelControl.SoldierChoiceMultiple);
                                control.Show(building);
                                control.GoButtonClickedEvent += OnGoButtonClicked;
                                control.HiddenEvent          += OnControlHidden;
                            }
                        }

                        targetTrapPlace = target.GetComponent <TrapPlace>();
                        if (targetTrapPlace != null && !targetTrapPlace.IsBusy)
                        {
                            var control = UILevelControlsManager.Instance.GetControl <UITrapChoiceClouds>(
                                UILevelControlsManager.LevelControl.TrapChoice);
                            control.Show(point, targetTrapPlace);
                            control.TrapChosenEvent += OnTrapChosen;
                            control.HiddenEvent     += OnControlHidden;
                        }
                    }
                }

                _dragArrow.End();
                _dragArrow = null;
            }
        }