GridObject.cs 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace KairoEngine.Grids
  5. {
  6. public class GridObject
  7. {
  8. private Grid<GridObject> grid;
  9. private int x;
  10. private int y;
  11. private int z;
  12. private PlacedObject placedObject;
  13. public GridObject(Grid<GridObject> grid, int x, int y, int z)
  14. {
  15. this.grid = grid;
  16. this.x = x;
  17. this.y = y;
  18. this.z = z;
  19. }
  20. public PlacedObject GetPlacedObject() => this.placedObject;
  21. public void SetPlacedObject(PlacedObject placedObject)
  22. {
  23. this.placedObject = placedObject;
  24. grid.TriggerGridObjectChanged(x, z);
  25. }
  26. public void ClearPlacedObject() => this.placedObject = null;
  27. public bool CanBuild() => this.placedObject == null;
  28. public override string ToString() => $"{x}, {z}";
  29. public Vector3Int GetPosition() => new Vector3Int(x, y, z);
  30. }
  31. }