|
@@ -4,22 +4,19 @@ using UnityEngine;
|
|
|
|
|
|
namespace KairoEngine.Core
|
|
|
{
|
|
|
- // Todo: Refactor components to use lists instead of a dictionary
|
|
|
- // Todo: Refactor ScriptableObjects to use lists instead of a dictionary
|
|
|
[System.Serializable]
|
|
|
public class ObjectSerializer
|
|
|
{
|
|
|
- //[HideInInspector] public Dictionary<string, Component> components = new Dictionary<string, Component>();
|
|
|
- //[HideInInspector] public Dictionary<string, ScriptableObject> scriptableObjects = new Dictionary<string, ScriptableObject>();
|
|
|
-
|
|
|
public void Clear()
|
|
|
{
|
|
|
objectKeyList.Clear();
|
|
|
objectList.Clear();
|
|
|
gameObjectKeyList.Clear();
|
|
|
gameObjectList.Clear();
|
|
|
- //components.Clear();
|
|
|
- //scriptableObjects.Clear();
|
|
|
+ scriptableObjectKeyList.Clear();
|
|
|
+ scriptableObjecttList.Clear();
|
|
|
+ unityObjectKeyList.Clear();
|
|
|
+ unityObjectList.Clear();
|
|
|
}
|
|
|
|
|
|
#region Objects
|
|
@@ -92,5 +89,76 @@ namespace KairoEngine.Core
|
|
|
public int GameObjectCount() => gameObjectList.Count;
|
|
|
|
|
|
#endregion
|
|
|
+
|
|
|
+ #region scriptablebjects
|
|
|
+
|
|
|
+ [SerializeField] private List<string> scriptableObjectKeyList = new List<string>();
|
|
|
+ [SerializeField] private List<ScriptableObject> scriptableObjecttList = new List<ScriptableObject>();
|
|
|
+
|
|
|
+ private int GetScriptableObjectIndex(string key)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < scriptableObjectKeyList.Count; i++)
|
|
|
+ {
|
|
|
+ if(scriptableObjectKeyList[i] == key) return i;
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void AddScriptableObject(string key, ScriptableObject obj)
|
|
|
+ {
|
|
|
+ int index = GetScriptableObjectIndex(key);
|
|
|
+ if(index == -1)
|
|
|
+ {
|
|
|
+ scriptableObjectKeyList.Add(key);
|
|
|
+ scriptableObjecttList.Add(obj);
|
|
|
+ }
|
|
|
+ else scriptableObjecttList[index] = obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ScriptableObject GetScriptableObject(string key)
|
|
|
+ {
|
|
|
+ int index = GetScriptableObjectIndex(key);
|
|
|
+ if(index == -1) return null;
|
|
|
+ else if(index >= scriptableObjecttList.Count) return null;
|
|
|
+ else return scriptableObjecttList[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ public int ScriptableObjectCount() => scriptableObjecttList.Count;
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region UnityObjects
|
|
|
+ [SerializeField] private List<string> unityObjectKeyList = new List<string>();
|
|
|
+ [SerializeField] private List<UnityEngine.Object> unityObjectList = new List<UnityEngine.Object>();
|
|
|
+
|
|
|
+ private int GetUnityObjectIndex(string key)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < unityObjectKeyList.Count; i++)
|
|
|
+ {
|
|
|
+ if(unityObjectKeyList[i] == key) return i;
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void AddUnityObject(string key, UnityEngine.Object obj)
|
|
|
+ {
|
|
|
+ int index = GetUnityObjectIndex(key);
|
|
|
+ if(index == -1)
|
|
|
+ {
|
|
|
+ unityObjectKeyList.Add(key);
|
|
|
+ unityObjectList.Add(obj);
|
|
|
+ }
|
|
|
+ else unityObjectList[index] = obj;
|
|
|
+ }
|
|
|
+
|
|
|
+ public object GetUnityObject(string key)
|
|
|
+ {
|
|
|
+ int index = GetUnityObjectIndex(key);
|
|
|
+ if(index == -1) return null;
|
|
|
+ else if(index >= unityObjectList.Count) return null;
|
|
|
+ else return unityObjectList[index];
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|