Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I know my approach might be wrong, but please humor me a little.
- I'm trying to do DialogueSystem where I can send a string to another class and have it
- spit out words one by one through a certain t time.
- public class Dialogue
- {
- public Actor actor; //enum
- public string line;
- }
- public class DialogueSystemManager
- {
- public static Func<Dialogue,bool> OnBroadcastToActors;
- Queue<Dialogue> sequence;
- .........
- //This class querries a Queue from a SerializableObject and sends it to a Coroutine
- public void GetQueue()
- {
- //Gets a queue from the SO
- StartCoroutine(OnBroadcastToActors(sequence));
- }
- //I want to send the dialogue one by one to the actors in sequence, thus the queue and dequeue
- //and wait for the coroutine in the other class to finish before continuing, thus the use of a Func
- private IEnumerator BroadcastToActors(Queue<Dialogue> _sequence)
- {
- for(int i = 0 ; i < _sequence.Count ; i++)
- {
- var dialogue = _sequence.Dequeue();
- yield return new WaitUntil(()=> OnBroadcastToActors(dialogue));
- }
- }
- .........
- }
- //This objects that need to talk have this class attached
- public class DialogueActor
- {
- public Actor actor; //enum //initialized on Awake()
- TextMeshProUGUI dialogueText;
- ..........
- void Awake()
- {
- ....
- DialogueSystemManager.OnBroadcastToActors += OnReceiveBroadcast;
- ....
- }
- bool OnReceiveBroadcast(Dialogue _dialogue)
- {
- if(_dialogue.actor != actor)
- return false;
- StartCoroutine(ShowText(_dialogue.line.ToCharArray()));
- //Here is where I'm stumped. I need to wait for the Coroutine to finish before continuining here,
- //But can't figure out the best way. Maybe the use of a Func is not the best way?
- return true;
- }
- IEnumerator ShowText(char[] _lineArray)
- {
- dialogueText.text = "";
- foreach(char c in _lineArray)
- {
- dialogueText.text+= c;
- yield return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement