示例#1
0
    /// <summary>
    /// Updates the various UI elements of the Prepare screen
    /// </summary>
    public void UpdateScreen()
    {
        string name = levelDropDown.options[levelDropDown.value].text;
        //



        Graphics    g  = Graphics.Instance();
        GameManager gm = GameManager.Instance();

        Database.LevelInfo info = Database.Instance().QueryLevelInfo(name);


        // *** Set the map image
        BaseActor ba = gm.gameSpace.transform.Find("Prepare").Find("AtlasLayer").Find("atlasMap").gameObject.GetComponent <BaseActor>();

        ba.AssignAtlasSprite("icon_level_" + name);
        //
        // *** This is "fallback" code in case the Sprite Atlas breaks again.
        Image im = mapPanel.transform.Find("MapImage").GetComponent <Image>();

        UnityEngine.Sprite o = g.GetSprite("Layout_" + name);
        im.sprite = o;


        // *** Get all the turrets in the selected level...
        Dictionary <Structure.StructureTypes, int> turretsInLevel = new Dictionary <Structure.StructureTypes, int>();

        foreach (Structure.StructureTypes Q in info.turrets)
        {
            if (!turretsInLevel.ContainsKey(Q))
            {
                turretsInLevel.Add(Q, 0);
            }
            //
            turretsInLevel[Q]++;
        }

        // *** Get all the creeps in the selected level...
        List <Creep.CreepTypes> creepsInLevel = new List <Creep.CreepTypes>();

        foreach (Database.SpawnSequenceRunner a in info.scenario.spawns)
        {
            foreach (Database.SpawnSequenceData b in a.sequence.spawns)
            {
                creepsInLevel.Add(b.type);
            }
        }
        //
        //
        GameObject go;

        // *** Fill the creep panel
        for (int n = 0; n < creepIcons.Length; n++)
        {
            if (n < creepsInLevel.Count)
            {
                creepIcons[n].SetActive(true);
                //
                Image i = creepIcons[n].GetComponent <Image>();
                i.sprite = g.GetSprite("icon_creep_" + creepsInLevel[n].ToString().ToLower());
            }
            else
            {
                creepIcons[n].SetActive(false);
                continue;
            }
        }
        // ??? <-- (if higher than 16): "And more..."


        // *** Fill the turret panel
        int count = 0;

        foreach (KeyValuePair <Structure.StructureTypes, int> Q in turretsInLevel)
        {
            go = turretIcons[count];
            go.SetActive(true);
            //
            //
            // *** Turret's image
            go.transform.Find("_TurretIcon").gameObject.GetComponent <Image>().sprite = g.GetSprite("icon_turret_" + Q.Key.ToString().ToLower());

            // *** Turret's count
            go.transform.Find("_TurretCount").gameObject.GetComponent <Text>().text = "x" + (Q.Value).ToString();


            count++;
        }
        // *** Disable the rest of the icons
        for (int i = count; i < turretIcons.Length; i++)
        {
            turretIcons[i].SetActive(false);
        }
    }