void OnDrawGizmosSelected() { if (Application.isPlaying) { var surroundings = Environment.Sense(coord); Gizmos.color = Color.white; if (surroundings.nearestFoodSource != null) { Gizmos.DrawLine(transform.position, surroundings.nearestFoodSource.transform.position); } if (surroundings.nearestWaterTile != Coord.invalid) { Gizmos.DrawLine(transform.position, Environment.tileCentres[surroundings.nearestWaterTile.x, surroundings.nearestWaterTile.y]); } if (currentAction == CreatureAction.GoingToFood) { var path = EnvironmentUtility.GetPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y); Gizmos.color = Color.black; for (int i = 0; i < path.Length; i++) { Gizmos.DrawSphere(Environment.tileCentres[path[i].x, path[i].y], .2f); } } } }
public void CreatePath(Coord target) { // Create new path if current is not already going to target if (path == null) { path = EnvironmentUtility.GetPath(coord.x, coord.y, target.x, target.y); pathIndex = 0; } else { bool a = (pathIndex >= path.Length), b = false, c = false; if (path.Length != 0) { b = (path[path.Length - 1] != target); if (pathIndex != 0) { c = (path[pathIndex - 1] != moveTargetCoord); } } if (a || b || c) { path = EnvironmentUtility.GetPath(coord.x, coord.y, target.x, target.y); pathIndex = 0; } } }
protected void CreatePath(Coord target) { // Create new path if current is not already going to target if (path == null || pathIndex >= path.Length || (path[path.Length - 1] != target || path[pathIndex - 1] != moveTargetCoord)) { path = EnvironmentUtility.GetPath(coord.x, coord.y, target.x, target.y); pathIndex = 0; } }
protected virtual void OnDrawGizmosSelected() { if (Application.isPlaying) { var surroundings = Environment.Sense(coord); Gizmos.color = Color.white; Gizmos.DrawWireSphere(transform.position, Animal.maxViewDistance); if (surroundings.nearestFoodSource != null) { Gizmos.DrawLine(transform.position, surroundings.nearestFoodSource.transform.position); } if (surroundings.nearestWaterTile != Coord.invalid) { Gizmos.DrawLine(transform.position, Environment.tileCentres[surroundings.nearestWaterTile.x, surroundings.nearestWaterTile.y]); } if (currentAction == CreatureAction.Exploring) { Gizmos.color = Color.red; Gizmos.DrawSphere(Environment.tileCentres[moveFromCoord.x, moveFromCoord.y], .2f); Gizmos.color = Color.green; Gizmos.DrawSphere(Environment.tileCentres[moveTargetCoord.x, moveTargetCoord.y], .2f); } if (currentAction == CreatureAction.GoingToMate) { Gizmos.color = Color.black; if (path != null) { for (int i = 0; i < path.Length; i++) { Gizmos.DrawSphere(Environment.tileCentres[path[i].x, path[i].y], .2f); } } } if (currentAction == CreatureAction.GoingToFood) { var path = EnvironmentUtility.GetPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y); Gizmos.color = Color.black; if (path != null) { for (int i = 0; i < path.Length; i++) { Gizmos.DrawSphere(Environment.tileCentres[path[i].x, path[i].y], .2f); } } } } }
// Start is called before the first frame update // Update is called once per frame protected override void OnDrawGizmosSelected() { if (Application.isPlaying) { Gizmos.color = Color.yellow; Gizmos.DrawLine(transform.position, Environment.tileCentres[buildingPlace.x, buildingPlace.y]); if (currentAction == CreatureAction.WorkingAtFarm) { var path = EnvironmentUtility.GetPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y); Gizmos.color = Color.black; if (path != null) { for (int i = 0; i < path.Length; i++) { Gizmos.DrawSphere(Environment.tileCentres[path[i].x, path[i].y], .2f); } } } } base.OnDrawGizmosSelected(); }