private void Awake() { Instance = this; UtilClass.InitializeUtilClass(); grid = new GridXZ <GridObject>(StartTransform, Width, Height, CellSize, StartTransform.position, (GridXZ <GridObject> g, int x, int z) => new GridObject(g, x, z)); }
void Awake() { EventManager.instance.onModeChanged += ResetLastClickedTile; instance = this; gridWidth = MapSizeController.mapSize; gridHeight = MapSizeController.mapSize; grid = new GridXZ(gridWidth, gridHeight, cellSize, Vector3.zero); // Create ground visual float groundSizeX = gridWidth * cellSize; float groundSizeY = gridHeight * cellSize; ground = Instantiate(groundVisualPrefab, new Vector3(groundSizeX / 2, -0.5f, groundSizeY / 2), Quaternion.identity); ground.localScale = new Vector3(groundSizeX, 1, groundSizeY); selectedBuildingSO = null; currentBuildingRotation = BuildingTypeSO.Direction.Down; float spawnChance = 0.05f; // The spawning chance of the trees when the game starts for (int i = 0; i < gridWidth; i++) { for (int j = 0; j < gridHeight; j++) { float randFloat = Random.Range(0f, 1f); if (randFloat < spawnChance) { spawnTree(i, j); } } } }
public void Setup() { GameObject buildings = new GameObject(); GameObject empty = new GameObject(); GameObject help = new GameObject(); buildings.name = "Buildings"; gameManager = help.AddComponent <GameManager>(); eventManager = help.AddComponent <EventManager>(); timeManager = help.AddComponent <TimeManager>(); empty.AddComponent <Attraction>(); gameManager.testMode = true; grid = new GridXZ(1, 1, 3, Vector3.zero); wcObject = ScriptableObject.CreateInstance <BuildingTypeSO>(); wcObject.type = BuildingTypeSO.Type.Attraction; wcObject.capacity = 1; wcObject.price = 150; wcObject.sellMultiplier = 0.5f; wcObject.baseIncome = 10; wcObject.breakChance = 0.2f; wcObject.width = 1; wcObject.height = 1; wcObject.prefab = empty.transform; wcObject.preview = empty.transform; wcObject.buildingName = "Toilet"; wcObject.uiPrefab = empty.transform; }
public GridObject(GridXZ <GridObject> grid, int x, int y) { this.grid = grid; this.x = x; this.y = y; placedObject = null; }
public void Teardown() { Object.Destroy(gameManager); Object.Destroy(eventManager); Object.Destroy(timeManager); grid = null; wcObject = null; }
public GridXZDebug(GridXZ <TValue> grid) : base(grid.Width, grid.Height, grid.CellSize) { this.grid = grid; gridTextArray = new TextMeshPro[grid.Width, grid.Height]; Display(); }
private void Awake() { int gridWidth = 10; int gridHeight = 10; float cellSize = 10f; grid = new GridXZ <GridObject>(gridWidth, gridHeight, cellSize, Vector3.zero, (GridXZ <GridObject> gameObject, int x, int z) => new GridObject(gameObject, x, z)); }
private void Awake() { Instance = this; int gridWidth = 10; int gridHeight = 10; float cellSize = 10f; grid = new GridXZ <GridObject>(gridWidth, gridHeight, cellSize, new Vector3(0, 0, 0), (GridXZ <GridObject> g, int x, int y) => new GridObject(g, x, y)); placedObjectTypeSO = null;// placedObjectTypeSOList[0]; }
protected override void OnAwake() { grid = new ObjectPlacementGrid(width, height, cellSize); if (debugMode) { grid = new GridXZDebug <GridObject>(grid); } CurrentBuilding = buildings[0]; currentDirection = GridObjectDirection.DOWN; }
public void Setup() { gridWidth = 5; gridHeight = 5; cellSize = 3f; vector = Vector3.zero; grid = new GridXZ(gridWidth, gridHeight, cellSize, vector); roadSO = ScriptableObject.CreateInstance <BuildingTypeSO>(); roadSO.buildingName = "roadX"; roadSO.type = BuildingTypeSO.Type.Road; testObject = new GameObject(); baseRoad = testObject.AddComponent <Road>(); baseRoad.Type = roadSO; }
void CheckIfReachable() { // find cell person is standing on GridXZ grid = BuildingSystem.instance.grid; int x; int z; if (transform.position.x <= grid.Width * grid.GetCellSize() && transform.position.x >= 0 && transform.position.z <= grid.Height * grid.GetCellSize() && transform.position.z >= 0) { grid.XZFromWorldPosition(transform.position, out x, out z); Road road = (Road)grid.GetCell(x, z).GetBuilding(); if (road != null && !NavigationManager.instance.reachableRoads.Contains(road)) { Destroy(gameObject); } } }
void CheckIfReachable() { // find cell person is standing on GridXZ grid = BuildingSystem.instance.grid; int x; int z; //if inside map if (transform.position.x <= grid.Width * grid.GetCellSize() && transform.position.x >= 0 && transform.position.z <= grid.Height * grid.GetCellSize() && transform.position.z >= 0) { grid.XZFromWorldPosition(transform.position, out x, out z); if (grid.GetCell(x, z) != null && grid.GetCell(x, z).GetBuilding() != null) { if (grid.GetCell(x, z).GetBuilding().Type.type == BuildingTypeSO.Type.Road) { Road road = (Road)grid.GetCell(x, z).GetBuilding(); if (road != null && !NavigationManager.instance.reachableRoads.Contains(road)) { agent.Warp(BuildingSystem.instance.entryPoint.position + new Vector3(1, 0, 1) * BuildingSystem.instance.CellSize / 2); } } else { agent.Warp(BuildingSystem.instance.entryPoint.position + new Vector3(1, 0, 1) * BuildingSystem.instance.CellSize / 2); GoToRandomRoad(); } } else { agent.Warp(BuildingSystem.instance.entryPoint.position + new Vector3(1, 0, 1) * BuildingSystem.instance.CellSize / 2); GoToRandomRoad(); } } else { GoToRandomRoad(); } RecheckNavigationTarget(); }
public GridObject(GridXZ <GridObject> grid, int x, int z) { this.grid = grid; this.x = x; this.z = z; }
void CalculateReachableAttractions() { List <Attraction> reachable = new List <Attraction>(); reachableCells = new List <Cell>(); reachableRoads = new List <Road>(); reachableCapacity = 0; reachableTrashBinCount = 0; List <Decoration> trashBins = new List <Decoration>(); GridXZ grid = BuildingSystem.instance.grid; int x; int z; // Find first cell from spawn grid.XZFromWorldPosition( BuildingSystem.instance.entryPoint.position + Vector3.forward * BuildingSystem.instance.CellSize, out x, out z); // if first cell is empty, nothing is reachable if (grid.GetCell(x, z).GetBuilding() == null) { return; } // if first cell is building, only this building is reachable if (grid.GetCell(x, z).GetBuilding().Type.type == BuildingTypeSO.Type.Attraction) { reachable.Add((Attraction)grid.GetCell(x, z).GetBuilding()); } // if first cell is decoration, nothing is reachable else if (grid.GetCell(x, z).GetBuilding().Type.type == BuildingTypeSO.Type.Decoration) { } // if first cell is road, start search else if (grid.GetCell(x, z).GetBuilding().Type.type == BuildingTypeSO.Type.Road) { List <Cell> visited = new List <Cell>(); Stack <Cell> path = new Stack <Cell>(); Cell currentCell = grid.GetCell(x, z); bool finished = false; while (!finished) { // add current to visited if (!visited.Contains(currentCell)) { visited.Add(currentCell); } //if current cell is attraction, add to reachable and go back if (currentCell.GetBuilding().Type.type == BuildingTypeSO.Type.Attraction) { Attraction current = (Attraction)currentCell.GetBuilding(); if (!reachable.Contains(current)) { reachable.Add(current); } if (!reachableCells.Contains(currentCell)) { reachableCells.Add(currentCell); } currentCell = path.Pop(); } // else search else if (currentCell.GetBuilding().Type.type == BuildingTypeSO.Type.Road) { Road road = (Road)currentCell.GetBuilding(); if (!reachableRoads.Contains(road)) { reachableRoads.Add(road); } // choose random direction Cell direction = null; foreach (Cell neighbour in currentCell.Neighbours) { // check if neighbour cell has building if (neighbour.GetBuilding() != null) { // check if already visited if (!visited.Contains(neighbour)) { // not visited neighbour exists direction = neighbour; break; } } } // if exists if (direction != null) { // add current to path // go there path.Push(currentCell); currentCell = direction; } //else else { // if path.count > 0 if (path.Count > 0) { // go back currentCell = path.Pop(); } else { finished = true; } } } else if (currentCell.GetBuilding().Type.type == BuildingTypeSO.Type.Decoration) { if (currentCell.GetBuilding().Type.buildingName == "Trash Bin") { if (!trashBins.Contains((Decoration)currentCell.GetBuilding())) { trashBins.Add((Decoration)currentCell.GetBuilding()); } } currentCell = path.Pop(); } } } foreach (Decoration decoration in trashBins) { reachableTrashBinCount++; } foreach (Attraction attraction in reachable) { reachableCapacity += attraction.TotalCapacity; } reachableAttractions = reachable; reachableAttractionCount = reachable.Count; }
public void Initialize(GridXZ <BuildingGridCell> grid, BuildingAssets buildingAssets) { this.grid = grid; ghostControll.Initialize(buildingAssets); }
public Cell(GridXZ grid, int x, int y) { this.grid = grid; this.x = x; this.y = y; }