GameActionCondition.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Sirenix.OdinInspector;
  6. using KairoEngine.Core;
  7. namespace KairoEngine.Core.GameActions
  8. {
  9. [System.Serializable, HideReferenceObjectPicker]
  10. public abstract class GameActionCondition : IComparable<GameActionCondition>
  11. {
  12. public virtual string name { get; }
  13. public virtual GameActionsController controller { get => _controller; set => _controller = value; }
  14. protected internal GameActionsController _controller;
  15. [HideInInspector] public string typeName = "GameActionCondition";
  16. public virtual string GetTypeName() => "GameActionCondition";
  17. public virtual string GetActionName() => "Generic Condition";
  18. [HideInInspector] public string className;
  19. /// <summary>The Restart function is fired once on each GameAction in a controller when all actions have the bool done set to True.</summary>
  20. public virtual bool Evaluate()
  21. {
  22. return true;
  23. }
  24. public static GameActionCondition InvokeStringMethod(string typeName, string methodName, string data)
  25. {
  26. Type calledType = Type.GetType(typeName);
  27. if(calledType == null) Debug.LogError($"type \"{typeName}\" is not valid");
  28. GameActionCondition condition = (GameActionCondition)calledType.InvokeMember($"JSONTo{methodName}",
  29. System.Reflection.BindingFlags.InvokeMethod |
  30. System.Reflection.BindingFlags.Public |
  31. System.Reflection.BindingFlags.Static,
  32. null, null, new object[] { data });
  33. return condition;
  34. }
  35. public int CompareTo(GameActionCondition other)
  36. {
  37. if(other == null) return 1;
  38. else return -1;
  39. }
  40. public virtual void OnBeforeSerialize(GameActionObjectSerializer serializer, int n, int depth) { }
  41. public virtual void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n, int depth) { }
  42. }
  43. public class GameActionConditionBase : GameActionCondition
  44. {
  45. }
  46. }