using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using NaughtyAttributes; using UnityEngine; namespace EscapeRoomEngine.Engine.Runtime { [SuppressMessage("ReSharper", "InconsistentNaming")] public enum TileLocation { NW, N, NE, W, C, E, SW, S, SE } [Serializable] public struct TilePrefab { public TileLocation location; public GameObject prefab; } public class SpaceTile : MonoBehaviour { public static HashSet EveryTileLocation => new(new[] { TileLocation.NW, TileLocation.N, TileLocation.NE, TileLocation.W, TileLocation.C, TileLocation.E, TileLocation.SW, TileLocation.S, TileLocation.SE }); [BoxGroup("Style Prefabs")] [SerializeField] private List tilePrefabs; [BoxGroup("Style Prefabs")] [SerializeField] private Material material; public TileLocation showTile; private GameObject _tile; private TileLocation _showTile; private void Start() { SetTile(); } private void Update() { if (_showTile != showTile) { SetTile(); } } private void SetTile() { if (_tile) { Destroy(_tile); } _tile = Instantiate(tilePrefabs.Find(tilePrefab => tilePrefab.location == showTile).prefab, transform); _tile.isStatic = true; _tile.GetComponent().material = material; var tileCollider = _tile.AddComponent(); tileCollider.convex = true; tileCollider.sharedMesh = _tile.GetComponent().sharedMesh; _showTile = showTile; } } }