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.
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using Unity.Plastic.Newtonsoft.Json.Linq;
|
|
using UnityEngine;
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Spawner Tile")]
|
|
public class SpawnerTile : LevelTile
|
|
{
|
|
[SerializeField]
|
|
private GameObject _prefab;
|
|
[SerializeField]
|
|
private bool _spawnOnStart = true;
|
|
[SerializeField]
|
|
private float _spawnSpeed = 0;
|
|
private float _spawnCounter = 0;
|
|
|
|
public override bool Equals(ILevelObject other)
|
|
{
|
|
return other is SpawnerTile spawner
|
|
&& spawner.Position == Position
|
|
&& spawner.Tilemap == Tilemap
|
|
&& spawner._prefab == _prefab
|
|
&& spawner._spawnOnStart == _spawnOnStart
|
|
&& spawner._spawnSpeed == _spawnSpeed;
|
|
}
|
|
|
|
public override void LevelDestroy()
|
|
{
|
|
//nothing
|
|
}
|
|
|
|
public override void LevelStart()
|
|
{
|
|
if (!_spawnOnStart) return;
|
|
var instance = Instantiate(_prefab, Position, Quaternion.identity);
|
|
instance.transform.SetParent(LevelManager.Instance.LevelTransform);
|
|
}
|
|
|
|
public override void LevelUpdate()
|
|
{
|
|
_spawnCounter += Time.deltaTime * _spawnSpeed;
|
|
if (_spawnCounter < 1) return;
|
|
|
|
_spawnCounter = 0;
|
|
var instance = Instantiate(_prefab, Position, Quaternion.identity);
|
|
instance.transform.SetParent(LevelManager.Instance.LevelTransform);
|
|
}
|
|
public override Dictionary<string, object> ToDictionary()
|
|
{
|
|
return Extensions.ToDictionary(this);
|
|
}
|
|
} |