CharacterUnarmedAttackTaskAction.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using NodeCanvas.Framework;
  5. using ParadoxNotion.Design;
  6. using KairoEngine.Core;
  7. namespace KairoEngine.CharacterSystem
  8. {
  9. [Category("KairoEngine")]
  10. public class CharacterUnarmedAttackTaskAction : ActionTask
  11. {
  12. [BlackboardOnly, RequiredField] public BBParameter<CharacterController> character;
  13. [BlackboardOnly, RequiredField] public BBParameter<Transform> target;
  14. protected override string info {
  15. get { return "Unarmed Attack"; }
  16. }
  17. protected override void OnExecute()
  18. {
  19. ICommand cancelCommand = new CancelAtionsCommand(character.value);
  20. CommandInvoker.AddCommand(cancelCommand);
  21. }
  22. protected override void OnUpdate()
  23. {
  24. if(target.value == null) EndAction(false);
  25. ICommand turnCommand = new TurnCommand(character.value, target.value.position);
  26. CommandInvoker.AddCommand(turnCommand);
  27. ICommand attackCommand = new CharacterUnarmedAttackCommand(character.value, target.value.position);
  28. CommandInvoker.AddCommand(attackCommand);
  29. GenericEvents.StartListening(character.value.unique_name + "-AnimationMeleeEnd", End);
  30. }
  31. protected override void OnStop()
  32. {
  33. GenericEvents.StopListening(character.value.unique_name + "-AnimationMeleeEnd", End);
  34. }
  35. private void End()
  36. {
  37. GenericEvents.StopListening(character.value.unique_name + "-AnimationMeleeEnd", End);
  38. EndAction(true);
  39. }
  40. }
  41. }