riversong code showcase
This commit is contained in:
54
Source/Riversong/Game/UI/Framework/UIControllerSystem.cs
Normal file
54
Source/Riversong/Game/UI/Framework/UIControllerSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[GameSystemGroup(typeof(UISystemGroup))]
|
||||
[InitializeAfter(typeof(UIInitializationSystem))]
|
||||
public abstract class UIControllerSystem : GameSystem, IInitializable
|
||||
{
|
||||
protected UIControllerSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
[field: InjectService] protected UIService UIService { get; }
|
||||
|
||||
protected IUIRoot UIRoot => UIService.UIRoot;
|
||||
|
||||
public virtual UniTask InitializeAsync()
|
||||
{
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
[GameSystemGroup(typeof(UISystemGroup))]
|
||||
[InitializeAfter(typeof(UIInitializationSystem))]
|
||||
public abstract class UIControllerSystem<T> : UIControllerSystem where T : UIView
|
||||
{
|
||||
private Button _closeButton;
|
||||
|
||||
protected UIControllerSystem(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
protected abstract T View { get; }
|
||||
|
||||
public override async UniTask InitializeAsync()
|
||||
{
|
||||
await base.InitializeAsync();
|
||||
|
||||
_closeButton = View.RootElement.Q<Button>(className: "close-button");
|
||||
_closeButton?.RegisterCallback<ClickEvent>(OnCloseButtonClick);
|
||||
}
|
||||
|
||||
private void OnCloseButtonClick(ClickEvent evt)
|
||||
{
|
||||
CloseView();
|
||||
}
|
||||
|
||||
protected virtual void CloseView(bool animate = true)
|
||||
{
|
||||
View.Show(false, animate);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user