private void CloseMenu(MageAssignableBuilding building)
 {
     UIManager.DestroyTowerMenuCloser();
     OpenMenu.AttachedBuilding.HideRangeObject();
     OpenMenu.AttachedBuilding.StopHighlighting();
     building.MenuOpen = false;
     building.Menu     = null;
     OpenMenu          = null;
     building.InsideMage.Data.ProfileButton.GetComponent <Toggle>().isOn = false;
 }
        public void SpawnMenu(MageAssignableBuilding building)
        {
            if (OpenMenu)
            {
                OpenMenu.AttachedBuilding.MenuOpen = false;
                OpenMenu.AttachedBuilding.Menu     = null;
                OpenMenu = null;
            }
            BuildingMenu newMenu = Instantiate(MenuPrefab);

            newMenu.transform.SetParent(transform, false);
            var screenSize = gameObject.GetComponent <RectTransform>().sizeDelta;
            var posX       = Camera.main.WorldToViewportPoint(building.transform.position).x *screenSize.x - screenSize.x / 2;
            var posY       = Camera.main.WorldToViewportPoint(building.transform.position).y *screenSize.y - screenSize.y / 2 + 80;

            newMenu.transform.localPosition = new Vector3(posX, posY, 0);
            newMenu.AttachedBuilding        = building;
            newMenu.AttachedBuilding.Menu   = newMenu;
            newMenu.SpawnButtons(building, UIManager);
            OpenMenu          = newMenu;
            building.MenuOpen = true;
            UIManager.CreateTowerMenuCloser(delegate {
                RaycastHit towerHit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out towerHit))
                {
                    if (towerHit.collider.tag == "Tower" || towerHit.collider.tag == "Shrine")
                    {
                        if (towerHit.collider.gameObject.GetComponent <MageAssignableBuilding>().InsideMage != null)
                        {
                            if (towerHit.collider.gameObject == building.gameObject)
                            {
                                CloseMenu(building);
                            }
                            else
                            {
                                building = towerHit.collider.gameObject.GetComponent <MageAssignableBuilding>();
                            }
                        }
                        else
                        {
                            CloseMenu(building);
                        }
                    }
                    else
                    {
                        CloseMenu(building);
                    }
                }
            });
        }
예제 #3
0
        // Use this for initialization
        public void SpawnButtons(MageAssignableBuilding building, UIManager uiManager)
        {
            _uiManager       = uiManager;
            AttachedBuilding = building;
            _buttonList      = new QkButton[building.options.Length];

            for (var i = 0; i < _buttonList.Length; i++)
            {
                var newButton = Instantiate(ButtonPrefab);

                newButton.transform.SetParent(transform, false);
                var theta = (2 * Mathf.PI / building.options.Length) * i;

                newButton.Init(theta, building.options[i]);

                _buttonList[i] = newButton;

                //First button is always close button!
                if (i == 0)
                {
                    newButton.GetButton().onClick.AddListener(
                        delegate {
                        CloseMenu();
                    }
                        );
                }
                //Third button always have cooldown
                if (i == 2)
                {
                    newButton.GetComponent <CoolDown>().enabled = true;
                    if (!AttachedBuilding.InsideMage.CanCast())
                    {
                        newButton.GetComponent <CoolDown>().Cooldown(ElementController.Instance.GetElementSkillCooldown(AttachedBuilding.InsideMage.Data.GetElement()), AttachedBuilding.InsideMage.CooldownStart);
                    }
                }
            }
            AttachedBuilding.DisplayRangeObject();
            AttachedBuilding.StartHighlighting();
        }