Ejemplo n.º 1
0
    public void SpawnUnitFromNetwork(int unitType, int unitIndex, int factionIndexMod)
    {
        UnitType  type = (UnitType)(unitType - 1);
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).unitIndex == unitIndex)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }
        GameObject newUnit = CreateNewUnit(factionIndexMod, site, type);

        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 2
0
    public void SpawnAStarFromNetwork(int unitType, int unitIndex)
    {
        UnitType  type = (UnitType)unitType;
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).unitIndex == unitIndex)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        GameObject newUnit = Instantiate(aStarUnits[unitType - aStarIndexMod], site.transform.position, Quaternion.identity);

        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 3
0
    public void SpawnUnitWithButton(int unitType, int factionIndexMod)
    {
        UnitType  type = (UnitType)(unitType);
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        Debug.Log(unitType.ToString() + " + " + factionIndexMod.ToString());
        GameObject newUnit = CreateNewUnit(factionIndexMod, site, type);

        //GameObject newUnit = Instantiate(aStarUnits[unitType - factionIndexMod], site.transform.position, Quaternion.identity);
        type           = (UnitType)(unitType + factionIndexMod);
        site.spawnUnit = true;

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }
Ejemplo n.º 4
0
    public void SpawniFactionWithButton(int unitType)
    {
        UnitType  type = (UnitType)unitType;
        BuildSite site = null;

        foreach (Unit b in GameObject.Find("CellGrid").GetComponent <CellGrid>().Units)
        {
            if (b is BuildSite && (b as BuildSite).selected)
            {
                site = b as BuildSite;
                break;
            }
        }

        if (site == null)
        {
            return;
        }

        GameObject newUnit = Instantiate(iFactionUnits[unitType - iFactIndexMod], site.transform.position, Quaternion.identity);

        site.spawnUnit             = true;
        newUnit.transform.position = new Vector3(newUnit.transform.position.x, newUnit.transform.position.y, -1.0f);

        if (!site.Cell.IsTaken && site.spawnUnit && site.selected && site.CanSpawnUnit(newUnit.GetComponent <Unit>()))
        {
            site.hasAlreadySpawned = true;
            site.SpawnUnit(newUnit.GetComponent <Unit>());
            UnitUpdate update = new UnitUpdate();
            update.newLocationX = site.transform.position.x;
            update.newLocationY = site.transform.position.y;
            update.command      = UnitUpdateCommand.SPAWN;
            update.moving       = site.unitIndex;
            update.type         = type;
            NetManager.SendData(TagIndex.Controller, TagIndex.PlayerUpdate, update);
        }
        else
        {
            Destroy(newUnit.gameObject);
            newUnit = null;
        }
        site.spawnUnit = false;
    }