68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
namespace DanieleMarotta.RiversongCodeShowcase
|
|
{
|
|
public class TitleScreenUIController : UIControllerSystem<TitleScreenUIView>, IDisposable
|
|
{
|
|
[InjectService]
|
|
private BuildVersionAsset _buildVersion;
|
|
|
|
[InjectService]
|
|
private ISignalBus _signalBus;
|
|
|
|
public TitleScreenUIController(IServiceLocator serviceLocator) : base(serviceLocator)
|
|
{
|
|
}
|
|
|
|
protected override TitleScreenUIView View => UIRoot.GetView<TitleScreenUIView>();
|
|
|
|
public override async UniTask InitializeAsync()
|
|
{
|
|
await base.InitializeAsync();
|
|
|
|
_signalBus.Subscribe<GameInitializationCompletedSignal>(OnGameInitializationCompleted);
|
|
_signalBus.Subscribe<WorldReadySignal>(OnWorldReady);
|
|
|
|
View.StartGame += OnStartGame;
|
|
View.SetVersion($"v{_buildVersion.CurrentVersion}");
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_signalBus.Unsubscribe<GameInitializationCompletedSignal>(OnGameInitializationCompleted);
|
|
_signalBus.Unsubscribe<WorldReadySignal>(OnWorldReady);
|
|
|
|
View.StartGame -= OnStartGame;
|
|
}
|
|
|
|
private void OnGameInitializationCompleted(GameInitializationCompletedSignal signal)
|
|
{
|
|
_ = View.PlayIntroAsync();
|
|
}
|
|
|
|
private void OnStartGame()
|
|
{
|
|
FadeAndStartGameAsync().Forget();
|
|
}
|
|
|
|
private async UniTask FadeAndStartGameAsync()
|
|
{
|
|
await View.PlayStartFadeAsync(1);
|
|
|
|
_signalBus.Raise(new GameStartedSignal());
|
|
}
|
|
|
|
private void OnWorldReady(WorldReadySignal signal)
|
|
{
|
|
_ = HideWithDelay();
|
|
}
|
|
|
|
private async UniTask HideWithDelay()
|
|
{
|
|
await UniTask.NextFrame();
|
|
|
|
View.Show(false);
|
|
}
|
|
}
|
|
} |