|
@@ -1,39 +1,92 @@
|
|
|
-using System.Collections;
|
|
|
+
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
|
namespace KairoEngine.Core.ModuleSystem
|
|
|
{
|
|
|
- [System.Serializable]
|
|
|
- public class GameModule
|
|
|
+ [System.Serializable, HideReferenceObjectPicker]
|
|
|
+ public class GameModule : IComparable<GameModule>
|
|
|
{
|
|
|
- [SerializeField, HideInInspector] private string _name = "Empty Module Slot";
|
|
|
+ [SerializeField, HideInInspector] public virtual string name => "Empty Module Slot";
|
|
|
+ [SerializeField, HideInInspector] public string typeName = "GameModule";
|
|
|
+ [SerializeField, HideInInspector] public string className;
|
|
|
|
|
|
- [InlineButton("ResetModule", "Reset")]
|
|
|
- [InlineButton("RemoveModule", "Remove")]
|
|
|
- [FoldoutGroup("@_name"), HideIf("@module == null")] public bool enableModule = true;
|
|
|
-
|
|
|
- [SerializeReference, InlineProperty, HideLabel, FoldoutGroup("@_name"), OnValueChanged("UpdateModuleName"), PropertySpace(SpaceBefore = 5, SpaceAfter = 5)]
|
|
|
- public IGameModule module;
|
|
|
+ [InlineButton("Reset", "Reset")]
|
|
|
+ [InlineButton("Remove", "Remove")]
|
|
|
+ [FoldoutGroup("@name")] public bool enableModule = true;
|
|
|
|
|
|
[HideInInspector] public bool isInitialized = false;
|
|
|
[HideInInspector] public GameConfig gameConfig;
|
|
|
|
|
|
- private void UpdateModuleName()
|
|
|
+ public GameModule(GameConfig config)
|
|
|
+ {
|
|
|
+ this.gameConfig = config;
|
|
|
+ this.className = this.GetType().AssemblyQualifiedName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void Load(Transform parent)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void Reset()
|
|
|
{
|
|
|
- if(module != null) _name = module.name;
|
|
|
- else _name = "Empty Module Slot";
|
|
|
+
|
|
|
}
|
|
|
- private void ResetModule()
|
|
|
+
|
|
|
+ public virtual void Destroy()
|
|
|
{
|
|
|
- module.Reset();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- [FoldoutGroup("@_name"), HideIf("@module != null"), Button("Remove Empty Module")]
|
|
|
- private void RemoveModule()
|
|
|
+ [FoldoutGroup("@name")]
|
|
|
+ public virtual void Remove()
|
|
|
{
|
|
|
gameConfig.modules.Remove(this);
|
|
|
}
|
|
|
+
|
|
|
+ public virtual int CompareTo(GameModule other)
|
|
|
+ {
|
|
|
+ if(other == null) return 1;
|
|
|
+ else return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static GameModuleBase InvokeStringMethod(string typeName, string methodName, string data)
|
|
|
+ {
|
|
|
+ Type calledType = Type.GetType(typeName);
|
|
|
+ if(calledType == null)
|
|
|
+ {
|
|
|
+ Debug.LogError($"Could not find type: \"{typeName}\"");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GameModuleBase module = (GameModuleBase)calledType.InvokeMember($"JSONTo{methodName}",
|
|
|
+ System.Reflection.BindingFlags.InvokeMethod |
|
|
|
+ System.Reflection.BindingFlags.Public |
|
|
|
+ System.Reflection.BindingFlags.Static,
|
|
|
+ null, null, new object[] { data });
|
|
|
+ return module;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static GameModule JSONToGameModule(string data)
|
|
|
+ {
|
|
|
+ return JsonUtility.FromJson<GameModule>(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public virtual void OnBeforeSerialize(ObjectSerializer serializer) { }
|
|
|
+ public virtual void OnBeforeDeserialize(ObjectSerializer serializer) { }
|
|
|
+ }
|
|
|
+
|
|
|
+ [System.Serializable, HideReferenceObjectPicker]
|
|
|
+ public class GameModuleBase : GameModule
|
|
|
+ {
|
|
|
+ public GameModuleBase(GameConfig config) : base(config)
|
|
|
+ {
|
|
|
+ this.gameConfig = config;
|
|
|
+ this.className = this.GetType().AssemblyQualifiedName;
|
|
|
+ this.typeName = "GameModuleBase";
|
|
|
+ }
|
|
|
}
|
|
|
}
|