Skip to content

Instantly share code, notes, and snippets.

@trungnhm1998
Created November 8, 2023 04:20
Show Gist options
  • Save trungnhm1998/2c96f3f0131f4af86a40b7e16aefe62a to your computer and use it in GitHub Desktop.
Save trungnhm1998/2c96f3f0131f4af86a40b7e16aefe62a to your computer and use it in GitHub Desktop.
using System.Collections;
using CryptoQuest.System.Dialogue.Events;
using UnityEngine;
using Yarn.Unity;
namespace CryptoQuest.System.Dialogue.YarnManager
{
public class DialogRunnerController : MonoBehaviour
{
[SerializeField] private DialogueRunner _dialogueRunner;
[SerializeField] private UnityLocalisedLineProvider _localisedLineProvider;
[Header("listeners")]
[SerializeField] private YarnProjectConfigEvent _onYarnProjectConfigEvent;
private void OnEnable()
{
_onYarnProjectConfigEvent.ConfigRequested += OnConfigRequested;
}
private void OnDisable()
{
_onYarnProjectConfigEvent.ConfigRequested -= OnConfigRequested;
}
private void OnConfigRequested(YarnProjectConfigSO currentConfig)
{
StartCoroutine(LoadTableCo(currentConfig));
}
private IEnumerator LoadTableCo(YarnProjectConfigSO config)
{
var handle = config.StringTable.GetTableAsync();
yield return handle;
_dialogueRunner.yarnProject = config.YarnProject;
_dialogueRunner.SetProject(config.YarnProject);
_localisedLineProvider.SetStringTable(config.StringTable);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment