Felix Boucher 1bf7e04798 made LevelObject and Tile methods virtual
problème : le fait que les méthodes update/start/destroy etc des ILevelObject soit abstraites était restreignant (obligation de override)

solution : j'ai rendu les méthodes virtuelles à la place de abstraites.
2023-05-27 20:38:42 -04:00

41 lines
1.0 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using static Extensions;
/// <summary>
/// can be inherited by MonoBehaviours in order to be added to the level manager
/// </summary>
public abstract class LevelObject : MonoBehaviour, ILevelObject
{
[LevelSerialize]
public Vector3 Position => transform.position;
[LevelSerialize]
public string Name => name;
void Awake()
{
if (LevelManager.Instance.Has<LevelObject>(obj => obj.Equals(this))) return;
LevelManager.Instance.Add(this);
}
public virtual void LevelStart()
{
}
public virtual void LevelDestroy()
{
}
public virtual void LevelUpdate()
{
}
public virtual bool Equals(ILevelObject other)
{
if (!other.GetType().Equals(this.GetType())) return false;
var otherObject = other as LevelObject;
return otherObject.Name == Name
&& otherObject.Position == Position;
}
public abstract Dictionary<string, object> ToDictionary();
}