You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

146 lines
3.6 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace SUISSEngine
  4. {
  5. public class GridElement
  6. {
  7. public GridElement(IsometricGrid grid, GridIndex index, int type)
  8. {
  9. this.grid = grid;
  10. this.index = index;
  11. this.type = type;
  12. this.color = GridOverlay.TransparentColor;
  13. this.tile = null;
  14. this.unlocked = false;
  15. this.origin = new Vector2((float)(index.u - index.v) * grid.elementSize.x * 0.5f, (float)(index.u + index.v) * grid.elementSize.y * -0.5f - grid.elementSize.y);
  16. this.CalculateVisibility();
  17. }
  18. public GridIndex Index
  19. {
  20. get
  21. {
  22. return this.index;
  23. }
  24. }
  25. public int Type
  26. {
  27. get
  28. {
  29. return this.type;
  30. }
  31. }
  32. public Color Color
  33. {
  34. get
  35. {
  36. return this.color;
  37. }
  38. set
  39. {
  40. if (!object.Equals(value, this.color))
  41. {
  42. this.color = value;
  43. IsometricGrid isometricGrid = this.Grid;
  44. if (isometricGrid != null && isometricGrid.Overlay != null)
  45. {
  46. isometricGrid.Overlay.SetColor(this.index, this.color);
  47. }
  48. }
  49. }
  50. }
  51. public GridTile Tile
  52. {
  53. get
  54. {
  55. return this.tile;
  56. }
  57. set
  58. {
  59. this.tile = value;
  60. }
  61. }
  62. public IsometricGrid Grid
  63. {
  64. get
  65. {
  66. return this.grid;
  67. }
  68. }
  69. public Vector2 Origin
  70. {
  71. get
  72. {
  73. return this.origin;
  74. }
  75. }
  76. public bool Unlocked
  77. {
  78. get
  79. {
  80. return this.unlocked;
  81. }
  82. set
  83. {
  84. this.unlocked = value;
  85. }
  86. }
  87. public bool IsVisible
  88. {
  89. get
  90. {
  91. return this.bottomVisible || this.leftVisible || this.rightVisible || this.topVisible;
  92. }
  93. }
  94. public bool IsFullyVisible
  95. {
  96. get
  97. {
  98. return this.bottomVisible && this.leftVisible && this.rightVisible && this.topVisible;
  99. }
  100. }
  101. private void CalculateVisibility()
  102. {
  103. Bounds islandBounds = grid.island.islandBounds;
  104. Vector2 elementSize = Grid.elementSize;
  105. Vector3 point = grid.transform.position + (Vector3)origin;
  106. bottomVisible = islandBounds.Contains(point);
  107. leftVisible = islandBounds.Contains(new Vector3(point.x - elementSize.x / 2f, point.y + elementSize.y / 2f));
  108. rightVisible = islandBounds.Contains(new Vector3(point.x + elementSize.x / 2f, point.y + elementSize.y / 2f));
  109. topVisible = islandBounds.Contains(new Vector3(point.x, point.y + elementSize.y));
  110. }
  111. private GridIndex index;
  112. private int type;
  113. private Color color;
  114. private GridTile tile;
  115. private bool unlocked;
  116. private IsometricGrid grid;
  117. private Vector2 origin;
  118. private bool topVisible;
  119. private bool leftVisible;
  120. private bool rightVisible;
  121. private bool bottomVisible;
  122. }
  123. }