MOD!
This commit is contained in:
15
Assets/Scripts/MainGame/UI/Base/UIElementBase.cs
Normal file
15
Assets/Scripts/MainGame/UI/Base/UIElementBase.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis
|
||||
{
|
||||
public abstract class UIElementBase : MonoBehaviour
|
||||
{
|
||||
public RectTransform rectTransform;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
rectTransform ??= GetComponent<RectTransform>();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MainGame/UI/Base/UIElementBase.cs.meta
Normal file
2
Assets/Scripts/MainGame/UI/Base/UIElementBase.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71ebe269450f5dd46996e789ea821f9e
|
||||
37
Assets/Scripts/MainGame/UI/Base/UIManagerBase.cs
Normal file
37
Assets/Scripts/MainGame/UI/Base/UIManagerBase.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis
|
||||
{
|
||||
public abstract partial class UIManagerBase : Singleton<UIManagerBase>
|
||||
{
|
||||
[Header("UI Prefabs")]
|
||||
public Dictionary<string, GameObject> uiElementPrefabs = new Dictionary<string, GameObject>();
|
||||
public Dictionary<string, GameObject> uiPagePrefabs = new Dictionary<string, GameObject>();
|
||||
|
||||
[Header("Pages")]
|
||||
public List<UIPageBase> uiPageList = new List<UIPageBase>(); // 用于管理UI堆栈
|
||||
|
||||
[Header("Canvas")]
|
||||
public Canvas mainCanvas;
|
||||
public RectTransform canvasTransform;
|
||||
}
|
||||
|
||||
public partial class UIManagerBase
|
||||
{
|
||||
public T ShowPage<T>(string pageName) where T : UIPageBase
|
||||
{
|
||||
GameObject prefab = uiPagePrefabs[pageName];
|
||||
GameObject uiInstance = Instantiate(prefab, canvasTransform);
|
||||
T page = uiInstance.GetComponent<T>();
|
||||
|
||||
page.Initialize(this);
|
||||
page.Show();
|
||||
|
||||
// ... 处理层级 ...
|
||||
return page;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MainGame/UI/Base/UIManagerBase.cs.meta
Normal file
2
Assets/Scripts/MainGame/UI/Base/UIManagerBase.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 263bd9d6ba87e1542b8fdf608cc1e6e1
|
||||
36
Assets/Scripts/MainGame/UI/Base/UIPageBase.cs
Normal file
36
Assets/Scripts/MainGame/UI/Base/UIPageBase.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis
|
||||
{
|
||||
public abstract class UIPageBase : UIElementBase
|
||||
{
|
||||
public UIManagerBase uiManager;
|
||||
public CanvasGroup canvasGroup;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
Initialize(transform.parent.GetComponent<UIManagerBase>());
|
||||
}
|
||||
|
||||
public virtual void Initialize(UIManagerBase sourceManager)
|
||||
{
|
||||
if (sourceManager != null)
|
||||
{
|
||||
this.uiManager ??= sourceManager;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Show()
|
||||
{
|
||||
uiManager.uiPageList.Add(this);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public virtual void Close()
|
||||
{
|
||||
uiManager.uiPageList.Remove(this);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/MainGame/UI/Base/UIPageBase.cs.meta
Normal file
2
Assets/Scripts/MainGame/UI/Base/UIPageBase.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc4ec09be17fda745b0a5af6ec675912
|
||||
36
Assets/Scripts/MainGame/UI/Base/WaitableUIElement.cs
Normal file
36
Assets/Scripts/MainGame/UI/Base/WaitableUIElement.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis
|
||||
{
|
||||
public class WaitableUIElement : UIElementBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示该UI面板。
|
||||
/// </summary>
|
||||
public virtual void Show()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏该UI面板。
|
||||
/// </summary>
|
||||
public virtual void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个“确认”事件的 Observable。
|
||||
/// 这个 Observable 会在玩家做出确认操作(例如点击按钮)时发出一个信号并完成。
|
||||
/// 指令队列将等待这个 Observable 完成。
|
||||
/// </summary>
|
||||
/// <returns>代表确认事件的 Observable 流。</returns>
|
||||
public virtual IObservable<Unit> OnConfirm()
|
||||
{
|
||||
return Observable.ReturnUnit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 564bf781b725208459f5e2625f975819
|
||||
Reference in New Issue
Block a user