示例#1
0
        void Build(UnitTowerData towerData)
        {
            if (towerData.UpgradePath.Count == 0)
            {
                Log.Error("Cannot build Tower '{0}' as it has no data inside its upgrade path. It needs at least one upgrade.", towerData.Name);
                return;
            }

            if (resources.Value < towerData.UpgradePath[0].Cost)
            {
                ui.DisplayWarning = AssetLibrary.Strings.BuildNotEnoughResources;
            }
            else
            {
                ui.DisplayMessage = AssetLibrary.Strings.BuildSuccessful;

                // Tell the construction point to place a tower. This is where the tower is instantiated and initialized.
                selectedConstructionPoint.PlaceTower(towerData);

                ghost.Hide();

                resources.Remove(towerData.UpgradePath[0].Cost);

                buildMenuController.HideMenu();

                // Display a hitmarker UI showing how many resources have been deducted for building this tower.
                UiHud.CreateHitMarker(selectedConstructionPoint.Position, (text) =>
                {
                    text.Label.ApplyStyle(AssetLibrary.TextStyles.HudWorldSpaceText);
                    text.Label.Color   = Color.Red;
                    text.Label.Content = "-" + towerData.UpgradePath[0].Cost.ToString();
                });
            }
        }
示例#2
0
 /// <summary>
 /// Creates an instance of a Tower based on the specified UnitTowerData and places it at this Construction Point.
 /// </summary>
 /// <param name="unitTowerData"></param>
 public void PlaceTower(UnitTowerData unitTowerData)
 {
     if (Tower == null && !Occupied)
     {
         Tower = Factory.CreateUnit(unitTowerData) as Tower;
         Tower.Place(Position);
         Occupied = true;
         OnUnitPlaced?.Invoke(Tower);
     }
 }
示例#3
0
        public void Setup(Resources resources)
        {
            this.resources = resources;

            // Create UI
            ui = SceneObject.Instantiate <UiInventory>(UiHud.Canvas) as UiInventory;
            ui.UpgradeMenu.Upgrade += Upgrade;
            ui.UpgradeMenu.Sell    += Sell;
            ui.BuildMenu.Build     += Build;

            // Set UI so it renders last
            ui.SetAsFirstSibling();

            // Create the 'ghost' version of the Unit to be placed. It is the same as the Unit but with a transparent material.
            ghostUnitData = AssetLibrary.Data.Towers.TowerBasic;
            ghost         = Factory.CreateGhost(ghostUnitData);

            // Create the controllers that handle menu logic.
            upgradeMenuController = new TowerUpgradeMenuController(ui.UpgradeMenu);
            buildMenuController   = new TowerBuildMenuController(ui.BuildMenu);

            // Create the controller that handles mouse interaction.
            mouseController                      = new MouseController();
            mouseController.NoCell              += MouseController_OnNoCell;
            mouseController.EnterOccupiedCell   += MouseController_OnEnterOccupiedCell;
            mouseController.EnterUnoccupiedCell += Mouse_OnEnterUnoccupiedCell;

            // Prevent cells from being highlighted if the mouse is inside a piece of UI.
            mouseController.CanSelect = new Func <bool>(() =>
            {
                if (ui.UpgradeMenu.Active)
                {
                    return(!Mouse.CursorInside(ui.UpgradeMenu));
                }
                else if (ui.BuildMenu.Active)
                {
                    return(!Mouse.CursorInside(ui.BuildMenu));
                }
                return(true);
            });

            // Create the controller that handles mouse input
            inputController                   = new InputController(mouseController);
            inputController.Select           += InputController_Select;
            inputController.SelectionCleared += InputController_SelectionCleared;
        }