StatusEffectTemplate.cs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.Core;
  6. using KairoEngine.Core.GameActions;
  7. using KairoEngine.Stats.GameActions;
  8. namespace KairoEngine.Stats
  9. {
  10. [CreateAssetMenu(fileName = "StatusEffect", menuName = "KairoEngine/Status Effect", order = 8)]
  11. [HideMonoScript]
  12. public class StatusEffectTemplate : ScriptableObject
  13. {
  14. public string title = "";
  15. public string description = "";
  16. public bool hasDuration = true;
  17. [ShowIf("@hasDuration")] public float duration = 1;
  18. [Range(1, 10)] public int maxStack = 1;
  19. // [ListDrawerSettings(HideAddButton = false, HideRemoveButton = false, DraggableItems = false, Expanded = true, ShowPaging = false, ShowItemCount = false)]
  20. // [Space]
  21. // public List<StatModifier> modifiers = new List<StatModifier>();
  22. [TitleGroup("Actions")]
  23. [HideLabel, InlineProperty, OnInspectorInit("SetupContext"), PropertySpace(2, 4)]
  24. public GameActionContext context = new GameActionContext();
  25. [TabGroup("Actions/Triggers", "On Add"), InlineProperty, HideLabel, PropertySpace(1, 2)]
  26. [InfoBox("Execute actions when the StatusEffect is added to a StatsController", InfoMessageType.Info)]
  27. public GameActionsController onAddController;
  28. [TabGroup("Actions/Triggers", "On Stack"), InlineProperty, HideLabel, ShowIf("@maxStack > 1"), PropertySpace(1, 2)]
  29. [InfoBox("Executes when the StatusEffect stack is increased", InfoMessageType.Info)]
  30. public GameActionsController onStackController;
  31. [TabGroup("Actions/Triggers", "While"), InlineProperty, HideLabel, PropertySpace(1, 2)]
  32. [InfoBox("Executes every frame while the StatusEffect is active", InfoMessageType.Info)]
  33. public GameActionsController onWhileController;
  34. [TabGroup("Actions/Triggers", "On Destack"), InlineProperty, HideLabel, ShowIf("@maxStack > 1"), PropertySpace(1, 2)]
  35. [InfoBox("Executes when the StatusEffect stack is decreased", InfoMessageType.Info)]
  36. public GameActionsController onDestackController;
  37. [TabGroup("Actions/Triggers", "On Remove"), InlineProperty, HideLabel, PropertySpace(1, 2)]
  38. [InfoBox("Executes when the StatusEffect is removed from the StatsController", InfoMessageType.Info)]
  39. public GameActionsController onRemoveController;
  40. private void SetupContext()
  41. {
  42. if(context == null) return;
  43. onAddController.context = context;
  44. onStackController.context = context;
  45. onWhileController.context = context;
  46. onDestackController.context = context;
  47. onRemoveController.context = context;
  48. if(!context.HasVariable("Target GameObject"))
  49. {
  50. var variable = new GameActionContextGameObject();
  51. variable.name = "Target GameObject";
  52. variable.value = null;
  53. variable.canEdit = false;
  54. context.variables.Add(variable);
  55. }
  56. if(!context.HasVariable("Stats"))
  57. {
  58. var variable = new GameActionContextStatsController();
  59. variable.name = "Stats";
  60. variable.value = null;
  61. variable.canEdit = false;
  62. context.variables.Add(variable);
  63. }
  64. }
  65. }
  66. }