| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using UnityEngine;
- using System.Collections.Generic;
- [System.Serializable]
- public class GeographicFeature
- {
- public string name;
- public GeographicFeatureType type;
- public Vector2Int centerPosition;
- public List<Vector2Int> tiles;
- public bool isDiscovered = false;
- public GeographicFeature(string name, GeographicFeatureType type, Vector2Int centerPosition)
- {
- this.name = name;
- this.type = type;
- this.centerPosition = centerPosition;
- this.tiles = new List<Vector2Int>();
- this.isDiscovered = false;
- }
- public void AddTile(Vector2Int tile)
- {
- if (!tiles.Contains(tile))
- {
- tiles.Add(tile);
- }
- }
- public Vector2Int GetCenterPosition()
- {
- if (tiles.Count == 0)
- return centerPosition;
- Vector2 sum = Vector2.zero;
- foreach (var tile in tiles)
- {
- sum += new Vector2(tile.x, tile.y);
- }
- Vector2 center = sum / tiles.Count;
- return new Vector2Int(Mathf.RoundToInt(center.x), Mathf.RoundToInt(center.y));
- }
- }
- public enum GeographicFeatureType
- {
- Forest,
- Lake,
- Plain,
- Mountain,
- River
- }
|