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 serializedGameObjectKeys = new List(); [SerializeField] private List serializedGameObjects = new List(); 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(); serializedGameObjects = new List(); } #endregion #region SerializeScriptableObject [SerializeField] private List serializedScriptableObjectKeys = new List(); [SerializeField] private List serializedScriptableObjects = new List(); 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(); serializedScriptableObjects = new List(); } #endregion #region SerializeComponent [SerializeField] private List serializedComponentKeys = new List(); [SerializeField] private List serializedComponents = new List(); 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(); serializedComponents = new List(); } #endregion #region SerializeBehaviour [SerializeField] private List serializedBehaviourKeys = new List(); [SerializeField] private List serializedBehaviours = new List(); 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(); serializedBehaviours = new List(); } #endregion #region SerializeMaterial [SerializeField] private List serializedMaterialKeys = new List(); [SerializeField] private List serializedMaterials = new List(); 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(); serializedMaterials = new List(); } #endregion } }