problèmes : - mon code et l'arrangement des fichiers avait besoin d'un peu de tidy up - les tiles qui n'étaient pas des LevelTile ne loadaient pas solution : - rangé un peu + respecté structure une classe - un fichier - tenté un build pour voir si tout roulait comme il faut, ce qui m'a porté à ajouter des directives de preprocessing et à bouger les custom inspectors dans le dossier Editor. - ajouté une représentation simple des tuiles non-LevelTile dans la sauvegarde.
58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Collections;
|
|
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
|
|
{
|
|
public Vector3 Position { get => transform.position; protected set => transform.position = value; }
|
|
public string Name { get => name; protected set => name = value; }
|
|
|
|
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)
|
|
{
|
|
return other is LevelObject otherObject
|
|
&& otherObject.Name == Name
|
|
&& otherObject.Position == Position;
|
|
}
|
|
public virtual Dictionary<string, object> ToDictionary()
|
|
{
|
|
return new Dictionary<string, object>()
|
|
{
|
|
{nameof(Name), Name },
|
|
{nameof(Position), new float[]{Position.x, Position.y, Position.z } },
|
|
{nameof(ILevelObject.ObjectType), nameof(ILevelObject.ObjectType.Prefab) }
|
|
};
|
|
}
|
|
public virtual void LoadDictionary(Dictionary<string, object> dict)
|
|
{
|
|
Name = dict[nameof(Name)].ToString();
|
|
Position = dict[nameof(Position)].ToVector3();
|
|
}
|
|
|
|
public void RemoveFromLevel()
|
|
{
|
|
//checks if go is still in scene before removing it
|
|
if (!this) return;
|
|
Destroy(gameObject);
|
|
}
|
|
} |