/// <summary> /// finds the closest tree, sends the workers to it, and destroyes this tree /// </summary> public void findNearestTree() { mapGrid.removeTree(gridOn); PathFinderManager pathFinderManager = player.getSpawner().getPathFinderManager().GetComponent <PathFinderManager>(); nextTree = pathFinderManager.FindNearestGrid(gridOn, mapGrid.getTrees(), mapGrid); List <Unit> unitsC = new List <Unit>(units); for (int i = 0; i < unitsC.Count; i++) { nextTree.getBlockingObject().GetComponent <Tree>().addUnit(unitsC[i]); if (unitsC[i].GetComponent <Worker>().isLumberjack()) { unitsC[i].GetComponent <Worker>().setWorkGrid(nextTree, "wood"); if (unitsC[i].GetComponent <Worker>().getWorkPhase() == 1 && !unitsC[i].GetComponent <Worker>().isWoodFull()) { unitsC[i].GetComponent <Worker>().startWorking(false); unitsC[i].GetComponent <Worker>().startWorking(true); } } } destroyTree(); }
/// <summary> /// finds the closest iron and sends current workers to it, and destroys itself /// </summary> public void findNearestIronOre() { mapGrid.removeIronOres(gridOn); PathFinderManager pathFinderManager = player.getSpawner().getPathFinderManager().GetComponent <PathFinderManager>(); Grid nextIronOre = pathFinderManager.FindNearestGrid(gridOn, mapGrid.getIronOres(), mapGrid); List <Unit> unitsC = new List <Unit>(units); for (int i = 0; i < unitsC.Count; i++) { nextIronOre.getBlockingObject().GetComponent <IronOre>().addUnit(unitsC[i]); if (unitsC[i].GetComponent <Worker>().isIronOreMiner()) { unitsC[i].GetComponent <Worker>().setWorkGrid(nextIronOre, "ironOre"); if (unitsC[i].GetComponent <Worker>().getWorkPhase() == 1 && !unitsC[i].GetComponent <Worker>().isIronOreFull()) { unitsC[i].GetComponent <Worker>().startWorking(false); unitsC[i].GetComponent <Worker>().startWorking(true); } } } destroyIronOre(); }
public void onStart() { guiDisplayer = canvas.GetComponent <GUIDisplayer>(); player = GetComponent <Player>(); mapGrid = player.getMapGrid(); pathFinderManager = player.getSpawner().getPathFinderManager(); }
/// <summary> /// spawns a pathfindermanager /// </summary> /// <returns></returns> public GameObject SpawnPathFinderManager() { GameObject go = Instantiate(pathFinderManager); pathFinderManagerMain = go.GetComponent <PathFinderManager>(); pathFinderManagerMain.setMapGrid(player.getMapGrid()); return(go); }
public SearchState(AIController aiController) { this.aiController = aiController; playerActions = aiController.GetComponent<PlayerActions>(); pathManager = aiController.GetComponent<PathFinderManager>(); ChooseNewTarget(); lastPositionTarget = target; }
public void Start() { animator = transform.gameObject.GetComponentInChildren <Animator>(); triggerCollider = transform.gameObject.GetComponentInChildren <BoxCollider2D>(); sr = transform.gameObject.GetComponentInChildren <SpriteRenderer>(); defaultColor = sr.color; animationEventHandler = GetComponentInChildren <AnimationEventHandler>(); pathFinderManager = player.getSpawner().getPathFinderManager(); }
public static PathFinderManager GetInstance() { if (!instance) { var gameObject = new GameObject("PathFinderManager"); instance = gameObject.AddComponent <PathFinderManager>(); } return(instance); }
public void Start() { animator = transform.gameObject.GetComponentInChildren <Animator>(); triggerCollider = transform.gameObject.GetComponentInChildren <BoxCollider2D>(); lastScan = Time.time; animationEventHandler = GetComponentInChildren <AnimationEventHandler>(); enemyManager = player.getEnemyManager(); sr = GetComponentInChildren <SpriteRenderer>(); pathFinderManager = player.getSpawner().getPathFinderManager(); maxhealth = health; }
private void Awake() { if (Instance == null) { Instance = this; } else if (Instance != this) { Debug.LogError(gameObject + " was a second Instance! and was destroyed for it!"); Destroy(gameObject); } pathFinding = GetComponent <PathFinderManager>(); pathRequestQueue = new Queue <PathRequest>(); }
public void FindPath() { var startTile = TileHelper.GetTile(findPathStart); var endTile = TileHelper.GetTile(findPathEnd); PathFinderManager.StartPathFinding(true, startTile, endTile, (outPath) => { path = outPath; TileHelper.SetTilesColorToEnvironment(); float strengthPerPath = 1.0f / outPath.Count; int cnt = 0; foreach (var path in path) { path.color = new Color(strengthPerPath * ++cnt, 0, 0, 1); } TileHelper.ReDrawHexMesh(); }); }
private void OnEnable() { pathFinder = PathFinderManager.GetInstance(); pathFinder.StartPathFindingEvent += OnStartPathFindingEvent; destinationUITransform.gameObject.SetActive(false); }
private void Awake() { instance = this; }
public void Awake() { manager = this; pathFinder = GetComponent <PathFinder>(); }