Unity Cookbook
  • 2D
    • New Input System - 2D Move
    • Pixel Sprite Setup
    • Animations
    • Animator in Script
    • Tilemap
    • 2D Camera Follow Player
  • UI OnlyFans
    • 9-Splice Sprite
    • Interactible Game Objects
      • NPCs
      • Items
      • Interactible Marker
    • Dialogue System
      • Conversa Plugin
      • DiaManager.cs
      • DiaTrigger.cs
      • DiaManager.cs Alternate
      • Choices in Dialogue
    • New Input System - Interact
    • Designing the General Menu
    • New Input System - Open Menu
      • UI Buttons
      • GeneralMenu.cs
    • Controls Explanation UI
    • Items Menu
Powered by GitBook
On this page
  • Initial Updates to DiaManager.cs
  • Initial Updates to DiaTrigger.cs
  • Buckle up, Time for Delegates!
  1. UI OnlyFans
  2. Dialogue System

Conversa Plugin

This is for the long and sustainable evolution of the basic things seen before. This is a paid plugin and so this would not apply to everyone.

PreviousDialogue SystemNextDiaManager.cs

Last updated 1 year ago

Reference Link:

Initial Updates to DiaManager.cs

// Add to top of the script
using System;
using Conversa.Runtime.Events;

Initial Updates to DiaTrigger.cs

// Add to top of the script
using Conversa.Runtime;
using Conversa.Runtime.Events;
using Conversa.Runtime.Interfaces;

...

//Inside Class
[SerializeField] private Conversation conversation;
private ConversationRunner runner;

...

//Setting things up
private void Start()
{
	runner = new ConversationRunner(conversation);
	runner.OnConversationEvent.AddListener(HandleConversationEvent);
}

Buckle up, Time for Delegates!

In javascript, you can pass a function as a variable. Not in C#. Now, you have to create a delegate. This video, up to 3:28 will explain the shenanigans. If you go past that, you will get confused.

Just the additional Script added for DiaManager.

//Adding Namespaces required
using System;

...

//Storing the function from the conversation starter script into this one
public delegate void NextMessageDelegate();
private NextMessageDelegate NextMessageFunction;

//Initializing it
private void Start()
{
...
    NextMessageFunction = NextMessage;
}

private void NextMessage()
{
    Debug.Log("Testing out this new thing, yo.");
}

//Having it as a separate function so you can drag and drop it into the PlayerInputComponent
//if the PlayerInputComponent is set to "Invoke Unity Events"
public void Advance(InputAction.CallbackContext ctx)
{
    if (ctx.performed)
    {
        NextMessageFunction();
    }
}

//In the Show Message option that opens up the Dialogue box
public void Show(string actor, string message, Sprite avatar, Action onContinue)
{
    ...
    NextMessageFunction = () => onContinue();
}

Here are some failures I got when trying to set "onContinue" to a function in the DiaManager:

NextMessageFunction = onContinue();

NextMessage = onContinue;
https://github.com/enriquemorenotent/unity-conversa-support/wiki