public void UpdatePositions() { for (int x = 0; x < mapShape.x; x++) { for (int y = 0; y < mapShape.y; y++) { Vector2Int pos = new Vector2Int(x, y); GameObject block = blockGrid[x, y]; if (block == null) { CreateObject(blockGrid, pos, CombatMapper.blockMap[0], 0); } else { if (isBaseOfObject(blockGrid, new Vector2Int(x, y))) { GridObject blockInfo = block.GetComponent <GridObject>(); blockInfo.ContainingGrid = blockGrid; blockInfo.AddObjectToGrid(new Vector2Int(x, y)); UpdatePositionHelper(blockGrid, pos); block.GetComponent <BlockTemplate>().finalPosition = block.transform.position; } } GameObject character = characterGrid[x, y]; if (!(character is null)) { if (isBaseOfObject(characterGrid, new Vector2Int(x, y))) { GridObject characterInfo = character.GetComponent <GridObject>(); characterInfo.ContainingGrid = characterGrid; characterInfo.AddObjectToGrid(new Vector2Int(x, y)); UpdatePositionHelper(characterGrid, pos); } } GameObject Pobject = objectGrid[x, y]; if (!(Pobject is null)) { if (isBaseOfObject(objectGrid, new Vector2Int(x, y))) { GridObject PobjectInfo = Pobject.GetComponent <GridObject>(); PobjectInfo.ContainingGrid = objectGrid; PobjectInfo.AddObjectToGrid(new Vector2Int(x, y)); UpdatePositionHelper(objectGrid, pos); } } } } }
public void CreateObject(GameObject[,] grid, Vector2Int grid_pos, GameObject target_object, int objectID) { if (grid == characterGrid) { if (objectID == 0) { if (Clip != null) { return; } } else if (objectID <= 10) { if (Partner != null) { return; } } } GameObject newObject = Instantiate(target_object, new Vector3(0, 0, 0), Quaternion.identity); GridObject gridClass = newObject.GetComponent <GridObject>(); if (!LevelFloor(grid_pos, gridClass.TileSize) && grid != blockGrid) { Destroy(newObject); return; } newObject.transform.position = GridToPosition(grid_pos, gridClass.TileSize); grid[grid_pos.x, grid_pos.y] = newObject; gridClass.pos = grid_pos; gridClass.objectID = objectID; gridClass.ContainingGrid = grid; gridClass.AddObjectToGrid(grid_pos); if (gridClass.name == "GoalBlock") { Debug.Log("BlockAddedToList"); goalBlockList.Add(newObject.GetComponent <GoalBlock>()); } SpriteFlipper flipper = newObject.GetComponent <SpriteFlipper>(); if (flipper != null) { if (grid_pos.x <= mapShape.x / 2) { flipper.setFacingRightInstant(); } else { flipper.setFacingLeftInstant(); } } if (grid == characterGrid) { if (objectID == 0) { if (Clip == null) { Clip = newObject; } } else if (objectID <= 10) { if (Partner == null) { Partner = newObject; } } else { EnemyList.Add(newObject); } } }