problem : tiles dont have an update loop, neither do they have a start / destroy method solution : finished working on a way to create a custom start/update/destroy pipeline for the projects custom tiles. it's using LevelManagerScript as to Update. note : also created a database and a start of serialization system so we can save and load stuff.
111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System;
|
|
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
|
|
[CustomEditor(typeof(DatabaseSO))]
|
|
public class DatabaseEditor : Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
DrawDefaultInspector();
|
|
|
|
if (GUILayout.Button("fetch assets"))
|
|
{
|
|
var targ = target as DatabaseSO;
|
|
|
|
|
|
|
|
foreach (var folder in targ.Folders)
|
|
{
|
|
var path = AssetDatabase.GetAssetPath(folder);
|
|
foreach (var file in GetAllPaths(path))
|
|
{
|
|
var scriptableObject = AssetDatabase.LoadAssetAtPath<ScriptableObject>(file);
|
|
if (scriptableObject && !Database.Instance.ScriptableObjects.Contains(scriptableObject))
|
|
{
|
|
Database.Instance.ScriptableObjects.Add(scriptableObject);
|
|
}
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(file);
|
|
if (prefab && !Database.Instance.Prefabs.Contains(prefab))
|
|
{
|
|
Database.Instance.Prefabs.Add(prefab);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
string[] GetAllPaths(string target)
|
|
{
|
|
var files = Directory.GetFiles(target).ToList();
|
|
foreach (var dir in Directory.GetDirectories(target))
|
|
{
|
|
files.AddRange(GetAllPaths(dir));
|
|
}
|
|
return files.ToArray();
|
|
}
|
|
}
|
|
#endif
|
|
|
|
[Serializable]
|
|
public class Database : Singleton<Database>
|
|
{
|
|
[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>();
|
|
}
|
|
}
|
|
|
|
[CreateAssetMenu(menuName = "Gather And Defend/Database")]
|
|
public class DatabaseSO : ScriptableObject
|
|
{
|
|
[SerializeField]
|
|
private Database database = Database.Instance;
|
|
[Header("Editor section")]
|
|
[SerializeField]
|
|
private List<DefaultAsset> _folders;
|
|
|
|
public List<DefaultAsset> Folders => _folders;
|
|
}
|