Page 1 of 1
How to check for Start and End of conversation via code
Posted: Mon Oct 14, 2024 3:47 am
by Saper
Hi Tony
I want to setup a variable to change on "Start" and "End" of every conversation. I found events:
- OnConversationStart()
- OnConversationEnd()
can I setup my variable by monitoring those events?
Also if i use method "DialogueManager.StopConversation()", OnConversationEnd() would be propagated or not?
Also is there another method to check for end and start of conversation?
Re: How to check for Start and End of conversation via code
Posted: Mon Oct 14, 2024 7:37 am
by DarkProphet
I believe this is what you're looking for:
Code: Select all
DialogueManager.instance.conversationStarted += MyConversationStarted;
DialogueManager.instance.conversationEnded += MyConversationEnded;
// make your own functions like this:
private void MyConversationEnded(Transform t){}
Hope that helps!
PS: Remember to unsubscribe (-=) to the events in OnDestroy or whatever, depending on how your code works!
Code: Select all
DialogueManager.instance.conversationStarted -= MyConversationStarted;
Re: How to check for Start and End of conversation via code
Posted: Mon Oct 14, 2024 11:28 am
by Saper
I was thinking about somthing like this:
Code: Select all
public class DialogueConversationMonitor : InjectableMonoBehaviour
{
public override void DependenciesResolved()
{
EventSystem.Receive<OnConversationStart>().Subscribe(x => ChangeConversationStateToTrue()).AddTo(this);
EventSystem.Receive<OnConversationEnd>().Subscribe(x => ChangeConversationStateToFalse()).AddTo(this);
}
private void Update()
{
}
private void ChangeConversationStateToTrue()
{
DialogueLua.SetVariable("InConversation", true);
}
private void ChangeConversationStateToFalse()
{
DialogueLua.SetVariable("InConversation", false);
}
}
Re: How to check for Start and End of conversation via code
Posted: Mon Oct 14, 2024 12:00 pm
by Tony Li
Hi,
No need for that. I recommend DarkProphet's method above.