GameActionObjectSerializer.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace KairoEngine.Core.GameActions
  6. {
  7. [System.Serializable]
  8. public class GameActionObjectSerializer
  9. {
  10. #region SerializeGameObject
  11. [SerializeField] private List<string> serializedGameObjectKeys = new List<string>();
  12. [SerializeField] private List<GameObject> serializedGameObjects = new List<GameObject>();
  13. public void SerializeGameObject(string name, GameObject obj)
  14. {
  15. serializedGameObjectKeys.Add(name);
  16. serializedGameObjects.Add(obj);
  17. }
  18. public GameObject DeserializeGameObject(string name)
  19. {
  20. for (int i = 0; i < serializedGameObjectKeys.Count; i++)
  21. {
  22. if(serializedGameObjectKeys[i] == name) return serializedGameObjects[i];
  23. }
  24. return null;
  25. }
  26. public void ClearGameObjects()
  27. {
  28. serializedGameObjectKeys = new List<string>();
  29. serializedGameObjects = new List<GameObject>();
  30. }
  31. #endregion
  32. #region SerializeScriptableObject
  33. [SerializeField] private List<string> serializedScriptableObjectKeys = new List<string>();
  34. [SerializeField] private List<ScriptableObject> serializedScriptableObjects = new List<ScriptableObject>();
  35. public void SerializeScriptableObject(string name, ScriptableObject obj)
  36. {
  37. serializedScriptableObjectKeys.Add(name);
  38. serializedScriptableObjects.Add(obj);
  39. }
  40. public ScriptableObject DeserializeScriptableObject(string name)
  41. {
  42. for (int i = 0; i < serializedScriptableObjectKeys.Count; i++)
  43. {
  44. if(serializedScriptableObjectKeys[i] == name) return serializedScriptableObjects[i];
  45. }
  46. return null;
  47. }
  48. public void ClearScriptableObjects()
  49. {
  50. serializedScriptableObjectKeys = new List<string>();
  51. serializedScriptableObjects = new List<ScriptableObject>();
  52. }
  53. #endregion
  54. #region SerializeComponent
  55. [SerializeField] private List<string> serializedComponentKeys = new List<string>();
  56. [SerializeField] private List<Component> serializedComponents = new List<Component>();
  57. public void SerializeComponent(string name, Component comp)
  58. {
  59. serializedComponentKeys.Add(name);
  60. serializedComponents.Add(comp);
  61. }
  62. public Component DeserializeComponent(string name)
  63. {
  64. for (int i = 0; i < serializedComponentKeys.Count; i++)
  65. {
  66. if(serializedComponentKeys[i] == name) return serializedComponents[i];
  67. }
  68. return null;
  69. }
  70. public void ClearComponents()
  71. {
  72. serializedComponentKeys = new List<string>();
  73. serializedComponents = new List<Component>();
  74. }
  75. #endregion
  76. #region SerializeBehaviour
  77. [SerializeField] private List<string> serializedBehaviourKeys = new List<string>();
  78. [SerializeField] private List<Behaviour> serializedBehaviours = new List<Behaviour>();
  79. public void SerializeBehaviour(string name, Behaviour behaviour)
  80. {
  81. serializedBehaviourKeys.Add(name);
  82. serializedBehaviours.Add(behaviour);
  83. }
  84. public Behaviour DeserializeBehaviour(string name)
  85. {
  86. for (int i = 0; i < serializedBehaviourKeys.Count; i++)
  87. {
  88. if(serializedBehaviourKeys[i] == name) return serializedBehaviours[i];
  89. }
  90. return null;
  91. }
  92. public void ClearBehaviours()
  93. {
  94. serializedBehaviourKeys = new List<string>();
  95. serializedBehaviours = new List<Behaviour>();
  96. }
  97. #endregion
  98. #region SerializeMaterial
  99. [SerializeField] private List<string> serializedMaterialKeys = new List<string>();
  100. [SerializeField] private List<Material> serializedMaterials = new List<Material>();
  101. public void SerializeMaterial(string name, Material material)
  102. {
  103. serializedMaterialKeys.Add(name);
  104. serializedMaterials.Add(material);
  105. }
  106. public Material DeserializeMaterial(string name)
  107. {
  108. for (int i = 0; i < serializedMaterialKeys.Count; i++)
  109. {
  110. if(serializedMaterialKeys[i] == name) return serializedMaterials[i];
  111. }
  112. return null;
  113. }
  114. public void ClearMaterials()
  115. {
  116. serializedMaterialKeys = new List<string>();
  117. serializedMaterials = new List<Material>();
  118. }
  119. #endregion
  120. }
  121. }