public GridObjectBase SpawnObject(GridObjectBase newObjectPrefab, Vector2Int position, Color colorNormal, Color colorLinked) { bool canSpawn = IsFree(position, newObjectPrefab.size); if (canSpawn) { GridObjectBase newObject = Instantiate(newObjectPrefab, transform); newObject.UpdatePosition(position); if (newObject is Piece) { (newObject as Piece).Init(colorNormal, colorLinked); activePieces.Add((Piece)newObject); } ForGridRectDo(position, newObject.size, (x, y) => { grid[x, y] = newObject; }); return(newObject); } else { return(null); } }
// Use this for initialization void Start() { GridObjectBase targetObject = GetComponentInParent <GridObjectBase>(); Freeze freeze = targetObject.gameObject.AddComponent <Freeze>(); freeze.iceCubeAnimator = GetComponentInChildren <Animator>(); freeze.iceCubeRoot = this.gameObject; }
public GridObjectBase GetFirstObjectInLine(Vector2Int startOrigin, Vector2Int rect) { GridObjectBase foundObject = null; ForGridRectDo(startOrigin, rect, (x, y) => { if (grid[x, y] != null && foundObject == null) { foundObject = grid[x, y]; } }); return(foundObject); }
/// <summary> /// Shows the attack cubes for an grid object attack. /// </summary> /// <param name="agent">Agent.</param> public void ShowCubesForAgentAttack(GridObjectBase gridObject) { enabled = true; if (gridObject.attackMovementType == MovementType.PlusShaped || gridObject.attackMovementType == MovementType.PlusAndXShaped) { ShowPlusCubesForObject(gridObject); } if (gridObject.attackMovementType == MovementType.XShaped || gridObject.attackMovementType == MovementType.PlusAndXShaped) { ShowXCubesForObject(gridObject); } }
public void MoveObjectYMax(GridObjectBase movedObject, Vector2Int maxPosition) { int objectX = movedObject.Position.x; for (int y = movedObject.Position.y + 1; y <= maxPosition.y; y++) { Vector2Int newPosition = new Vector2Int(objectX, y); bool freeSpot = IsFree(newPosition, movedObject.size); if (freeSpot) { MoveObject(movedObject, newPosition); } else { break; } } }
public void MoveObject(GridObjectBase movedObject, Vector2Int newPosition) { //Remove piece from prev location ForGridRectDo(movedObject.Position, movedObject.size, (x, y) => { if (grid[x, y] == movedObject) { grid[x, y] = null; } }); //Move piece to new position movedObject.UpdatePosition(newPosition); ForGridRectDo(movedObject.Position, movedObject.size, (x, y) => { grid[x, y] = movedObject; }); }
public void AttackTarget(GridObjectBase pTarget) { targetGridObject = pTarget; AttackTargetLocal(); }
private void ForGridObjectRectDo(GridObjectBase gridObject, Action <int, int> action) { ForGridRectDo(gridObject.Position, gridObject.size, action); }
private void ShowPlusCubesForObject(GridObjectBase gridObject) { int cellXIndex = LevelArray.currentLevelArray.GetXIndex(gridObject.transform.position.x); int cellZIndex = LevelArray.currentLevelArray.GetZIndex(gridObject.transform.position.z); int newCellXIndex; int newCellZIndex; int steps = gridObject.attackSteps; while (steps > 0) { newCellXIndex = cellXIndex + steps; newCellZIndex = cellZIndex; if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex)) { NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex); if (agent != null) { if (agent.isLocalAgent == false) { LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject); currentAttackIndex++; } } } newCellXIndex = cellXIndex - steps; newCellZIndex = cellZIndex; if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex)) { NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex); if (agent != null) { if (agent.isLocalAgent == false) { LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject); currentAttackIndex++; } } } newCellXIndex = cellXIndex; newCellZIndex = cellZIndex + steps; if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex)) { NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex); if (agent != null) { if (agent.isLocalAgent == false) { LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject); currentAttackIndex++; } } } newCellXIndex = cellXIndex; newCellZIndex = cellZIndex - steps; if (LevelArray.currentLevelArray.isInIndexRange(newCellXIndex, newCellZIndex)) { NavTileAgent agent = LevelArray.currentLevelArray.GetAgentInCell(newCellXIndex, newCellZIndex); if (agent != null) { if (agent.isLocalAgent == false) { LevelArray.currentLevelArray.setLightCubeForCell(newCellXIndex, newCellZIndex, attackLightParent.GetChild(currentMoveIndex).gameObject); currentAttackIndex++; } } } steps--; } }