示例#1
0
 // Use this for initialization
 void Start()
 {
     grid             = GameGrid.instance;
     unit             = GetComponent <Unit>();
     aStar            = GetComponent <AStar>();
     unitStateHandler = GetComponent <UnitStateHandler>();
     GetComponent <InputHandler>().onRequestingAttackLogic += RequestingAttackLogic;
     unitStateHandler.onPlanningAttack += InitiateAttackTargetting;
 }
示例#2
0
 void Awake()
 {
     selectionImage   = transform.Find("Selected Image").GetComponent <Image>();
     unitStateHandler = GetComponentInParent <UnitStateHandler>();
     UnitStateHandler.onUnitSelected     += ShowSelection;
     UnitStateHandler.onUnitPastPlanning += HideSelection;
     // HideSelection();
     this.transform.Find("Selected Image").GetComponent <Image>().enabled = false;
 }
示例#3
0
 void Start()
 {
     sceneManager              = SceneManager.instance;
     grid                      = GameGrid.instance;
     gizmothing                = DebugGizmo.instance;
     unitStateHandler          = GetComponent <UnitStateHandler>();
     Debug.Assert(aStar        = GetComponent <AStar>());
     Debug.Assert(unit         = GetComponent <Unit>());
     Debug.Assert(inputHandler = GetComponent <InputHandler>());
     target                    = FindObjectOfType <TargetPosition>().transform;
 }
示例#4
0
 private void Start()
 {
     unitStateHandler = GetComponent <UnitStateHandler>();
     inputHandler     = GetComponent <InputHandler>();
     aStar            = GetComponent <AStar>();
     grid             = GameGrid.instance;
     inputHandler.onRequestingMovementLogic  += MovementLogic;
     unitStateHandler.onUnitPlanningMovement += DisplayMoves;
     unitStateHandler.onMovementFinished     += ResetNodesInRange;
     unitStateHandler.onUnitMoving           += ResetNodesInRange;
     unit = GetComponent <Unit>();
 }
示例#5
0
 void Start()
 {
     grid                           = GameGrid.instance;
     requestManager                 = PathRequestManager.instance;
     gizmothing                     = DebugGizmo.instance;
     unit                           = GetComponent <Unit>();
     target                         = FindObjectOfType <TargetPosition>().transform;
     Debug.Assert(aStar             = GetComponent <AStar>());
     unitMovement                   = GetComponent <UnitMovement>();
     inputHandler                   = GetComponent <InputHandler>();
     unitStateHandler               = GetComponent <UnitStateHandler>();
     unitStateHandler.onUnitMoving += StartMovementPathLogic;
 }
示例#6
0
    public Unit spawnUnit(eUnitType unitType)
    {
        Vector3 spawnPosition;

        if (m_wayPointClone.transform.position != transform.position)
        {
            spawnPosition = Utilities.getClosestPositionOutsideAABB(m_selectionComponent.getAABB(),
                                                                    m_wayPointClone.transform.position, transform.position, m_spawnOffSet);
        }
        else
        {
            spawnPosition = Utilities.getRandomPositionOutsideAABB(m_selectionComponent.getAABB(),
                                                                   transform.position, m_spawnOffSet);
        }

        Unit newUnit = null;

        if (unitType == eUnitType.Harvester)
        {
            newUnit = Instantiate(m_harvesterToSpawn, spawnPosition, Quaternion.identity);
            Harvester harvester = newUnit.GetComponent <Harvester>();
            Assert.IsNotNull(harvester);
            harvester.m_buildingToReturnResource = this;
        }
        else if (unitType == eUnitType.Attacker)
        {
            newUnit = Instantiate(m_tankToSpawn, spawnPosition, Quaternion.identity);
        }

        if (m_wayPointClone.transform.position != transform.position)
        {
            Assert.IsTrue(m_wayPointClone.activeSelf);
            UnitStateHandler stateHandlerComponent = newUnit.GetComponent <UnitStateHandler>();
            Assert.IsNotNull(stateHandlerComponent);

            stateHandlerComponent.switchToState(eUnitState.SetDestination, Utilities.INVALID_ID, m_wayPointClone.transform.position);
        }

        return(newUnit);
    }
示例#7
0
    public void targetEnemyAtPosition(Vector3 position)
    {
        Unit enemy = GameManager.Instance.getUnit(position);

        if (!enemy)
        {
            return;
        }

        foreach (Unit tank in m_units)
        {
            Selection selectionComponent = tank.gameObject.GetComponent <Selection>();
            Assert.IsNotNull(selectionComponent);

            if (selectionComponent.isSelected())
            {
                UnitStateHandler unitStateHandler = tank.gameObject.GetComponent <UnitStateHandler>();
                Assert.IsNotNull(unitStateHandler);

                unitStateHandler.switchToState(eUnitState.MovingToNewPosition, enemy.getID(), enemy.transform.position);
            }
        }
    }
示例#8
0
 private void Awake()
 {
     m_unit = GetComponent <Unit>();
     Assert.IsNotNull(m_unit);
     m_unitState = GetComponent <UnitStateHandler>();
 }
示例#9
0
文件: UnitTimer.cs 项目: kgc00/GMTKJ
 // Use this for initialization
 void Start()
 {
     unitStateHandler = GetComponent <UnitStateHandler>();
     unitStateHandler.onMovementFinished += AddTimeToTimerMovement;
     unitStateHandler.onAttackFinished   += AddTimeToTimerAttack;
 }
示例#10
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);
                    }
                }
            }
        }
    }