problem : tiles dont have an update loop, neither do they have a start / destroy method solution : finished working on a way to create a custom start/update/destroy pipeline for the projects custom tiles. it's using LevelManagerScript as to Update. note : also created a database and a start of serialization system so we can save and load stuff.
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
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<string, object> ToDictionary()
|
|
{
|
|
return Extensions.ToDictionary(this);
|
|
}
|
|
} |