Organize custom scripts under Assets/Baba_yaga and merge Opsive folders to Assets root
This commit is contained in:
78
Assets/Baba_yaga/UI/BaseUIController.cs
Normal file
78
Assets/Baba_yaga/UI/BaseUIController.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using PrimeTween;
|
||||
using System.Threading.Tasks;
|
||||
using DG.Tweening;
|
||||
using Tween = PrimeTween.Tween;
|
||||
using Ease = PrimeTween.Ease;
|
||||
|
||||
namespace Baba_yaga.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();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user