|
- using System;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- public class GridElement
- {
- public GridElement(IsometricGrid grid, GridIndex index, int type)
- {
- this.grid = grid;
- this.index = index;
- this.type = type;
- this.color = GridOverlay.TransparentColor;
- this.tile = null;
- this.unlocked = false;
- 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);
- this.CalculateVisibility();
- }
-
- public GridIndex Index
- {
- get
- {
- return this.index;
- }
- }
-
- public int Type
- {
- get
- {
- return this.type;
- }
- }
-
- public Color Color
- {
- get
- {
- return this.color;
- }
- set
- {
- if (!object.Equals(value, this.color))
- {
- this.color = value;
- IsometricGrid isometricGrid = this.Grid;
- if (isometricGrid != null && isometricGrid.Overlay != null)
- {
- isometricGrid.Overlay.SetColor(this.index, this.color);
- }
- }
- }
- }
-
- public GridTile Tile
- {
- get
- {
- return this.tile;
- }
- set
- {
- this.tile = value;
- }
- }
-
- public IsometricGrid Grid
- {
- get
- {
- return this.grid;
- }
- }
-
- public Vector2 Origin
- {
- get
- {
- return this.origin;
- }
- }
-
- public bool Unlocked
- {
- get
- {
- return this.unlocked;
- }
- set
- {
- this.unlocked = value;
- }
- }
-
- public bool IsVisible
- {
- get
- {
- return this.bottomVisible || this.leftVisible || this.rightVisible || this.topVisible;
- }
- }
-
- public bool IsFullyVisible
- {
- get
- {
- return this.bottomVisible && this.leftVisible && this.rightVisible && this.topVisible;
- }
- }
-
- private void CalculateVisibility()
- {
- Bounds islandBounds = grid.island.islandBounds;
- Vector2 elementSize = Grid.elementSize;
- Vector3 point = grid.transform.position + (Vector3)origin;
- bottomVisible = islandBounds.Contains(point);
- leftVisible = islandBounds.Contains(new Vector3(point.x - elementSize.x / 2f, point.y + elementSize.y / 2f));
- rightVisible = islandBounds.Contains(new Vector3(point.x + elementSize.x / 2f, point.y + elementSize.y / 2f));
- topVisible = islandBounds.Contains(new Vector3(point.x, point.y + elementSize.y));
- }
-
- private GridIndex index;
-
- private int type;
-
- private Color color;
-
- private GridTile tile;
-
- private bool unlocked;
-
- private IsometricGrid grid;
-
- private Vector2 origin;
-
- private bool topVisible;
-
- private bool leftVisible;
-
- private bool rightVisible;
-
- private bool bottomVisible;
- }
- }
|