Beispiel #1
0
        public void Show(Vector2 point, TrapPlace trapPlace)
        {
            // if (isShown)
            //  return;
            //
            // isShown = true;
            this.point     = point;
            this.trapPlace = trapPlace;

            Vector3 position = Camera.main.WorldToScreenPoint(trapPlace.transform.position);

            _transform.position = UICamera.ScreenToWorldPoint(position);

            _transform.localScale = Vector3.zero;
            LeanTween.scale(gameObject, Vector3.one, showAnimationDuration).setOnComplete(ActivateSlots);

            // LeanTween.delayedCall(scaleTime, ActivateSlots);

            Show();
        }
Beispiel #2
0
        public void SetTrap(TrapPlace trapPlace, GameObject trapPrefab)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            if (CurrentlyInBuilding)
            {
                building.UnloadSoldier(this);
            }
            else
            {
                StopMoving();
            }

            this.trapPlace  = trapPlace;
            this.trapPrefab = trapPrefab;

            _moveByTransform.AssignTransform(trapPlace.transform);
            ArrivedDestinationEvent += PutTrapInPlace;
        }
Beispiel #3
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;
            }
        }