Browse Source

Fixed GameActions serialization bugs

James Peret 2 years ago
parent
commit
baa2ef254c

+ 1 - 1
Runtime/ConfigOptions/ConfigOptionsManager.cs

@@ -9,7 +9,7 @@ namespace KairoEngine.Core.ConfigOptions
     public class ConfigOptionsManager
     {
         
-        [ShowInInspector, LabelText("Configuration"), PropertySpace(4,4)] public List<ConfigOptionBase> list = new List<ConfigOptionBase>();
+        [ShowInInspector, LabelText("Configuration"), PropertySpace(4,0)] public List<ConfigOptionBase> list = new List<ConfigOptionBase>();
         [LabelText("Debug config loading")] public bool debug = false;
 
         public static void SetConfigOption(string title, ConfigOptionData data)

+ 1 - 1
Runtime/GameActions/GameActionContext.cs

@@ -12,7 +12,7 @@ namespace KairoEngine.Core.GameActions
     public class GameActionContext : ISerializationCallbackReceiver
     {
         [ListDrawerSettings(HideAddButton = true, HideRemoveButton = false, DraggableItems = false, Expanded = false, ShowPaging = false, ShowItemCount = true)]
-        [ShowInInspector]
+        [ShowInInspector, NonSerialized]
         public List<GameActionContextVariable> variables = new List<GameActionContextVariable>();
 
         public bool HasVariable(string variableName)

+ 1 - 0
Runtime/GameActions/Triggers/OnEventGameActionTrigger.cs

@@ -69,6 +69,7 @@ namespace KairoEngine.Core.GameActions
 
         private void TriggerActions()
         {
+            controller.actionsController.Restart();
             controller.TriggerActions();
             if(oneShot) 
             {

+ 2 - 4
Runtime/ModuleSystem/GameConfig.cs

@@ -13,18 +13,16 @@ namespace KairoEngine.Core.ModuleSystem
     [CreateAssetMenu(fileName = "GameConfig", menuName = "KairoEngine/GameConfig"), HideMonoScript]
     public class GameConfig : ScriptableObject, ISerializationCallbackReceiver
     {
-        [Title("Game Modules", "List of game system modules in load order")]
         [ListDrawerSettings(DraggableItems = false, HideRemoveButton = true, ShowPaging = false)]
-        [ShowInInspector, NonSerialized, OnValueChanged("StartModule")]
+        [ShowInInspector, NonSerialized, OnValueChanged("StartModule"), LabelText("Game Modules")]
         public List<GameModule> modules = new List<GameModule>();
 
         [OnInspectorInit("GetModuleNames"), OnValueChanged("AddNewModule")]
         [ValueDropdown("possibleModules", IsUniqueList = false)]
         [LabelText("Add New Module")]
-        [NonSerialized]
+        [NonSerialized, PropertySpace(0, 8)]
         public GameModule newModule;
 
-        [Title("Startup Configurations", "List of configurations to be set up when the game starts")]
         [InlineProperty, HideLabel] public ConfigOptionsManager configOptions = new ConfigOptionsManager();
         
         private void StartModule()

+ 1 - 0
Runtime/ObjectPoolModule.cs

@@ -32,6 +32,7 @@ namespace KairoEngine.Core.ObjectPooling
                 return;
             }
             GameObject objectPoolObj = GameObject.Instantiate(ObjectPoolPrefab, parent);
+            objectPoolObj.name = "ObjectPool";
             MasterObjectPooler masterObjectPooler = objectPoolObj.GetComponent<MasterObjectPooler>();
             if(masterObjectPooler == null)
             {

+ 75 - 7
Runtime/ObjectSerializer.cs

@@ -4,22 +4,19 @@ 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();
+            scriptableObjectKeyList.Clear();
+            scriptableObjecttList.Clear();
+            unityObjectKeyList.Clear();
+            unityObjectList.Clear();
         }
 
         #region Objects
@@ -92,5 +89,76 @@ namespace KairoEngine.Core
         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
     }
 }