Skip to content

Instantly share code, notes, and snippets.

@trungnhm1998
Created November 10, 2023 05:04
Show Gist options
  • Save trungnhm1998/d0afba1b4d9b9c5157ef055fc99ea936 to your computer and use it in GitHub Desktop.
Save trungnhm1998/d0afba1b4d9b9c5157ef055fc99ea936 to your computer and use it in GitHub Desktop.
using System.Collections;
using CryptoQuest.Battle.UI.Logs;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace CryptoQuest.Battle.Presenter.Commands
{
public class PresentLogCommand : IPresentCommand
{
private readonly LocalizedString _message;
private readonly LogPresenter _presenter;
private string _loadedMessage;
private AsyncOperationHandle<string> _handle;
public PresentLogCommand(LogPresenter presenter, LocalizedString message)
{
_presenter = presenter;
_message = message;
}
public IEnumerator Load()
{
_handle = _message.GetLocalizedStringAsync();
yield return _handle;
_loadedMessage = _handle.Result;
}
public IEnumerator Present()
{
if (_handle.IsValid() && _handle.IsDone == false)
yield return _handle;
_loadedMessage = _handle.Result;
_presenter.Append(_loadedMessage);
yield return new WaitForSeconds(_presenter.DelayBetweenLines);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment