Created
November 8, 2023 04:20
-
-
Save trungnhm1998/2c96f3f0131f4af86a40b7e16aefe62a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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