8000 Events · unity3d-open-tools/openconvo Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Events

Jump to bottom < 7961 a href="/unity3d-open-tools/openconvo/wiki/Events/_edit" data-view-component="true" class="Button--secondary Button--small Button ml-0"> Edit New page
Jeppe Zapp edited this page Jul 30, 2014 · 1 revision

Events in OpenConvo are the logic that you execute during key points of the conversation, e.g. when the speaker changes or when the conversation begins/ends.

First, you create the event handler script and link it to an object. It should be a subclass of OCEventHandler

public class MyEventHandler : OCEventHandler {
}

Let's add some callbacks to the handler

public class MyEventHandler : OCEventHandler {
   public void OnConversationStart ( OCTree tree ) {
      Debug.Log ( "Conversation with " + tree.gameObject.name + " started" );
   }

   public void OnSetSpeaker ( OCSpeaker speaker, OCSpeak node ) {
      // This type of node doesn't change the camera
      if ( node.smalltalk ) {
         Debug.Log ( speaker.name + ": " + node.lines[0].text );
      
      // Only one line, proceed
      } else if ( node.lines.Length == 1 ) {
         Camera.main.transform.LookAt ( speaker.gameObject.transform.position );
         Debug.Log ( speaker.name + ": " + node.lines[0].text );

      // Multiple lines, this is a player choice
      } else {
         for ( int i = 0; i < node.lines.Length; i++ ) {
            uiInstance.SetChoice ( i, node.lines[i].string );
         }
      }
   }

   public void OnConversationEnd () {
      Debug.Log ( "Conversation ended" );
   }
}
Clone this wiki locally
0