problème : pas de moyen de sauvegarder et de charger les niveaux entamés solution : fonctions save et load dans le LevelManager
59 lines
1.9 KiB
C#
59 lines
1.9 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 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 bool Equals(ILevelObject other)
|
|
{
|
|
return other is SpawnerTile spawner
|
|
&& base.Equals(spawner)
|
|
&& spawner._prefab == _prefab
|
|
&& spawner._spawnOnStart == _spawnOnStart
|
|
&& spawner._spawnSpeed == _spawnSpeed;
|
|
}
|
|
public override Dictionary<string, object> ToDictionary()
|
|
{
|
|
var dict = base.ToDictionary();
|
|
|
|
dict[nameof(_prefab)] = _prefab.name;
|
|
dict[nameof(_spawnOnStart)] = _spawnOnStart;
|
|
dict[nameof(_spawnSpeed)] = _spawnSpeed;
|
|
|
|
return dict;
|
|
}
|
|
public override void LoadDictionary(Dictionary<string, object> dict)
|
|
{
|
|
base.LoadDictionary(dict);
|
|
|
|
var prefabName = dict[nameof(_prefab)].ToString();
|
|
_prefab = Database.Instance.Prefabs[prefabName];
|
|
_spawnOnStart = (bool)dict[nameof(_spawnOnStart)];
|
|
_spawnSpeed = (float)dict[nameof(_spawnSpeed)];
|
|
}
|
|
} |