mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交完美
This commit is contained in:
@@ -4,6 +4,13 @@ namespace SHFrame
|
||||
{
|
||||
public abstract class UIBase
|
||||
{
|
||||
//当前UIBase Id
|
||||
public string PkgName;
|
||||
//当前UIBase Id
|
||||
public string ResName;
|
||||
//当前UIBase Id
|
||||
public int Id;
|
||||
|
||||
public string PanelName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -52,5 +59,10 @@ namespace SHFrame
|
||||
View = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
SHFrameModule.UI.Close(PkgName,ResName,Id);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,19 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SHFrame
|
||||
{
|
||||
|
||||
public class UIModule : Module
|
||||
{
|
||||
public readonly Dictionary<string, UIBase> UIMap = new();
|
||||
|
||||
private int id = 1;
|
||||
|
||||
public readonly Dictionary<string, List<UIBase>> UIMap = new();
|
||||
private FairyGUILoader m_FguiLoader;
|
||||
public string CurKey { private set; get; } = "";
|
||||
|
||||
private GComponent ViewRoot { get; set; }
|
||||
|
||||
|
||||
private float lastwidth = 0f;
|
||||
private float lastheight = 0f;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (lastwidth != Screen.width || lastheight != Screen.height)
|
||||
{
|
||||
lastwidth = Screen.width;
|
||||
lastheight = Screen.height;
|
||||
Log.Debug("Resolution :" + Screen.width + " X" + Screen.height);
|
||||
foreach (var uiList in UIMap.Values)
|
||||
{
|
||||
uiList.ForEach(item =>
|
||||
{
|
||||
if (item.View is not null)
|
||||
{
|
||||
item.View.MakeFullScreen();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 游戏框架模块初始化。
|
||||
@@ -53,7 +81,7 @@ namespace SHFrame
|
||||
{
|
||||
return m_FguiLoader.AddPackageAsync(packageName);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 通过UIManager打开UI
|
||||
/// </summary>
|
||||
@@ -69,13 +97,21 @@ namespace SHFrame
|
||||
|
||||
var key = pkgName + "/" + resName;
|
||||
|
||||
UIMap.TryGetValue(key, out var uiClass);
|
||||
UIMap.TryGetValue(key, out var uiList);
|
||||
|
||||
if (uiClass == null)
|
||||
if (uiList == null)
|
||||
{
|
||||
uiClass = new TClassType();
|
||||
UIMap.Add(key, uiClass);
|
||||
uiList = new List<UIBase>();
|
||||
UIMap.Add(key,uiList);
|
||||
}
|
||||
|
||||
var uiClass = new TClassType
|
||||
{
|
||||
ResName = resName,
|
||||
PkgName = pkgName,
|
||||
Id = id++
|
||||
};
|
||||
uiList.Add(uiClass);
|
||||
|
||||
if (uiClass.View == null)
|
||||
{
|
||||
@@ -84,7 +120,7 @@ namespace SHFrame
|
||||
// uiClass.View.SetScale(ScaleT, ScaleT);
|
||||
// uiClass.View.SetSize(GRoot.inst.width / ScaleT, GRoot.inst.height / ScaleT);
|
||||
uiClass.View.MakeFullScreen();
|
||||
UIMap[key].OnInit();
|
||||
uiClass.OnInit();
|
||||
}
|
||||
|
||||
// root.RemoveChildren();
|
||||
@@ -101,7 +137,6 @@ namespace SHFrame
|
||||
uiClass.View.y = 0;
|
||||
uiClass.View.name = resName;
|
||||
uiClass.OnOpen(param);
|
||||
// uiClass.RemoveListener();
|
||||
uiClass.AddListener();
|
||||
CurKey = key;
|
||||
}
|
||||
@@ -115,13 +150,13 @@ namespace SHFrame
|
||||
/// <summary>
|
||||
/// 关闭通过UIManager打开的UI
|
||||
/// </summary>
|
||||
public void Close(string pkgName, string resName)
|
||||
public void Close(string pkgName, string resName,int index = 0)
|
||||
{
|
||||
var key = pkgName + "/" + resName;
|
||||
|
||||
if (key == "" || !UIMap.ContainsKey(key)) return;
|
||||
|
||||
Close(key);
|
||||
Close(key,index);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
@@ -129,17 +164,23 @@ namespace SHFrame
|
||||
Close(CurKey);
|
||||
}
|
||||
|
||||
public void Close(string key)
|
||||
public void Close(string key,int index = 0)
|
||||
{
|
||||
if (key == "" || !UIMap.ContainsKey(key)) return;
|
||||
|
||||
if (UIMap[key].View == null || UIMap[key].View.parent == null) return;
|
||||
|
||||
UIMap[key].View.parent.RemoveChild(UIMap[key].View);
|
||||
UIMap[key].OnClose();
|
||||
UIMap[key].RemoveListener();
|
||||
UIMap[key].OnDispose();
|
||||
UIMap.Remove(key);
|
||||
var uiList = UIMap[key];
|
||||
foreach (var item in uiList.ToArray())
|
||||
{
|
||||
if (index == item.Id || index == 0)
|
||||
{
|
||||
uiList.Remove(item);
|
||||
if (item.View?.parent == null) return;
|
||||
item.View.parent.RemoveChild(item.View);
|
||||
item.OnClose();
|
||||
item.RemoveListener();
|
||||
item.OnDispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseAll()
|
||||
|
Reference in New Issue
Block a user