Felix Boucher d4f32e439f working save / load functions
problème : au moment de load une save, les tiles qui spawnaient des GameObjects au start les spawnaient malgré qu'ils l'avait déjà spawné dans la dernière session de jeu + problèmes de sérialisation divers

solution : spawner le GameObject seulement si le lifetime de la tile est de zéro. correction des différents problèmes de sérialisation.

note : les tiles ne semblent vraiment pas être faites pour avoir une update loop. mais bon, maintenant ça marche.
2023-05-28 01:52:44 -04:00

102 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static Extensions;
public class Entity : LevelObject
{
//Attribut
[SerializeField]
private int _hp;
[SerializeField]
private float _speed;
[SerializeField]
private int _attack_damage;
[SerializeField]
private float _attack_speed;
private float _attack_speed_wait = 0f;
//Enemy Spotted
private bool _isEnemyDetected = false;
private Entity _enemy;
//GETTERS AND SETTERS
public int Hp
{
get { return _hp; }
set { _hp = value; }
}
public float Speed
{
get { return _speed; }
set { _speed = value; }
}
public int AttackDamage
{
get { return _attack_damage; }
set { _attack_damage = value; }
}
public float AttackSpeed
{
get { return _attack_speed; }
set { _attack_speed = value; }
}
public float AttackSpeedWait
{
get { return _attack_speed_wait; }
set { _attack_speed_wait = value; }
}
public bool IsEnemyDetected
{
get { return _isEnemyDetected; }
set { _isEnemyDetected = value; }
}
public Entity Enemy
{
get { return _enemy; }
set { _enemy = value; }
}
#region [LevelManager code]
public override bool Equals(ILevelObject other)
{
return other is Entity otherEntity
&& base.Equals(otherEntity)
&& otherEntity._hp == _hp
&& otherEntity._speed == _speed
&& otherEntity._attack_speed == _attack_speed
&& otherEntity._attack_damage == _attack_damage;
}
public override Dictionary<string, object> ToDictionary()
{
var dict = base.ToDictionary();
dict[nameof(_hp)] = _hp;
dict[nameof(_speed)] = _speed;
dict[nameof(_attack_speed)] = _attack_speed;
dict[nameof(_attack_damage)] = _attack_damage;
dict[nameof(_attack_speed_wait)] = _attack_speed_wait;
return dict;
}
public override void LoadDictionary(Dictionary<string, object> dict)
{
base.LoadDictionary(dict);
_hp = dict[nameof(_hp)].ToInt();
_speed = dict[nameof(_speed)].ToFloat();
_attack_speed = dict[nameof(_attack_speed)].ToFloat();
_attack_damage = dict[nameof(_attack_damage)].ToInt();
_attack_speed_wait = dict[nameof(_attack_speed_wait)].ToFloat();
}
#endregion
}