Exemplo n.º 1
0
    protected virtual void Start()
    {
        for (int i = 0; i < m_startingHarvesterCount; ++i)
        {
            Unit harvester = m_building.spawnUnit(eUnitType.Harvester);
            addUnit(harvester);

            HarvesterStateHandler harvesterStateHandler = harvester.GetComponent <HarvesterStateHandler>();
            Assert.IsNotNull(harvesterStateHandler);
            harvesterStateHandler.switchToState(eHarvesterState.SetBoidSpawner, m_boidSpawner);
            harvesterStateHandler.switchToState(eHarvesterState.TargetAvailableBoid);
        }
    }
Exemplo n.º 2
0
    public void handleSelectedUnits(Vector3 position)
    {
        //Handle selected building
        Selection buildingSelection = m_building.GetComponent <Selection>();

        Assert.IsNotNull(buildingSelection);
        if (buildingSelection.isSelected())
        {
            m_building.setWayPoint(position);
        }
        //Handle units
        else
        {
            Selection boidSpawnerSelection = m_boidSpawner.GetComponent <Selection>();
            Assert.IsNotNull(boidSpawnerSelection);
            if (boidSpawnerSelection.contains(position))
            {
                foreach (Unit unit in m_units)
                {
                    Selection unitSelection = unit.gameObject.GetComponent <Selection>();
                    Assert.IsNotNull(unitSelection);
                    HarvesterStateHandler harvesterStateHandler = unit.GetComponent <HarvesterStateHandler>();

                    if (unitSelection.isSelected() && harvesterStateHandler)
                    {
                        harvesterStateHandler.switchToState(eHarvesterState.SetBoidSpawner, m_boidSpawner);
                        harvesterStateHandler.switchToState(eHarvesterState.TargetAvailableBoid);
                    }
                }
            }
            else if (buildingSelection.contains(position))
            {
                foreach (Unit unit in m_units)
                {
                    Selection unitSelection = unit.gameObject.GetComponent <Selection>();
                    Assert.IsNotNull(unitSelection);
                    HarvesterStateHandler harvesterStateHandler = unit.GetComponent <HarvesterStateHandler>();
                    if (unitSelection.isSelected() && harvesterStateHandler)
                    {
                        harvesterStateHandler.switchToState(eHarvesterState.SetDestinationResourceBuilding, null);
                    }
                }
            }
            else
            {
                foreach (Unit unit in m_units)
                {
                    Selection unitSelection = unit.gameObject.GetComponent <Selection>();
                    Assert.IsNotNull(unitSelection);
                    if (!unitSelection.isSelected())
                    {
                        continue;
                    }

                    UnitStateHandler unitStateHandler = unit.GetComponent <UnitStateHandler>();
                    Assert.IsNotNull(unitStateHandler);

                    if (m_attackMoveNextSelection)
                    {
                        unitStateHandler.switchToState(eUnitState.SetAttackDestination, Utilities.INVALID_ID, position);
                    }
                    else
                    {
                        unitStateHandler.switchToState(eUnitState.SetDestination, Utilities.INVALID_ID, position);
                    }
                }
            }
        }
    }