Exemplo n.º 1
0
    void GenerateUI(Player p)
    {
        GameObject        thisUI = p.Type == PlayerType.Battlebeard ? BattlebeardUI : StormshaperUI;
        List <UnitTypeUI> data   = getUnitTypeUI(p.Type);

        data.ForEach(ui => ui.Reset());         // maybe not necesarry?
        List <GameObject> children = new List <GameObject>();

        foreach (Transform child in thisUI.transform)
        {
            children.Add(child.gameObject);
        }
        children.ForEach(child => Destroy(child));

        data.Clear();
        List <Unit>     allUnits  = p.PlayerArmy.GetUnits();
        List <UnitType> unitTypes = new List <UnitType>();

        foreach (Unit unit in allUnits)
        {
            if (!unitTypes.Contains(unit.Type))
            {
                unitTypes.Add(unit.Type);
            }
        }
        foreach (UnitType t in unitTypes)
        {
            UnitTypeUI unitTypeUI = createUIForUnitType(thisUI, t, data);
            p.PlayerArmy.GetUnits(t).ForEach(u => unitTypeUI.AddUnit(u));
        }
    }
Exemplo n.º 2
0
    private void unitRemoved(Player p, Unit u, int i)
    {
        List <UnitTypeUI> data   = getUnitTypeUI(p.Type);
        UnitTypeUI        unitUI = data.Find(ui => (ui.GetType() == u.Type));

        if (unitUI != null)
        {
            //i = p.PlayerArmy.GetAllUnits().IndexOf(u);
            unitUI.RemoveUnit(i);
        }
    }
Exemplo n.º 3
0
    void unitUpdated(Player p, Unit u)
    {
        List <UnitTypeUI> data   = getUnitTypeUI(p.Type);
        UnitTypeUI        unitUI = data.Find(ui => (ui.GetType() == u.Type));

        if (unitUI != null)
        {
            int i = p.PlayerArmy.GetUnits(u.Type).IndexOf(u);
            unitUI.UpdateUnit(i, u);
        }
    }
Exemplo n.º 4
0
    UnitTypeUI createUIForUnitType(GameObject UI, UnitType t, List <UnitTypeUI> data)
    {
        GameObject o      = Instantiate(UnitsPrefab);
        UnitTypeUI unitUI = o.GetComponent <UnitTypeUI>();

        unitUI.Initialise(t);
        int index = ~data.BinarySearch(unitUI, comparator);

        o.transform.SetParent(UI.transform);
        // Make sure they show in order in the UI
        o.transform.SetSiblingIndex(index);
        o.transform.localScale = Vector3.one;
        data.Insert(index, unitUI);
        unitUI.OnClickUnit += _clickUnit;
        unitUI.Show();
        return(unitUI);
    }
Exemplo n.º 5
0
    private void unitAdded(Player p, Unit u)
    {
        List <UnitTypeUI> data   = getUnitTypeUI(p.Type);
        UnitTypeUI        unitUI = null;

        data.ForEach(ui => {
            if (ui.GetType() == u.Type)
            {
                unitUI = ui;
            }
        });

        if (unitUI == null)
        {
            GameObject thisUI = p.Type == PlayerType.Battlebeard ? BattlebeardUI : StormshaperUI;
            unitUI = createUIForUnitType(thisUI, u.Type, data);
        }
        unitUI.AddUnit(u);
    }