PlayableBehaviourInteractiveBubble.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Playables;
  5. using UnityEngine.UI;
  6. // A behaviour that is attached to a playable
  7. public class PlayableBehaviourInteractiveBubble : PlayableBehaviour
  8. {
  9. public Transform bubblePoint;
  10. public Text talkText;
  11. public string talkStr;
  12. public void Init(Text talkText, Transform bubblePoint, string talkStr)
  13. {
  14. this.talkText = talkText;
  15. this.bubblePoint = bubblePoint;
  16. this.talkStr = talkStr;
  17. }
  18. // Called when the owning graph starts playing
  19. public override void OnGraphStart(Playable playable)
  20. {
  21. }
  22. // Called when the owning graph stops playing
  23. public override void OnGraphStop(Playable playable)
  24. {
  25. }
  26. // Called when the state of the playable is set to Play
  27. public override void OnBehaviourPlay(Playable playable, FrameData info)
  28. {
  29. Vector3 pos1 = Camera.main.WorldToScreenPoint(bubblePoint.position);
  30. talkText.transform.parent.localPosition = Camera.main.ScreenToWorldPoint(pos1);
  31. //talkText.transform.parent.localPosition = CommonUtil.ConvertPosToUIPos(bubblePoint.position);
  32. talkText.text = talkStr;
  33. }
  34. // Called when the state of the playable is set to Paused
  35. public override void OnBehaviourPause(Playable playable, FrameData info)
  36. {
  37. }
  38. // Called each frame while the state is set to Play
  39. public override void PrepareFrame(Playable playable, FrameData info)
  40. {
  41. }
  42. }