76 lines
2.2 KiB
C#
76 lines
2.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using PrimeTween;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Hallucinate.UI
|
|
{
|
|
public abstract class BaseUIController : ScriptableObject
|
|
{
|
|
protected VisualElement root;
|
|
protected UIManager uiManager;
|
|
|
|
public VisualElement Root => root; // Thêm thuộc tính này
|
|
|
|
public virtual void Initialize(VisualElement uxmlRoot, UIManager manager)
|
|
{
|
|
root = uxmlRoot;
|
|
uiManager = manager;
|
|
|
|
// Đảm bảo ban đầu ẩn hết
|
|
Hide();
|
|
|
|
// Tự động gán âm thanh phản hồi cho các UI elements
|
|
UIAudioHelper.BindFeedback(root);
|
|
}
|
|
|
|
public virtual void Show()
|
|
{
|
|
if (root != null)
|
|
{
|
|
root.style.display = DisplayStyle.Flex;
|
|
root.style.opacity = 1;
|
|
}
|
|
}
|
|
|
|
public virtual void Hide()
|
|
{
|
|
if (root != null)
|
|
{
|
|
root.style.display = DisplayStyle.None;
|
|
}
|
|
}
|
|
|
|
protected string GetLoc(string key)
|
|
{
|
|
if (LocalizationManager.Instance != null)
|
|
return LocalizationManager.Instance.GetLocalizedString(key);
|
|
return key;
|
|
}
|
|
|
|
public virtual void Update() { }
|
|
|
|
public virtual async Task PlayTransitionIn()
|
|
{
|
|
if (root == null) return;
|
|
|
|
Show();
|
|
// Reset vị trí mặc định để tránh lỗi trôi màn hình
|
|
root.style.translate = new StyleTranslate(new Translate(Length.Percent(100), 0));
|
|
|
|
await Tween.Custom(100f, 0f, duration: 0.5f, ease: Ease.OutBack,
|
|
onValueChange: val => root.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
|
|
}
|
|
|
|
public virtual async Task PlayTransitionOut()
|
|
{
|
|
if (root == null) return;
|
|
|
|
await Tween.Custom(0f, -100f, duration: 0.5f, ease: Ease.InBack,
|
|
onValueChange: val => root.style.translate = new StyleTranslate(new Translate(Length.Percent(val), 0)));
|
|
|
|
Hide();
|
|
}
|
|
}
|
|
}
|