BuildingGridNode.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BuildingGridNode {
  5. GridXZ<BuildingGridNode> grid;
  6. int x, z;
  7. private Transform transform;
  8. public BuildingGridNode(GridXZ<BuildingGridNode> grid, int x, int z) {
  9. this.grid = grid;
  10. this.x = x;
  11. this.z = z;
  12. }
  13. public void SetTransform(Transform transform) {
  14. this.transform = transform;
  15. grid.TriggerGridObjectChanged(x, z);
  16. }
  17. public void ClearTransform() {
  18. this.transform = null;
  19. grid.TriggerGridObjectChanged(x, z);
  20. }
  21. // Needs to be aböe to replace with corner transfom depending on other placed transform and the new one
  22. public bool CanBuild(PlacedObjectTypeSO newObject) {
  23. if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) return false; // Check if over UI element
  24. /* This is not working, can't compare the rotations yet
  25. BuildingGridNode bgn = grid.GetGridObject(x, z);
  26. if (bgn != null) {
  27. Debug.Log("building Grid Node rotation" + bgn +
  28. " new Object Visual Rotation " + newObject.visual.rotation +
  29. " new Object Prefab Rotation " + newObject.prefab.rotation);
  30. }
  31. Debug.Log(transform != null ? transform.gameObject.GetType() : "");
  32. if (transform != null) {
  33. if (transform.childCount > 0) {
  34. for (int i = 0; i < transform.childCount; i++) {
  35. if (transform.GetChild(i).rotation == newObject.prefab.transform.rotation) {
  36. Debug.Log("transform rotation " + transform.GetChild(i).rotation + " newObject rotation " + newObject.prefab.rotation);
  37. return false;
  38. }
  39. }
  40. return true;
  41. }
  42. }
  43. */
  44. return transform == null;
  45. }
  46. public override string ToString() {
  47. return x + ", " + z + " \n" + transform;
  48. }
  49. }