GeographicFeature.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. [System.Serializable]
  4. public class GeographicFeature
  5. {
  6. public string name;
  7. public GeographicFeatureType type;
  8. public Vector2Int centerPosition;
  9. public List<Vector2Int> tiles;
  10. public bool isDiscovered = false;
  11. public GeographicFeature(string name, GeographicFeatureType type, Vector2Int centerPosition)
  12. {
  13. this.name = name;
  14. this.type = type;
  15. this.centerPosition = centerPosition;
  16. this.tiles = new List<Vector2Int>();
  17. this.isDiscovered = false;
  18. }
  19. public void AddTile(Vector2Int tile)
  20. {
  21. if (!tiles.Contains(tile))
  22. {
  23. tiles.Add(tile);
  24. }
  25. }
  26. public Vector2Int GetCenterPosition()
  27. {
  28. if (tiles.Count == 0)
  29. return centerPosition;
  30. Vector2 sum = Vector2.zero;
  31. foreach (var tile in tiles)
  32. {
  33. sum += new Vector2(tile.x, tile.y);
  34. }
  35. Vector2 center = sum / tiles.Count;
  36. return new Vector2Int(Mathf.RoundToInt(center.x), Mathf.RoundToInt(center.y));
  37. }
  38. }
  39. public enum GeographicFeatureType
  40. {
  41. Forest,
  42. Lake,
  43. Plain,
  44. Mountain,
  45. River
  46. }