123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<GameActionContextVariable>
- {
- [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>(T defaultValue);
- public abstract void SetValue<T>(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>(T defaultValue) => default(T);
- public override void SetValue<T>(T newValue) {}
- }
-
- }
|