using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Tilemaps; using static Extensions; [CreateAssetMenu(menuName = "Gather And Defend/Resource Tile")] public class ResourceTile : LevelTile { [SerializeField] [Tooltip("the prefab of the currency that will be spawned when mining this resource")] private GameObject _yieldPrefab; [LevelSerialize] private string YieldPrefabName => _yieldPrefab.name; [SerializeField, LevelSerialize] private float _yieldSpeed = 1; //resource per second [LevelSerialize] private float _yieldCounter = 0; [LevelSerialize] public bool Occupied { get; set; } public override void LevelDestroy() { //nothing } public override void LevelStart() { //nothing } public override void LevelUpdate() { if (!Occupied) return; _yieldCounter += Time.deltaTime * _yieldSpeed; if (_yieldCounter < 1) return; _yieldCounter = 0; var yielded = Instantiate(_yieldPrefab, Position, Quaternion.identity); yielded.transform.SetParent(LevelManager.Instance.LevelTransform); } public override bool Equals(ILevelObject other) { return other is ResourceTile otherRes && Position == otherRes.Position && Tilemap == otherRes.Tilemap && _yieldPrefab == otherRes._yieldPrefab && _yieldCounter == otherRes._yieldCounter; } public override Dictionary ToDictionary() { return Extensions.ToDictionary(this); } }