123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace KairoEngine.Core
- {
- [System.Serializable]
- public class ObjectSerializer
- {
- public void Clear()
- {
- objectKeyList.Clear();
- objectList.Clear();
- gameObjectKeyList.Clear();
- gameObjectList.Clear();
- scriptableObjectKeyList.Clear();
- scriptableObjecttList.Clear();
- unityObjectKeyList.Clear();
- unityObjectList.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 if(index >= objectList.Count) 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 if(index >= gameObjectList.Count) return null;
- else return gameObjectList[index];
- }
- 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
- }
- }
|