123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- 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<GameAction>
- {
- 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;
- /// <summary>This is set to True if the Start function has already been called.</summary>
- public bool started { get => _started; }
- protected internal bool _started = false;
- /// <summary>Set to True when the action has finished execution. In the next frame the controller will move to the next GameAction in its list.</summary>
- 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) { }
- /// <summary>The Start function is fired once when the action starts executing.</summary>
- public virtual void Start() { }
- /// <summary>The Update function is fired every frame while executing this GameAction.</summary>
- public virtual void Update() { }
- /// <summary>The Restart function is fired once on each GameAction in a controller when all actions have the bool done set to True.</summary>
- 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;
- }
- }
- }
|