using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Sirenix.OdinInspector; using KairoEngine.Core; namespace KairoEngine.Core.GameActions { [System.Serializable, HideReferenceObjectPicker] public abstract class GameActionContextVariable : IComparable { [ShowIf("@showEdit && canEdit"), ShowInInspector, PropertyOrder(3)] public string name { get => _name; set => _name = value; } [SerializeField, HideInInspector] private string _name = "New Variable"; protected internal bool showEdit = false; [HideInInspector] public bool canEdit = true; [HideInInspector] public string typeName = "GameActionContextVariable"; public virtual string GetTypeName() => "GameActionContextVariable"; public virtual string GetVariableName() => "Generic Variable"; [HideInInspector] public string className; public int CompareTo(GameActionContextVariable other) { if(other == null) return 1; else return 0; } public abstract T GetValue(T defaultValue); public abstract void SetValue(T newValue); public static GameActionContextVariableBase InvokeStringMethod(string typeName, string methodName, string data) { Type calledType = Type.GetType(typeName); GameActionContextVariableBase variable = (GameActionContextVariableBase)calledType.InvokeMember($"JSONTo{methodName}", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, null, new object[] { data }); return variable; } public virtual void OnBeforeSerialize(GameActionObjectSerializer serializer) { } public virtual void OnBeforeDeserialize(GameActionObjectSerializer serializer) { } } public class GameActionContextVariableBase : GameActionContextVariable { public override T GetValue(T defaultValue) => default(T); public override void SetValue(T newValue) {} } }