Questnodes
Questnodes are the trigger elements. They work closly together with the Game Scene Controller. After being triggerd once, a Questnode deactivates itself, if multipleTriggering is not set to true. If it is set to true, the Questnode will trigger again if the player leaves and enteres the trigger collider again.
When the scene is loaded, every Questnode registers a function of the Game Scene Controller to its delegate questNodeTriggeredDelegate. It passes itself as an argument when it fires it, so that the Game Scene Controller knows which Quest Node Controller was activated.

If there is a text set in this Questnode, it also registers a function of the Game Scene Controller to its delegate questNodeTextMessageToDisplayDelegate with the text set in the inspector as parameter.
If there is a sound set in the Questnode, then this also happends with the questNodeVoiceToPlayDelegate delegate, which is called voice to play, but should rather be SoundToPlay. #todo
Up to now only the player triggers those Questnodes (since the player has a rigidbody, it will trigger the triggers).
This is the OnTriggerEnter method. I am using here the ? operator behind the delegate method name, which is such a nice way to make sure only to invoke the delegate if there is at least one method listening for the event.
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Player"))
{
this.questNodeTriggeredDelegate?.Invoke(this);
this.questNodeTextMessageToDisplayDelegate?.Invoke(this.questNodeMessage);
this.questNodeVoiceToPlayDelegate?.Invoke(this.questNodeVoiceAudioClip);
if (!this.multipleTriggering)
this.gameObject.SetActive(false);
}
}
Game Scene Controller
Right now the only function of this is that the Game Scene Controller knows when to show a text or a play a sound (voice snippet).
For this he has a delegate called QuestNodeTextMessageToDisplayEventDelegate with a string as parameter.
Right now there is one UI Element, that shows a text for a certain time and then fades it out. This UI Element registers itself to that delegate of the Game Scene Controller.
If the Game Scene Controller receives an event from a Quest node, it fires the event for all elements registered to that delegate.
public void ProcessTextMessageToDisplayQuestNode(string messageToDisplay)
{
this.QuestNodeTextMessageToDisplayEventDelegate(messageToDisplay);
}
ControllerQuestNodeTextMessagePrompter
The QuestNode TextMessage Prompter (yikes, thats a long name, I know) then receives the string to show.
public void ShowQuestNodeMessage(string messageToShow)
{
this.uITextField.gameObject.SetActive(true);
this.uITextField.text = messageToShow;
StartCoroutine("FadeMessageOut");
}
It then starts a coroutine and turns of the text after five seconds.
IEnumerator FadeMessageOut()
{
yield return new WaitForSeconds(5);
this.uITextField.gameObject.SetActive(false);
}
That is all for now. Now this needs to be enhanced. Stay tuned. 😀