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 GameAction : IConvertible, IComparable { public virtual string name { get; } public virtual GameActionsController controller { get => _controller; set => _controller = value; } [NonSerialized] protected internal GameActionsController _controller; [HideInInspector] public string typeName = "GameAction"; public virtual string GetTypeName() => "GameAction"; public virtual string GetActionName() => "Generic Action"; [HideInInspector] public string className; /// This is set to True if the Start function has already been called. public bool started { get => _started; } protected internal bool _started = false; /// Set to True when the action has finished execution. In the next frame the controller will move to the next GameAction in its list. public bool done { get => _done; } protected internal bool _done = false; public GameAction(GameActionsController controller = null) { if(controller != null) this.controller = controller; className = this.GetType().AssemblyQualifiedName; } public virtual void Initialize(GameActionObjectSerializer objectSerializer) { } /// The Start function is fired once when the action starts executing. public virtual void Start() { } /// The Update function is fired every frame while executing this GameAction. public virtual void Update() { } /// The Restart function is fired once on each GameAction in a controller when all actions have the bool done set to True. public virtual void Restart() { _started = false; _done = false; } public TypeCode GetTypeCode() { return this.GetTypeCode(); } public bool ToBoolean(IFormatProvider provider) { throw new NotImplementedException(); } public byte ToByte(IFormatProvider provider) { throw new NotImplementedException(); } public char ToChar(IFormatProvider provider) { throw new NotImplementedException(); } public DateTime ToDateTime(IFormatProvider provider) { throw new NotImplementedException(); } public decimal ToDecimal(IFormatProvider provider) { throw new NotImplementedException(); } public double ToDouble(IFormatProvider provider) { throw new NotImplementedException(); } public short ToInt16(IFormatProvider provider) { throw new NotImplementedException(); } public int ToInt32(IFormatProvider provider) { throw new NotImplementedException(); } public long ToInt64(IFormatProvider provider) { throw new NotImplementedException(); } public sbyte ToSByte(IFormatProvider provider) { throw new NotImplementedException(); } public float ToSingle(IFormatProvider provider) { throw new NotImplementedException(); } public string ToString(IFormatProvider provider) { throw new NotImplementedException(); } public object ToType(Type conversionType, IFormatProvider provider) { //Debug.Log("Coverting type...."); if(conversionType == typeof(DebugLogGameAction)) return this as DebugLogGameAction; else return this; } public ushort ToUInt16(IFormatProvider provider) { throw new NotImplementedException(); } public uint ToUInt32(IFormatProvider provider) { throw new NotImplementedException(); } public ulong ToUInt64(IFormatProvider provider) { throw new NotImplementedException(); } public static GameActionBase InvokeStringMethod(string typeName, string methodName, string data) { Type calledType = Type.GetType(typeName); if(calledType == null) { Debug.LogError($"Could not find type: \"{typeName}\""); return null; } GameActionBase action = (GameActionBase)calledType.InvokeMember($"JSONTo{methodName}", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, null, new object[] { data }); return action; } public int CompareTo(GameAction other) { if(other == null) return 1; else return -1; } public virtual void OnBeforeSerialize(GameActionObjectSerializer serializer, int n, int depth) { } public virtual void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n, int depth) { } } public class GameActionBase : GameAction { public override GameActionsController controller { get => _controller; set { _controller = value; typeName = "GameActionBase"; } } public GameActionBase(GameActionsController controller) : base(controller) { this.controller = controller; className = this.GetType().AssemblyQualifiedName; } } }