1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
-
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Sirenix.OdinInspector;
- namespace KairoEngine.Core.ModuleSystem
- {
- [System.Serializable, HideReferenceObjectPicker]
- public class GameModule : IComparable<GameModule>
- {
- [SerializeField, HideInInspector] public virtual string name => "Empty Module Slot";
- [SerializeField, HideInInspector] public string typeName = "GameModule";
- [SerializeField, HideInInspector] public string className;
- [InlineButton("Reset", "Reset")]
- [InlineButton("Remove", "Remove")]
- [FoldoutGroup("@name")] public bool enableModule = true;
- [HideInInspector] public bool isInitialized = false;
- [HideInInspector] public GameConfig gameConfig;
- public GameModule(GameConfig config)
- {
- this.gameConfig = config;
- this.className = this.GetType().AssemblyQualifiedName;
- }
- public virtual void Load(Transform parent)
- {
-
- }
- public virtual void Reset()
- {
-
- }
- public virtual void Destroy()
- {
-
- }
- [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";
- }
- }
- }
|