GameActionTrigger.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 class GameActionTrigger : IComparable<GameActionTrigger>
  11. {
  12. public virtual string name { get; }
  13. public virtual GameActionTriggersController controller { get => _controller; set => _controller = value; }
  14. protected internal GameActionTriggersController _controller;
  15. public virtual string GetTypeName() => "GameActionTrigger";
  16. public virtual string GetTriggerName() => "Generic Trigger";
  17. [HideInInspector] public string typeName = "GameActionTrigger";
  18. [HideInInspector] public string className;
  19. /// <summary> Fired when the action starts executing.</summary>
  20. public virtual void OnEnable() { }
  21. /// <summary>Fired every frame while executing this trigger.</summary>
  22. public virtual void Update() { }
  23. /// <summary>Fired when the trigger stops executing.</summary>
  24. public virtual void OnDisable() { }
  25. public static GameActionTriggerBase InvokeStringMethod(string typeName, string methodName, string data)
  26. {
  27. Type calledType = Type.GetType(typeName);
  28. GameActionTriggerBase trigger = (GameActionTriggerBase)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 trigger;
  34. }
  35. public int CompareTo(GameActionTrigger other)
  36. {
  37. if(other == null) return 1;
  38. else return -1;
  39. }
  40. public virtual void OnBeforeSerialize(GameActionObjectSerializer serializer, int n) { }
  41. public virtual void OnBeforeDeserialize(GameActionObjectSerializer serializer, int n) { }
  42. }
  43. public class GameActionTriggerBase : GameActionTrigger
  44. {
  45. }
  46. }