riversong code showcase
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class PausePopupUIController : UIControllerSystem<PausePopupUIView>, IDisposable
|
||||
{
|
||||
[InjectService]
|
||||
private ICancelAction _cancelAction;
|
||||
|
||||
public PausePopupUIController(IServiceLocator serviceLocator) : base(serviceLocator)
|
||||
{
|
||||
}
|
||||
|
||||
protected override PausePopupUIView View => UIRoot.GetView<PausePopupUIView>();
|
||||
|
||||
public override async UniTask InitializeAsync()
|
||||
{
|
||||
await base.InitializeAsync();
|
||||
|
||||
View.Show(false);
|
||||
|
||||
View.FeedbackButtonClick += OnFeedbackButtonClick;
|
||||
View.QuitButtonClick += OnQuitButtonClick;
|
||||
|
||||
_cancelAction.AddHandler(
|
||||
(int)CancelActions.PauseMenu,
|
||||
cancelActionType =>
|
||||
{
|
||||
if (cancelActionType != CancelActionType.EscapeKey) return false;
|
||||
|
||||
View.Toggle(true);
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
View.FeedbackButtonClick -= OnFeedbackButtonClick;
|
||||
View.QuitButtonClick -= OnQuitButtonClick;
|
||||
}
|
||||
|
||||
private void OnFeedbackButtonClick()
|
||||
{
|
||||
Application.OpenURL(AppLinks.DemoFeedbackUrl);
|
||||
}
|
||||
|
||||
private void OnQuitButtonClick()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
[UIView("pause-popup")]
|
||||
public class PausePopupUIView : UIView
|
||||
{
|
||||
private Button _feedbackButton;
|
||||
|
||||
private Button _quitButton;
|
||||
|
||||
private EventCallback<ClickEvent> _onFeedbackButtonClick;
|
||||
|
||||
private EventCallback<ClickEvent> _onQuitButtonClick;
|
||||
|
||||
public event Action FeedbackButtonClick;
|
||||
|
||||
public event Action QuitButtonClick;
|
||||
|
||||
public override UniTask InitializeAsync(UIService uiService, VisualElement rootElement)
|
||||
{
|
||||
base.InitializeAsync(uiService, rootElement);
|
||||
|
||||
_feedbackButton = rootElement.Q<Button>(className: "pause-popup__feedback-button");
|
||||
_onFeedbackButtonClick = _ => FeedbackButtonClick?.Invoke();
|
||||
_feedbackButton.RegisterCallback(_onFeedbackButtonClick);
|
||||
|
||||
_quitButton = rootElement.Q<Button>(className: "pause-popup__quit-button");
|
||||
_onQuitButtonClick = _ => QuitButtonClick?.Invoke();
|
||||
_quitButton.RegisterCallback(_onQuitButtonClick);
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_feedbackButton?.UnregisterCallback(_onFeedbackButtonClick);
|
||||
_quitButton?.UnregisterCallback(_onQuitButtonClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user