12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- using System.Collections.Generic;
- 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();
- }
- #region Objects
- [SerializeField] private List<string> objectKeyList = new List<string>();
- [SerializeField] private List<object> objectList = new List<object>();
- private int GetObjectIndex(string key)
- {
- for (int i = 0; i < objectKeyList.Count; i++)
- {
- if(objectKeyList[i] == key) return i;
- }
- return -1;
- }
- public void AddObject(string key, object obj)
- {
- int index = GetObjectIndex(key);
- if(index == -1)
- {
- objectKeyList.Add(key);
- objectList.Add(obj);
- }
- else objectList[index] = obj;
- }
- public object GetObject(string key)
- {
- int index = GetObjectIndex(key);
- if(index == -1) return null;
- else return objectList[index];
- }
- #endregion
- #region gameObjects
- [SerializeField] private List<string> gameObjectKeyList = new List<string>();
- [SerializeField] private List<GameObject> gameObjectList = new List<GameObject>();
- private int GetGameObjectIndex(string key)
- {
- for (int i = 0; i < gameObjectKeyList.Count; i++)
- {
- if(gameObjectKeyList[i] == key) return i;
- }
- return -1;
- }
- public void AddGameObject(string key, GameObject obj)
- {
- int index = GetGameObjectIndex(key);
- if(index == -1)
- {
- gameObjectKeyList.Add(key);
- gameObjectList.Add(obj);
- }
- else gameObjectList[index] = obj;
- }
- public GameObject GetGameObject(string key)
- {
- int index = GetGameObjectIndex(key);
- if(index == -1) return null;
- else return gameObjectList[index];
- }
- public int GameObjectCount() => gameObjectList.Count;
- #endregion
- }
- }
|