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