public void AddButton(Ship ship)
    {
        var ui = Instantiate <ShipSelectionUI>(buttonPrefab, buttonParent);

        ui.gameObject.SetActive(true);
        ui.Ship      = ship;
        ui.OnSelect += () =>
        {
            OnShipSelected?.Invoke(ship);
            // Can be immediatelly removed -> should not be selected again
        };
        lookup.Add(ship, ui);
    }
示例#2
0
        private TreeViewItem GetTreeForShip(ShipSchema shipSchema)
        {
            var shipParent = new TreeViewItem();

            shipParent.Header     = shipSchema.Name;
            shipParent.GotFocus  += (sender, arg) => OnShipSelected?.Invoke(sender, shipSchema);
            shipParent.IsExpanded = true;
            var reactorsParent  = GetTreeForSchemas(shipSchema.Reactors.Select(item => item), "Reactors", OnDeleteReactor);
            var enginesParent   = GetTreeForSchemas(shipSchema.Engines.Select(item => item), "Engines", OnDeleteEngine);
            var shieldsParent   = GetTreeForSchemas(shipSchema.Shields.Select(item => item), "Shields", OnDeleteShield);
            var weaponsParent   = GetTreeForSchemas(shipSchema.Weapons.Select(item => item), "Weapons", OnDeleteWeapon);
            var crewdecksParent = GetTreeForSchemas(shipSchema.CrewDecks.Select(item => item), "CrewDecks", OnDeleteCrewDeck);

            shipParent.Items.Add(reactorsParent);
            shipParent.Items.Add(shieldsParent);
            shipParent.Items.Add(weaponsParent);
            shipParent.Items.Add(enginesParent);
            shipParent.Items.Add(crewdecksParent);
            return(shipParent);
        }