riversong code showcase
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user