// adds a unit group(on retreat)
 public void addUnitGroup(UnitGroupScript group)
 {
     SavedUnitGroup newUnitGroup = new SavedUnitGroup();
     newUnitGroup.normalUpgrades = new List<string>();
     newUnitGroup.numUnits = group.unitsInBaseScripts.Count;
     unitGroupsSaved.Add (newUnitGroup);
 }
예제 #2
0
    // adds a unit group(on retreat)
    public void addUnitGroup(UnitGroupScript group)
    {
        SavedUnitGroup newUnitGroup = new SavedUnitGroup();

        newUnitGroup.normalUpgrades = new List <string>();
        newUnitGroup.numUnits       = group.unitsInBaseScripts.Count;
        unitGroupsSaved.Add(newUnitGroup);
    }
예제 #3
0
    // spawns a waiting unit group
    public void spawnUnitgroup(SavedUnitGroup group)
    {
        Vector3         position           = new Vector3(transform.position.x + 5.0f, transform.position.y, transform.position.z);
        GameObject      newgroup           = Instantiate(unitGroupPrefab, position, Quaternion.identity) as GameObject;
        UnitGroupScript newUnitGroupScript = newgroup.GetComponent <UnitGroupFriendlyScript>();

        GameObject        newUnit;
        List <UnitScript> listNewUnits = new List <UnitScript>();

        position = new Vector3(transform.position.x + 5.0f, transform.position.y, transform.position.z);
        for (int i = 0; i < group.numUnits; i++)
        {
            newUnit = Instantiate(unitPrefab, position, Quaternion.identity) as GameObject;
            newUnit.SetActive(false);
            UnitScript unitScript = newUnit.GetComponent <UnitScript>();
            unitScript.unitGroupScript = newUnitGroupScript;

            listNewUnits.Add(unitScript);
        }
        GameObject newUpgrade;
        Skill      newUpgradeSkill;

        if (group.normalUpgrades.Count > 0)
        {
            foreach (string upgrade in group.normalUpgrades)
            {
                newUpgrade      = Instantiate(upgradeManager.getUpgrade(upgrade), position, Quaternion.identity) as GameObject;
                newUpgradeSkill = newUpgrade.GetComponent <Skill>();
                if (newUpgradeSkill.skillType == 1)
                {
                    newUpgrade.SetActive(true);
                    newUpgradeSkill.unitGroupScript = newUnitGroupScript;
                    newUpgradeSkill.skillTarget     = newUnitGroupScript.gameObject;
                    newUpgrade.transform.parent     = newgroup.transform;
                }
                if (newUpgradeSkill.skillType == 0 && listNewUnits.Count > 0)
                {
                    newUpgradeSkill.unitScript  = listNewUnits[0];
                    newUpgrade.transform.parent = listNewUnits[0].transform;
                    newUpgrade.SetActive(true);
                    for (int i = 1; i < listNewUnits.Count; i++)
                    {
                        newUpgrade = Instantiate(upgradeManager.getUpgrade(upgrade), position, Quaternion.identity) as GameObject;
                        newUpgrade.SetActive(true);
                        newUpgradeSkill             = newUpgrade.GetComponent <Skill>();
                        newUpgradeSkill.unitScript  = listNewUnits[i];
                        newUpgradeSkill.skillTarget = listNewUnits[i].gameObject;
                        newUpgrade.transform.parent = listNewUnits[i].transform;
                    }
                }
            }
        }

        if (group.specialUpgrade != null)
        {
            newUpgrade      = Instantiate(upgradeManager.getUpgrade(group.specialUpgrade).gameObject, position, Quaternion.identity) as GameObject;
            newUpgradeSkill = newUpgrade.GetComponent <Skill>();
            if (newUpgradeSkill.skillType == 1)
            {
                newUpgrade.SetActive(true);
                newUpgradeSkill.unitGroupScript = newUnitGroupScript;
                newUpgradeSkill.skillTarget     = newUnitGroupScript.gameObject;
                newUpgrade.transform.parent     = newgroup.transform;
            }
            if (newUpgradeSkill.skillType == 0 && listNewUnits.Count > 0)
            {
                newUpgradeSkill.unitScript  = listNewUnits[0];
                newUpgrade.transform.parent = listNewUnits[0].transform;
                newUpgrade.SetActive(true);
                for (int i = 1; i < listNewUnits.Count; i++)
                {
                    newUpgrade = Instantiate(upgradeManager.getUpgrade(group.specialUpgrade), position, Quaternion.identity) as GameObject;
                    newUpgrade.SetActive(true);
                    newUpgradeSkill             = newUpgrade.GetComponent <Skill>();
                    newUpgradeSkill.unitScript  = listNewUnits[i];
                    newUpgradeSkill.skillTarget = listNewUnits[i].gameObject;
                    newUpgrade.transform.parent = listNewUnits[i].transform;
                }
            }
        }

        deleteUnitGroup(group);
        StartCoroutine(setListGroupUnitsActive(listNewUnits));
    }