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.
65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
|
|
|
|
public class Database : SingletonBehaviour<Database>
|
|
{
|
|
#if UNITY_EDITOR
|
|
[Header("Editor section")]
|
|
[SerializeField]
|
|
private List<DefaultAsset> _folders;
|
|
|
|
public List<DefaultAsset> Folders => _folders;
|
|
#endif
|
|
|
|
public const string TYPE = nameof(TYPE);
|
|
[Serializable]
|
|
public class DataList<T> : IEnumerable<T> where T : UnityEngine.Object
|
|
{
|
|
[SerializeField]
|
|
private List<T> elements;
|
|
public DataList() => elements = new List<T>();
|
|
|
|
public T this[string key] => elements.Find(x => x.name == key);
|
|
|
|
public void Add(T element) => elements.Add(element);
|
|
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
return elements.GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return elements.GetEnumerator();
|
|
}
|
|
|
|
public static implicit operator DataList<T>(List<T> list) => new DataList<T>() { elements = list };
|
|
}
|
|
|
|
[SerializeField]
|
|
private List<GameObject> _prefabs;
|
|
[SerializeField]
|
|
private List<ScriptableObject> _scriptableObjects;
|
|
|
|
public DataList<GameObject> Prefabs => _prefabs;
|
|
public DataList<ScriptableObject> ScriptableObjects => _scriptableObjects;
|
|
|
|
public Database()
|
|
{
|
|
_prefabs = new List<GameObject>();
|
|
_scriptableObjects = new List<ScriptableObject>();
|
|
}
|
|
#if UNITY_EDITOR
|
|
|
|
#endif
|
|
} |