// 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; }
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; }
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; }
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>(); }
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; }
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); }
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); } } }
private void Awake() { m_unit = GetComponent <Unit>(); Assert.IsNotNull(m_unit); m_unitState = GetComponent <UnitStateHandler>(); }
// Use this for initialization void Start() { unitStateHandler = GetComponent <UnitStateHandler>(); unitStateHandler.onMovementFinished += AddTimeToTimerMovement; unitStateHandler.onAttackFinished += AddTimeToTimerAttack; }
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); } } } } }