| | 1 | | using UnityEngine; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | using TMPro; |
| | 5 | |
|
| | 6 | | namespace DroneGame |
| | 7 | | { |
| | 8 | | [SerializeField] |
| | 9 | | /// <summary>struct that holds information about the tiles from the API</summary> |
| | 10 | | public struct TileData |
| | 11 | | { |
| | 12 | | /// <summary>World coordinates of the tile</summary> |
| | 13 | | public Vector3 globalCoordinates; |
| | 14 | |
|
| | 15 | | /// <summary>Original letter and number coordinate</summary> |
| | 16 | | public string letterCoordinate; |
| | 17 | |
|
| | 18 | | /// <summary>Dict with the tile neighbors, key is letterCoordinate and value is distance to the neighbor</summary> |
| | 19 | | public Dictionary<string, float> neighbors; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | /// <summary>Component of the tile, mainly used for Unity</summary> |
| | 23 | | public class Tile : MonoBehaviour |
| | 24 | | { |
| | 25 | | Material _tileMaterial; |
| | 26 | | Color _startColor; |
| | 27 | |
|
| | 28 | | /// <summary>Set color of the tile</summary> |
| 0 | 29 | | public void SetColor(Color color) =>_tileMaterial.color = color; |
| | 30 | |
|
| | 31 | | /// <summary>Set color of the tile back to the original</summary> |
| 0 | 32 | | public void ResetColor() => SetColor(_startColor); |
| | 33 | |
|
| | 34 | | /// <summary>Since Unity does not allow arguments trough Instantiate we create a startup function |
| | 35 | | /// Position and initialize tile from the TileData</summary> |
| | 36 | | public void Initialize(TileData data) |
| 64 | 37 | | { |
| 64 | 38 | | _tileMaterial = transform.Find("TileModel").GetComponent<MeshRenderer>().material ?? throw new("TileMaterial not f |
| 64 | 39 | | _startColor = _tileMaterial.color; |
| 64 | 40 | | transform.localPosition = data.globalCoordinates; |
| 64 | 41 | | var text = transform.Find("Text").GetComponent<TextMeshPro>(); |
| 64 | 42 | | text.text = data.letterCoordinate; |
| 64 | 43 | | } |
| | 44 | |
|
| | 45 | |
|
| | 46 | | } |
| | 47 | | } |