using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace KairoEngine.Core.GameActions { [System.Serializable] public class GameActionObjectSerializer { #region SerializeGameObject [SerializeField] private List<string> serializedGameObjectKeys = new List<string>(); [SerializeField] private List<GameObject> serializedGameObjects = new List<GameObject>(); public void SerializeGameObject(string name, GameObject obj) { serializedGameObjectKeys.Add(name); serializedGameObjects.Add(obj); } public GameObject DeserializeGameObject(string name) { for (int i = 0; i < serializedGameObjectKeys.Count; i++) { if(serializedGameObjectKeys[i] == name) return serializedGameObjects[i]; } return null; } public void ClearGameObjects() { serializedGameObjectKeys = new List<string>(); serializedGameObjects = new List<GameObject>(); } #endregion #region SerializeScriptableObject [SerializeField] private List<string> serializedScriptableObjectKeys = new List<string>(); [SerializeField] private List<ScriptableObject> serializedScriptableObjects = new List<ScriptableObject>(); public void SerializeScriptableObject(string name, ScriptableObject obj) { serializedScriptableObjectKeys.Add(name); serializedScriptableObjects.Add(obj); } public ScriptableObject DeserializeScriptableObject(string name) { for (int i = 0; i < serializedScriptableObjectKeys.Count; i++) { if(serializedScriptableObjectKeys[i] == name) return serializedScriptableObjects[i]; } return null; } public void ClearScriptableObjects() { serializedScriptableObjectKeys = new List<string>(); serializedScriptableObjects = new List<ScriptableObject>(); } #endregion #region SerializeComponent [SerializeField] private List<string> serializedComponentKeys = new List<string>(); [SerializeField] private List<Component> serializedComponents = new List<Component>(); public void SerializeComponent(string name, Component comp) { serializedComponentKeys.Add(name); serializedComponents.Add(comp); } public Component DeserializeComponent(string name) { for (int i = 0; i < serializedComponentKeys.Count; i++) { if(serializedComponentKeys[i] == name) return serializedComponents[i]; } return null; } public void ClearComponents() { serializedComponentKeys = new List<string>(); serializedComponents = new List<Component>(); } #endregion #region SerializeBehaviour [SerializeField] private List<string> serializedBehaviourKeys = new List<string>(); [SerializeField] private List<Behaviour> serializedBehaviours = new List<Behaviour>(); public void SerializeBehaviour(string name, Behaviour behaviour) { serializedBehaviourKeys.Add(name); serializedBehaviours.Add(behaviour); } public Behaviour DeserializeBehaviour(string name) { for (int i = 0; i < serializedBehaviourKeys.Count; i++) { if(serializedBehaviourKeys[i] == name) return serializedBehaviours[i]; } return null; } public void ClearBehaviours() { serializedBehaviourKeys = new List<string>(); serializedBehaviours = new List<Behaviour>(); } #endregion #region SerializeMaterial [SerializeField] private List<string> serializedMaterialKeys = new List<string>(); [SerializeField] private List<Material> serializedMaterials = new List<Material>(); public void SerializeMaterial(string name, Material material) { serializedMaterialKeys.Add(name); serializedMaterials.Add(material); } public Material DeserializeMaterial(string name) { for (int i = 0; i < serializedMaterialKeys.Count; i++) { if(serializedMaterialKeys[i] == name) return serializedMaterials[i]; } return null; } public void ClearMaterials() { serializedMaterialKeys = new List<string>(); serializedMaterials = new List<Material>(); } #endregion } }