예제 #1
0
    public override void spawnTeam()
    {
        controllerID = 1;
        List <unitScript> team = new List <unitScript>();

        EnemyType[] types = map.getEnemyTypes();
        Dictionary <Vector2, int> spawnData = map.getSpawnData();

        foreach (Vector2 position in spawnData.Keys)
        {
            if (spawnData[position] >= 2)            // If greater than 2 then spawn enemy
            {
                EnemyType type = types[spawnData[position]];

                GameObject newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
                unitScript unit    = newUnit.GetComponent <unitScript>();

                unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
                unit.gameObject.layer = 8;
                unit.setPosition((int)position.x, (int)position.y);
                unit.setOwner(1);
                AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();
                ai.healthThreshold = type.healthThreshold;
                team.Add(unit);
                unitsInGame.Add(unit);
            }
        }
        playerUnitList = team.ToArray();
    }
    public override void spawnTeam()
    {
        Vector2[] spawns = map.getSpawnPoints();



        XmlDocument xml = new XmlDocument();

        xml.LoadXml(playerData.text);

        XmlNode data = xml.SelectSingleNode("data");

        playerUnitList = new unitScript[data.ChildNodes.Count];

        for (int i = 0; i < data.ChildNodes.Count; i++)
        {
            if (LevelData.party[i] != 1)
            {
                playerUnitList[i] = null;
                continue;
            }

            XmlNode    current        = data.ChildNodes[i];
            string     unitName       = current.SelectSingleNode("name").InnerText;
            string     unitClass      = current.SelectSingleNode("class").InnerText;
            int        health         = int.Parse(current.SelectSingleNode("health").InnerText);
            int        speed          = int.Parse(current.SelectSingleNode("speed").InnerText);
            int        skill          = int.Parse(current.SelectSingleNode("skill").InnerText);
            int        strength       = int.Parse(current.SelectSingleNode("strength").InnerText);
            int        smarts         = int.Parse(current.SelectSingleNode("smarts").InnerText);
            string     portraitString = current.SelectSingleNode("portait").InnerText;
            string     source         = current.SelectSingleNode("source").InnerText;
            GameObject newUnit        = (GameObject)Instantiate(Resources.Load(source), transform, true);
            unitScript unit           = newUnit.GetComponent <unitScript>();

            XmlNode       weaponNode  = current.SelectSingleNode("weapons");
            List <string> unitWeapons = new List <string>();
            foreach (XmlNode weapon in weaponNode.ChildNodes)
            {
                unitWeapons.Add(weapon.InnerText);
            }

            unit.setData(unitName, unitClass, health, speed, skill, strength, smarts, portraitString, unitWeapons);
            unit.gameObject.layer = 8;

            unit.setPosition(Mathf.FloorToInt(spawns[i].x), Mathf.FloorToInt(spawns[i].y));
            playerUnitList[i] = unit;
            unitsInGame.Add(unit);
        }
        gui.GetComponent <GUIController>().setPlayerTeam(playerUnitList);
    }
예제 #3
0
    public void addUnit(int typeIndex, int x, int y)
    {
        EnemyType[] types   = map.getEnemyTypes();
        EnemyType   type    = types[typeIndex];
        GameObject  newUnit = (GameObject)Instantiate(Resources.Load(type.source), transform, true);
        unitScript  unit    = newUnit.GetComponent <unitScript>();

        unit.setData(type.unitName, type.unitClass, type.health, type.speed, type.skill, type.strength, type.smarts, "", new List <string>(type.weapons));
        unit.gameObject.layer = 8;
        unit.setPosition(x, y);
        unit.setOwner(1);
        AIUnitController ai = unit.gameObject.AddComponent <AIUnitController>();

        ai.healthThreshold = type.healthThreshold;
        List <unitScript> newList = new List <unitScript>(playerUnitList);

        newList.Add(unit);
        this.playerUnitList = newList.ToArray();
        unitsInGame.Add(unit);
    }