117 lines
3.1 KiB
C#
Raw Normal View History

2024-10-16 20:41:40 +08:00
using System.Collections.Generic;
using System.Threading.Tasks;
using Common;
using Cysharp.Threading.Tasks;
using FairyGUI;
2024-10-17 20:36:24 +08:00
using Hall;
using HotScripts.GameScripts.FGui.Scripts.Common;
2024-10-17 01:59:25 +08:00
// using HotScripts.GameLauncher;
using JNGame.Runtime.System;
2024-10-16 20:41:40 +08:00
using MainUI;
using SHFrame;
namespace HotScripts.GameScripts.FGui
{
public enum UILayerEnum
{
2024-10-17 20:36:24 +08:00
View, //页面
Tip, //提示
2024-10-16 20:41:40 +08:00
}
public enum UIID
{
2024-10-17 20:36:24 +08:00
Tip,
Hall
2024-10-16 20:41:40 +08:00
}
/**
* UI
*/
public struct UIConfigStruct
{
public readonly string PkgName;
public readonly string ResName;
public readonly UILayerEnum Layer;
2024-10-17 20:36:24 +08:00
public readonly bool IsOnce;
2024-10-16 20:41:40 +08:00
2024-10-17 20:36:24 +08:00
public UIConfigStruct(string pkgName, string resName, UILayerEnum layer, bool isOnce)
2024-10-16 20:41:40 +08:00
{
PkgName = pkgName;
ResName = resName;
Layer = layer;
2024-10-17 20:36:24 +08:00
IsOnce = isOnce;
2024-10-16 20:41:40 +08:00
}
}
public class FGuiManager : SystemBase
{
private UI_MainUI _mainUI;
public static Dictionary<UIID, UIConfigStruct> UIConfigMap = new();
public static Dictionary<UILayerEnum, GComponent> LayerMap = new();
public override async Task OnInit()
{
await UniTask.DelayFrame(1);
Log.Debug($"UI 初始化中");
2024-10-17 01:59:25 +08:00
// App.EventLauncher.DispatchEvent(HotLauncherEvent.InitSystem,$"UI 初始化中");
2024-10-16 20:41:40 +08:00
BindAll();
BindUI();
await SHFrameModule.UI.AddPackageASync("MainUI");
_mainUI = UI_MainUI.CreateInstance();
_mainUI.MakeFullScreen();
GRoot.inst.AddChildAt(_mainUI,0);
_mainUI.Center();
LayerMap.Add(UILayerEnum.View,_mainUI.m_View);
2024-10-17 20:36:24 +08:00
LayerMap.Add(UILayerEnum.Tip,_mainUI.m_Tip);
2024-10-16 20:41:40 +08:00
}
/// <summary>
/// 绑定UI包
/// </summary>
2024-10-17 20:36:24 +08:00
private async void BindAll()
2024-10-16 20:41:40 +08:00
{
2024-10-17 20:36:24 +08:00
//加载依赖包
await SHFrameModule.UI.AddPackageASync("Common");
2024-10-16 20:41:40 +08:00
CommonBinder.BindAll();
2024-10-17 20:36:24 +08:00
MainUIBinder.BindAll();
HallBinder.BindAll();
2024-10-16 20:41:40 +08:00
}
/// <summary>
/// 绑定UI配置
/// </summary>
private void BindUI()
{
2024-10-17 20:36:24 +08:00
UIConfigMap.Add(UIID.Tip,new UIConfigStruct("Common", "TipTitleUI", UILayerEnum.Tip,false));
UIConfigMap.Add(UIID.Hall,new UIConfigStruct("Hall", "HallUI", UILayerEnum.View,true));
2024-10-16 20:41:40 +08:00
}
2024-10-17 20:36:24 +08:00
/// <summary>
/// 打开页面
/// </summary>
2024-10-16 20:41:40 +08:00
public async UniTask Open<TClassType>(UIID id, params object[] param)
where TClassType : UIBase, new()
{
if (!UIConfigMap.ContainsKey(id)) return;
var config = UIConfigMap[id];
await SHFrameModule.UI.Open<TClassType>(config.PkgName, config.ResName, LayerMap[config.Layer], param);
}
2024-10-17 20:36:24 +08:00
/// <summary>
/// 打开提示
/// </summary>
public void Tip(string title)
{
Open<TipTitleUI>(UIID.Tip,title).Forget();
}
2024-10-16 20:41:40 +08:00
}
}