Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. I know my approach might be wrong, but please humor me a little.
  2.  
  3. I'm trying to do DialogueSystem where I can send a string to another class and have it
  4. spit out words one by one through a certain t time.
  5.  
  6. public class Dialogue
  7. {
  8. public Actor actor; //enum
  9. public string line;
  10. }
  11.  
  12. public class DialogueSystemManager
  13. {
  14. public static Func<Dialogue,bool> OnBroadcastToActors;
  15. Queue<Dialogue> sequence;
  16.  
  17. .........
  18. //This class querries a Queue from a SerializableObject and sends it to a Coroutine
  19. public void GetQueue()
  20. {
  21. //Gets a queue from the SO
  22. StartCoroutine(OnBroadcastToActors(sequence));
  23. }
  24.  
  25. //I want to send the dialogue one by one to the actors in sequence, thus the queue and dequeue
  26. //and wait for the coroutine in the other class to finish before continuing, thus the use of a Func
  27. private IEnumerator BroadcastToActors(Queue<Dialogue> _sequence)
  28. {
  29. for(int i = 0 ; i < _sequence.Count ; i++)
  30. {
  31. var dialogue = _sequence.Dequeue();
  32. yield return new WaitUntil(()=> OnBroadcastToActors(dialogue));
  33. }
  34. }
  35.  
  36. .........
  37. }
  38.  
  39. //This objects that need to talk have this class attached
  40. public class DialogueActor
  41. {
  42. public Actor actor; //enum //initialized on Awake()
  43. TextMeshProUGUI dialogueText;
  44.  
  45. ..........
  46. void Awake()
  47. {
  48. ....
  49. DialogueSystemManager.OnBroadcastToActors += OnReceiveBroadcast;
  50. ....
  51. }
  52.  
  53. bool OnReceiveBroadcast(Dialogue _dialogue)
  54. {
  55. if(_dialogue.actor != actor)
  56. return false;
  57.  
  58. StartCoroutine(ShowText(_dialogue.line.ToCharArray()));
  59.  
  60. //Here is where I'm stumped. I need to wait for the Coroutine to finish before continuining here,
  61. //But can't figure out the best way. Maybe the use of a Func is not the best way?
  62.  
  63. return true;
  64. }
  65.  
  66. IEnumerator ShowText(char[] _lineArray)
  67. {
  68. dialogueText.text = "";
  69.  
  70. foreach(char c in _lineArray)
  71. {
  72. dialogueText.text+= c;
  73. yield return null;
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement