CharacteCheckForInteractionTaskAction.cs 1.5 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 CharacteCheckForInteractionTaskAction : ActionTask
  11. {
  12. [BlackboardOnly] public BBParameter<CharacterController> character;
  13. [BlackboardOnly] public BBParameter<GameObject> interactionTarget;
  14. [BlackboardOnly] public BBParameter<bool> isInteracting;
  15. public float timer = 2f;
  16. private float counter = 0f;
  17. protected override string info
  18. {
  19. get { return "Check for interaction"; }
  20. }
  21. protected override void OnExecute()
  22. {
  23. InteractionEvents.StartListening($"{character.value.unique_name}-StartDialogue", OnInteraction);
  24. counter = 0f;
  25. }
  26. protected override void OnUpdate()
  27. {
  28. counter += Time.deltaTime;
  29. if(counter > timer)
  30. {
  31. InteractionEvents.StopListening($"{character.value.unique_name}-StartDialogue", OnInteraction);
  32. EndAction(false);
  33. }
  34. }
  35. private void OnInteraction(EventData eventData)
  36. {
  37. InteractionEvents.StopListening($"{character.value.unique_name}-StartDialogue", OnInteraction);
  38. interactionTarget.value = eventData.obj;
  39. isInteracting.value = true;
  40. EndAction(true);
  41. }
  42. }
  43. }