初始化

This commit is contained in:
come
2025-07-26 16:56:42 +08:00
parent 8291dbb91c
commit fa81439a8c
2574 changed files with 328492 additions and 2170 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f5cf9acb13b24a3a8cf1e03d88138fb5
timeCreated: 1681977795

View File

@@ -0,0 +1,17 @@
using Sirenix.OdinInspector;
namespace YIUIFramework
{
[LabelText("组件类型")]
public enum EUICodeType
{
[LabelText("Panel 面板")]
Panel,
[LabelText("View 界面")]
View,
[LabelText("Component 组件")]
Component,
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e337ad83123e4e5bba290b61e07903ad
timeCreated: 1682427307

View File

@@ -0,0 +1,102 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using YIUIBind;
using UnityEngine;
namespace YIUIFramework
{
//[DetailedInfoBox("UI CDE总表 点击展开详细介绍", @"李胜扬")]
[Serializable]
[LabelText("UI CDE总表")]
[AddComponentMenu("YIUIBind/★★★★★UI CDE Table 总表★★★★★")]
public sealed partial class UIBindCDETable : SerializedMonoBehaviour
{
#if UNITY_EDITOR
[InlineButton("AddComponentTable", "Add")]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
public UIBindComponentTable ComponentTable;
#if UNITY_EDITOR
[InlineButton("AddDataTable", "Add")]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
public UIBindDataTable DataTable;
#if UNITY_EDITOR
[InlineButton("AddEventTable", "Add")]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
#endif
public UIBindEventTable EventTable;
[LabelText("UI包名")]
[ReadOnly]
public string PkgName;
[LabelText("UI资源名")]
[ReadOnly]
public string ResName;
#region
//关联的UI
private UIBase m_UIBase;
[OdinSerialize]
[LabelText("编辑时所有公共组件")]
[ReadOnly]
[PropertyOrder(1000)] //生成UI类时使用
#if UNITY_EDITOR
[ShowIf("@UIOperationHelper.CommonShowIf()")]
#endif
internal List<UIBindCDETable> AllChildCdeTable = new List<UIBindCDETable>();
[OdinSerialize]
[NonSerialized]
[ShowInInspector]
[ReadOnly]
[PropertyOrder(1000)]
[LabelText("运行时所有公共组件")] //动态生成后的子类(公共组件) 运行时使用
#if UNITY_EDITOR
[HideIf("@UIOperationHelper.CommonShowIf()")]
#endif
private Dictionary<string, UIBase> m_AllChildUIBase = new Dictionary<string, UIBase>();
internal void AddUIBase(string uiName, UIBase uiBase)
{
if (m_AllChildUIBase.ContainsKey(uiName))
{
Debug.LogError($"{name} 已存在 {uiName} 请检查为何重复添加 是否存在同名组件");
return;
}
m_AllChildUIBase.Add(uiName, uiBase);
}
internal UIBase FindUIBase(string uiName)
{
if (!m_AllChildUIBase.ContainsKey(uiName))
{
Debug.LogError($"{name} 不存在 {uiName} 请检查");
return null;
}
return m_AllChildUIBase[uiName];
}
public T FindUIBase<T>(string uiName) where T : UIBase
{
return (T)FindUIBase(uiName);
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 76af6b314c984a70bd77fd9c0d998f89
timeCreated: 1681228108

View File

@@ -0,0 +1,328 @@
#if UNITY_EDITOR
using System;
using System.Reflection;
using Sirenix.OdinInspector;
using YIUIBind;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using YIUIFramework.Editor;
namespace YIUIFramework
{
//Editor
public sealed partial class UIBindCDETable
{
#region
[LabelText("组件类型")]
[OnValueChanged("OnValueChangedEUICodeType")]
[ReadOnly]
public EUICodeType UICodeType = EUICodeType.Component;
[BoxGroup("配置", true, true)]
[HideIf("UICodeType", EUICodeType.Component)]
[LabelText("窗口选项")]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EWindowOption WindowOption = EWindowOption.None;
[ShowIf("UICodeType", EUICodeType.Panel)]
[BoxGroup("配置", true, true)]
[OnValueChanged("OnValueChangedEPanelLayer")]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EPanelLayer PanelLayer = EPanelLayer.Panel;
[ShowIf("UICodeType", EUICodeType.Panel)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EPanelOption PanelOption = EPanelOption.None;
[ShowIf("UICodeType", EUICodeType.Panel)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EPanelStackOption PanelStackOption = EPanelStackOption.VisibleTween;
[ShowIf("UICodeType", EUICodeType.View)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EViewWindowType ViewWindowType = EViewWindowType.View;
[ShowIf("UICodeType", EUICodeType.View)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public EViewStackOption ViewStackOption = EViewStackOption.VisibleTween;
[ShowIf("ShowCachePanelTime", EUICodeType.Panel)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[LabelText("缓存时间")]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public float CachePanelTime = 10;
private bool ShowCachePanelTime => PanelOption.HasFlag(EPanelOption.TimeCache);
[LabelText("同层级时 优先级高的在前面")] //相同时后开的在前
[ShowIf("UICodeType", EUICodeType.Panel)]
[BoxGroup("配置", true, true)]
[GUIColor(0, 1, 1)]
[EnableIf("@UIOperationHelper.CommonShowIf()")]
public int Priority = 0;
private void OnValueChangedEUICodeType()
{
if (name.EndsWith(UIStaticHelper.UIPanelName) || name.EndsWith(UIStaticHelper.UIPanelSourceName))
{
if (UICodeType != EUICodeType.Panel)
{
Debug.LogWarning($"{name} 结尾{UIStaticHelper.UIPanelName} 必须设定为{UIStaticHelper.UIPanelName}类型");
}
UICodeType = EUICodeType.Panel;
}
else if (name.EndsWith(UIStaticHelper.UIViewName))
{
if (UICodeType != EUICodeType.View)
{
Debug.LogWarning($"{name} 结尾{UIStaticHelper.UIViewName} 必须设定为{UIStaticHelper.UIViewName}类型");
}
UICodeType = EUICodeType.View;
}
else
{
if (UICodeType != EUICodeType.Component)
{
Debug.LogWarning($"{name} 想设定为其他类型 请按照规则设定 请勿强行修改");
}
UICodeType = EUICodeType.Component;
}
}
private void OnValueChangedEPanelLayer()
{
if (PanelLayer >= EPanelLayer.Cache)
{
Debug.LogError($" {name} 层级类型 选择错误 请重新选择");
PanelLayer = EPanelLayer.Panel;
}
}
#endregion
private bool ShowAutoCheckBtn()
{
if (!UIOperationHelper.CheckUIOperation(false)) return false;
return true;
}
[GUIColor(1, 1, 0)]
[Button("自动检查所有", 30)]
[PropertyOrder(-100)]
[ShowIf("ShowAutoCheckBtn")]
private void AutoCheckBtn()
{
AutoCheck();
}
[GUIColor(1, 1, 1)]
[Button("重置子预制", 20)]
[PropertyOrder(-100)]
[ShowIf("ShowAutoCheckBtn")]
private void RevertPrefabInstance()
{
UnityTipsHelper.CallBack("将会重置所有子CDE 还原到预制初始状态 \n(防止嵌套预制修改)",
() =>
{
UICreateModule.RefreshChildCdeTable(this);
foreach (var cdeTable in AllChildCdeTable)
{
try
{
PrefabUtility.RevertPrefabInstance(cdeTable.gameObject, InteractionMode.AutomatedAction);
}
catch (Exception e)
{
Debug.LogError($"这个CDETable 不是预制体 请检查 {cdeTable.name}\n{e.Message}", cdeTable.gameObject);
}
}
});
}
[GUIColor(0, 1, 1)]
[Button("保存选中", 50)]
[PropertyOrder(-100)]
[HideIf("ShowCreateBtn")]
private void SaveSelectSelf()
{
var stage = PrefabStageUtility.GetPrefabStage(gameObject);
if (stage == null)
{
Debug.LogError($"未知错误 没有找到预制 {gameObject.name}");
return;
}
var methodInfo = stage.GetType().GetMethod("Save", BindingFlags.Instance | BindingFlags.NonPublic);
if (methodInfo != null)
{
bool result = (bool)methodInfo.Invoke(stage, null);
if (!result)
{
Debug.LogError("自动保存失败 注意请手动保存");
}
}
else
{
Debug.LogError("Save方法不存在 自动保存失败 注意请手动保存");
}
var assetObj = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(stage.assetPath);
EditorGUIUtility.PingObject(assetObj);
Selection.activeObject = assetObj;
}
internal bool AutoCheck()
{
if (!UIOperationHelper.CheckUIOperation(this)) return false;
if (!UICreateModule.InitVoName(this)) return false;
OnValueChangedEUICodeType();
OnValueChangedEPanelLayer();
if (UICodeType == EUICodeType.Panel && IsSplitData)
{
PanelSplitData.Panel = gameObject;
if (!PanelSplitData.AutoCheck()) return false;
}
UICreateModule.RefreshChildCdeTable(this);
ComponentTable?.AutoCheck();
DataTable?.AutoCheck();
EventTable?.AutoCheck();
return true;
}
private bool ShowCreateBtnByHierarchy()
{
if (string.IsNullOrEmpty(PkgName) || string.IsNullOrEmpty(ResName)) return false;
if (ResName.Contains("Source")) return false;
if (!UIOperationHelper.CheckUIOperation(this, false)) return false;
return !PrefabUtility.IsPartOfPrefabAsset(this);
}
[GUIColor(0f, 0.5f, 1f)]
[Button("生成", 50)]
[ShowIf("ShowCreateBtnByHierarchy")]
internal void CreateUICodeByHierarchy()
{
if (!ShowCreateBtnByHierarchy()) return;
var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
if (prefabStage == null)
{
Debug.LogError($"当前不在预制体编辑器模式下");
return;
}
var path = prefabStage.assetPath;
var root = prefabStage.prefabContentsRoot;
PrefabUtility.SaveAsPrefabAsset(root, path, out var success);
if (!success)
{
Debug.LogError("快捷保存失败 请检查");
return;
}
prefabStage.ClearDirtiness();
var cdeTable = AssetDatabase.LoadAssetAtPath<UIBindCDETable>(path);
if (cdeTable == null) return;
cdeTable.CreateUICode();
AssetDatabase.OpenAsset(cdeTable);
}
private bool ShowCreateBtn()
{
if (IsSplitData) return false;
if (!UIOperationHelper.CheckUIOperationAll(this, false)) return false;
return true;
}
[GUIColor(0.7f, 0.4f, 0.8f)]
[Button("生成", 50)]
[ShowIf("ShowCreateBtn")]
internal void CreateUICode()
{
if (!UIOperationHelper.CheckUIOperation(this)) return;
CreateUICode(true, true);
}
private bool ShowPanelSourceSplit()
{
if (!UIOperationHelper.CheckUIOperationAll(this, false)) return false;
return IsSplitData;
}
[GUIColor(0f, 0.4f, 0.8f)]
[Button("源数据拆分", 50)]
[ShowIf("ShowPanelSourceSplit")]
internal void PanelSourceSplit()
{
if (!UIOperationHelper.CheckUIOperation(this)) return;
if (IsSplitData)
{
if (AutoCheck())
{
UIPanelSourceSplit.Do(this);
}
}
else
{
UnityTipsHelper.ShowError($"{name} 当前数据不是源数据 无法进行拆分 请检查数据");
}
}
internal void CreateUICode(bool refresh, bool tips)
{
UICreateModule.Create(this, refresh, tips);
}
private void OnValidate()
{
ComponentTable ??= GetComponent<UIBindComponentTable>();
DataTable ??= GetComponent<UIBindDataTable>();
EventTable ??= GetComponent<UIBindEventTable>();
}
private void AddComponentTable()
{
if (!UIOperationHelper.CheckUIOperation()) return;
ComponentTable = gameObject.GetOrAddComponent<UIBindComponentTable>();
}
private void AddDataTable()
{
if (!UIOperationHelper.CheckUIOperation()) return;
DataTable = gameObject.GetOrAddComponent<UIBindDataTable>();
}
private void AddEventTable()
{
if (!UIOperationHelper.CheckUIOperation()) return;
EventTable = gameObject.GetOrAddComponent<UIBindEventTable>();
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dc56a5993b8c4d65aba9966b4389ecfd
timeCreated: 1685499334

View File

@@ -0,0 +1,84 @@
using System;
using UnityEngine;
namespace YIUIFramework
{
//生命周期
public sealed partial class UIBindCDETable
{
/// <summary>
/// 关联UIBase
/// 由UIBase初始化后调用
/// 目前还没用 预留这里而已 不知道以后是否会有用
/// </summary>
internal void BindUIBase(UIBase uiBase)
{
if (m_UIBase != null)
{
Debug.LogError($"{gameObject.name} m_UIBase 已存在 请检查为何重复调用");
}
m_UIBase = uiBase;
}
internal Action UIBaseOnEnable;
private void OnEnable()
{
try
{
UIBaseOnEnable?.Invoke();
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
}
internal Action UIBaseStart;
private void Start()
{
try
{
UIBaseStart?.Invoke();
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
}
internal Action UIBaseOnDisable;
private void OnDisable()
{
try
{
UIBaseOnDisable?.Invoke();
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
}
internal Action UIBaseOnDestroy;
private void OnDestroy()
{
try
{
UIBaseOnDestroy?.Invoke();
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 27ce269d96c04f9180948aa332daca61
timeCreated: 1685499423

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using YIUIBind;
using UnityEngine;
namespace YIUIFramework
{
//Panel的分块数据
public sealed partial class UIBindCDETable
{
[OdinSerialize]
[LabelText("源数据")]
[ReadOnly]
#if !YIUIMACRO_BIND_RUNTIME_EDITOR
[HideInInspector]
#endif
internal bool IsSplitData;
//源数据 拆分前的源数据
[ShowInInspector]
[HideLabel]
[BoxGroup("面板拆分数据", centerLabel: true)]
[OdinSerialize]
#if UNITY_EDITOR
[ShowIf("ShowPanelSplitData")]
#endif
internal UIPanelSplitData PanelSplitData = new UIPanelSplitData();
#if UNITY_EDITOR
private bool ShowPanelSplitData => IsSplitData && UICodeType == EUICodeType.Panel;
//拆分后的引用数据
[ShowInInspector]
[HideLabel]
[BoxGroup("面板拆分数据", centerLabel: true)]
[OdinSerialize]
[HideIf("HidePanelSplitData")]
[ReadOnly] //就是一个只读的 展示用数据 请不要使用此数据 或修改数据
internal UIPanelSplitData PanelSplitEditorShowData;
private bool HidePanelSplitData => IsSplitData || UICodeType != EUICodeType.Panel;
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0b2b83a76b2d47dd8f9c315b4f345ad0
timeCreated: 1685499635

View File

@@ -0,0 +1,40 @@
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 面板拆分数据
/// 主要做分块加载
/// </summary>
[HideReferenceObjectPicker]
[HideLabel]
public sealed partial class UIPanelSplitData
{
[HideInInspector]
public GameObject Panel;
[BoxGroup("通用界面", centerLabel: true)]
[LabelText("所有子界面父对象")]
[ReadOnly]
public RectTransform AllViewParent;
[BoxGroup("通用界面", centerLabel: true)]
[LabelText("所有通用界面(已存在不创建的)")]
public List<RectTransform> AllCommonView = new List<RectTransform>();
[BoxGroup("通用界面", centerLabel: true)]
[LabelText("所有需要被创建的界面")]
public List<RectTransform> AllCreateView = new List<RectTransform>();
[BoxGroup("弹窗界面", centerLabel: true)]
[LabelText("所有弹出界面父级")]
[ReadOnly]
public RectTransform AllPopupViewParent;
[BoxGroup("弹窗界面", centerLabel: true)]
[LabelText("所有弹出界面")]
public List<RectTransform> AllPopupView = new List<RectTransform>();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8ff53ae7ba11434bb3aee38b3010aa48
timeCreated: 1683700753

View File

@@ -0,0 +1,240 @@
#if UNITY_EDITOR
using System.Collections.Generic;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;
using YIUIBind;
namespace YIUIFramework
{
public sealed partial class UIPanelSplitData
{
[OdinSerialize]
[LabelText("生成通用界面枚举")]
[ShowIf("ShowCreatePanelViewEnum")]
internal bool CreatePanelViewEnum = true;
internal bool ShowCreatePanelViewEnum()
{
return (AllCommonView.Count + AllCreateView.Count) >= 1;
}
private bool ShowCheckBtn()
{
if (Panel == null)
{
return false;
}
if (!Panel.name.EndsWith(UIStaticHelper.UISource))
{
return false;
}
return true;
}
[GUIColor(0, 1, 1)]
[Button("检查拆分数据", 30)]
[ShowIf("ShowCheckBtn")]
private void AutoCheckBtn()
{
AutoCheck();
}
internal bool AutoCheck()
{
if (!ResetParent()) return false;
if (!CheckPanelName()) return false;
CheckViewName(AllCommonView);
CheckViewName(AllCreateView);
CheckViewName(AllPopupView);
CheckViewParent(AllCommonView, AllViewParent);
CheckViewParent(AllCreateView, AllViewParent);
CheckViewParent(AllPopupView, AllPopupViewParent);
var hashList = new HashSet<RectTransform>();
CheckRepetition(ref hashList, AllCommonView);
CheckRepetition(ref hashList, AllCreateView);
CheckRepetition(ref hashList, AllPopupView);
return true;
}
private bool ResetParent()
{
if (Panel == null)
{
Debug.LogError($"没有找到 Panel");
return false;
}
if (AllViewParent == null || AllViewParent.name != UIStaticHelper.UIAllViewParentName)
{
AllViewParent = Panel.transform.FindChildByName(UIStaticHelper.UIAllViewParentName)
.GetComponent<RectTransform>();
}
if (AllViewParent == null)
{
Debug.LogError($"没有找到 {Panel.name} {UIStaticHelper.UIAllViewParentName} 这是必须存在的组件 你可以不用 但是不能没有");
return false;
}
if (AllPopupViewParent == null || AllPopupViewParent.name != UIStaticHelper.UIAllPopupViewParentName)
{
AllPopupViewParent = Panel.transform.FindChildByName(UIStaticHelper.UIAllPopupViewParentName)
.GetComponent<RectTransform>();
}
if (AllPopupViewParent == null)
{
Debug.LogError($"没有找到 {Panel.name} {UIStaticHelper.UIAllPopupViewParentName} 这是必须存在的组件 你可以不用 但是不能没有");
return false;
}
return true;
}
private bool CheckPanelName()
{
var qualifiedName = NameUtility.ToFirstUpper(Panel.name);
if (Panel.name != qualifiedName)
{
Panel.name = qualifiedName;
}
if (Panel.name == UIStaticHelper.UIYIUIPanelSourceName)
{
Debug.LogError($"当前是默认名称 请手动修改名称 Xxx{UIStaticHelper.UIPanelSourceName}");
return false;
}
if (!Panel.name.EndsWith($"{UIStaticHelper.UIPanelSourceName}"))
{
Debug.LogError($"{Panel.name} 命名必须以 {UIStaticHelper.UIPanelSourceName} 结尾 请勿随意修改");
return false;
}
return true;
}
//命名检查
private void CheckViewName(List<RectTransform> list)
{
for (var i = list.Count - 1; i >= 0; i--)
{
var current = list[i];
if (current == null)
{
list.RemoveAt(i);
continue;
}
var qualifiedName = NameUtility.ToFirstUpper(current.name);
if (current.name != qualifiedName)
{
current.name = qualifiedName;
}
if (current.name == UIStaticHelper.UIYIUIViewParentName)
{
Debug.LogError($"当前是默认名称 请手动修改名称 Xxx{UIStaticHelper.UIViewParentName}");
list.RemoveAt(i);
continue;
}
if (!current.name.EndsWith(UIStaticHelper.UIViewParentName))
{
Debug.LogError($"{current.name} 命名必须以 {UIStaticHelper.UIViewParentName} 结尾 请勿随意修改");
list.RemoveAt(i);
continue;
}
var viewName = current.name.Replace(UIStaticHelper.UIParentName, "");
var viewCde = current.GetComponentInChildren<UIBindCDETable>();
if (viewCde == null)
{
//如果这个子物体被隐藏了
if (current.transform.childCount >= 1)
{
var firstChild = current.transform.GetChild(0);
viewCde = firstChild.GetComponent<UIBindCDETable>();
}
}
if (viewCde == null)
{
Debug.LogError($" {current.name} 父物体下必须有View 但是未找到View 请使用 右键 YIUI/Create UIView 创建符合要求的结构");
list.RemoveAt(i);
continue;
}
viewCde.gameObject.name = viewName;
}
}
//检查null / 父级
private void CheckViewParent(List<RectTransform> list, RectTransform parent)
{
for (var i = list.Count - 1; i >= 0; i--)
{
if (list[i] == null)
{
list.RemoveAt(i);
continue;
}
var current = list[i];
var parentP = current.parent;
if (parentP == null)
{
list.RemoveAt(i);
continue;
}
if (parentP != parent)
{
list.RemoveAt(i);
//因为只有2个父级 所以如果不是这个就会自动帮你移动到另外一个上面
//如果多了还是不要自动了
var currentParentName = parentP.name;
if (currentParentName == UIStaticHelper.UIAllViewParentName)
{
AllCreateView.Add(current);
}
else if (currentParentName == UIStaticHelper.UIAllPopupViewParentName)
{
AllPopupView.Add(current);
}
}
}
}
//检查重复
private void CheckRepetition(ref HashSet<RectTransform> hashList, List<RectTransform> list)
{
for (var i = list.Count - 1; i >= 0; i--)
{
var current = list[i];
if (hashList.Contains(current))
{
list.RemoveAt(i);
Debug.LogError($"{Panel.name} / {current.name} 重复存在 已移除 请检查");
}
else
{
hashList.Add(current);
}
}
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 116fc62782e44221bb7644696b4e60d5
timeCreated: 1685605176

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f5d9049fcb194a3fb63c8cb25261f2ea
timeCreated: 1682498473

View File

@@ -0,0 +1,46 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public static partial class YIUIFactory
{
//普通的UI预制体 创建与摧毁 一定要成对
//为了防止忘记 所以默认自动回收
public static GameObject InstantiateGameObject(string pkgName, string resName)
{
var obj = YIUILoadHelper.LoadAssetInstantiate(pkgName, resName);
if (obj == null)
{
Debug.LogError($"没有加载到这个资源 {pkgName}/{resName}");
return null;
}
//强制添加 既然你要使用这个方法那就必须接受 否则请使用其他方式
//被摧毁时 自动回收 无需调用 UIFactory.Destroy
obj.AddComponent<YIUIReleaseInstantiate>();
return obj;
}
public static async UniTask<GameObject> InstantiateGameObjectAsync(string pkgName, string resName)
{
var obj = await YIUILoadHelper.LoadAssetAsyncInstantiate(pkgName, resName);
if (obj == null)
{
Debug.LogError($"没有加载到这个资源 {pkgName}/{resName}");
return null;
}
obj.AddComponent<YIUIReleaseInstantiate>();
return obj;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 611e6023ac2e4dcb86fc889f289678bb
timeCreated: 1682498501

View File

@@ -0,0 +1,31 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using UnityEngine;
namespace YIUIFramework
{
public static partial class YIUIFactory
{
internal static void Destroy(GameObject obj)
{
YIUILoadHelper.ReleaseInstantiate(obj);
}
//内部会自动调用
//一定要使用本类中的创建 否则会有报错提示
internal static void Destroy(UIBase uiBase)
{
if (uiBase.OwnerGameObject == null)
{
Debug.LogError($"此UI 是空对象 请检查{uiBase.UIBindVo.PkgName} {uiBase.UIBindVo.ResName}");
return;
}
Destroy(uiBase.OwnerGameObject);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 01802f5fb7dc49d383cbfa99c13687ed
timeCreated: 1688113765

View File

@@ -0,0 +1,125 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public static partial class YIUIFactory
{
private static void SetParent(RectTransform self, RectTransform parent)
{
self.SetParent(parent, false);
self.AutoReset();
}
internal static UIBase CreateCommon(string pkgName, string resName, GameObject obj)
{
var bingVo = UIBindHelper.GetBindVoByPath(pkgName, resName);
if (bingVo == null) return null;
var vo = bingVo.Value;
return CreateByObjVo(vo, obj);
}
internal static UIBase CreatePanel(PanelInfo panelInfo)
{
return Create(panelInfo.PkgName, panelInfo.ResName);
}
private static T Create<T>() where T : UIBase
{
var data = UIBindHelper.GetBindVoByType<T>();
if (data == null) return null;
var vo = data.Value;
return (T)Create(vo);
}
private static UIBase Create(string pkgName, string resName)
{
var bingVo = UIBindHelper.GetBindVoByPath(pkgName, resName);
return bingVo == null ? null : Create(bingVo.Value);
}
private static UIBase Create(UIBindVo vo)
{
var obj = YIUILoadHelper.LoadAssetInstantiate(vo.PkgName, vo.ResName);
if (obj == null)
{
Debug.LogError($"没有加载到这个资源 {vo.PkgName}/{vo.ResName}");
return null;
}
return CreateByObjVo(vo, obj);
}
private static UIBase CreateByObjVo(UIBindVo vo, GameObject obj)
{
var cdeTable = obj.GetComponent<UIBindCDETable>();
if (cdeTable == null)
{
Debug.LogError($"{obj.name} 没有 UIBindCDETable 组件 无法创建 请检查");
return null;
}
var lastActive = cdeTable.gameObject.activeSelf;
if (!lastActive)
{
//加载时必须保证处于激活状态 否则一些Mono相关未初始化导致不可预知的错误
cdeTable.gameObject.SetActive(true);
}
cdeTable.CreateComponent();
var uiBase = (UIBase)Activator.CreateInstance(vo.CreatorType);
uiBase.InitUIBase(vo, obj);
if (!lastActive)
{
//如果之前是隐藏的状态 则还原
//此时已经初始化完毕 所以可能会收到被隐藏的消息 请自行酌情处理
cdeTable.gameObject.SetActive(false);
}
return uiBase;
}
private static void CreateComponent(this UIBindCDETable cdeTable)
{
foreach (var childCde in cdeTable.AllChildCdeTable)
{
if (childCde == null)
{
Debug.LogError($"{cdeTable.name} 存在null对象的childCde 检查是否因为删除或丢失或未重新生成");
continue;
}
var lastActive = childCde.gameObject.activeSelf;
if (!lastActive)
{
//加载时必须保证处于激活状态 否则一些Mono相关未初始化导致不可预知的错误
childCde.gameObject.SetActive(true);
}
var bingVo = UIBindHelper.GetBindVoByPath(childCde.PkgName, childCde.ResName);
if (bingVo == null) continue;
var childBase = (UIBase)Activator.CreateInstance(bingVo.Value.CreatorType);
childCde.CreateComponent();
childBase.InitUIBase(bingVo.Value, childCde.gameObject);
cdeTable.AddUIBase(childCde.gameObject.name, childBase);
if (!lastActive)
{
//如果之前是隐藏的状态 则还原
//此时已经初始化完毕 所以可能会收到被隐藏的消息 请自行酌情处理
childCde.gameObject.SetActive(false);
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 22cb104eb4d94e60bdbc322695d370f8
timeCreated: 1688113831

View File

@@ -0,0 +1,77 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public static partial class YIUIFactory
{
public static async UniTask<T> InstantiateAsync<T>(RectTransform parent = null) where T : UIBase
{
var data = UIBindHelper.GetBindVoByType<T>();
if (data == null) return null;
var vo = data.Value;
return await InstantiateAsync<T>(vo, parent);
}
public static async UniTask<T> InstantiateAsync<T>(UIBindVo vo, RectTransform parent = null) where T : UIBase
{
var uiBase = await CreateAsync(vo);
SetParent(uiBase.OwnerRectTransform, parent ? parent : PanelMgr.Inst.UICache);
return (T)uiBase;
}
public static async UniTask<UIBase> InstantiateAsync(UIBindVo vo, RectTransform parent = null)
{
var uiBase = await CreateAsync(vo);
SetParent(uiBase.OwnerRectTransform, parent ? parent : PanelMgr.Inst.UICache);
return uiBase;
}
public static async UniTask<UIBase> InstantiateAsync(Type uiType, RectTransform parent = null)
{
var data = UIBindHelper.GetBindVoByType(uiType);
if (data == null) return null;
var vo = data.Value;
return await InstantiateAsync(vo, parent);
}
public static async UniTask<UIBase> InstantiateAsync(string pkgName, string resName,
RectTransform parent = null)
{
var data = UIBindHelper.GetBindVoByPath(pkgName, resName);
if (data == null) return null;
var vo = data.Value;
return await InstantiateAsync(vo, parent);
}
internal static async UniTask<UIBase> CreatePanelAsync(PanelInfo panelInfo)
{
var bingVo = UIBindHelper.GetBindVoByPath(panelInfo.PkgName, panelInfo.ResName);
if (bingVo == null) return null;
var uiBase = await CreateAsync(bingVo.Value);
return uiBase;
}
private static async UniTask<UIBase> CreateAsync(UIBindVo vo)
{
var obj = await YIUILoadHelper.LoadAssetAsyncInstantiate(vo.PkgName, vo.ResName);
if (obj == null)
{
Debug.LogError($"没有加载到这个资源 {vo.PkgName}/{vo.ResName}");
return null;
}
return CreateByObjVo(vo, obj);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 281fac6207be48379ad9008ad4837b79
timeCreated: 1688113666

View File

@@ -0,0 +1,62 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public static partial class YIUIFactory
{
public static T Instantiate<T>(RectTransform parent = null) where T : UIBase
{
var data = UIBindHelper.GetBindVoByType<T>();
if (data == null) return null;
var vo = data.Value;
return Instantiate<T>(vo, parent);
}
public static T Instantiate<T>(UIBindVo vo, RectTransform parent = null) where T : UIBase
{
var instance = (T)Create(vo);
if (instance == null) return null;
SetParent(instance.OwnerRectTransform, parent ? parent : PanelMgr.Inst.UICache);
return instance;
}
public static UIBase Instantiate(Type uiType, RectTransform parent = null)
{
var data = UIBindHelper.GetBindVoByType(uiType);
if (data == null) return null;
var vo = data.Value;
return Instantiate(vo, parent);
}
public static UIBase Instantiate(UIBindVo vo, RectTransform parent = null)
{
var instance = Create(vo);
if (instance == null) return null;
SetParent(instance.OwnerRectTransform, parent ? parent : PanelMgr.Inst.UICache);
return instance;
}
public static UIBase Instantiate(string pkgName, string resName, RectTransform parent = null)
{
var data = UIBindHelper.GetBindVoByPath(pkgName, resName);
if (data == null) return null;
var vo = data.Value;
return Instantiate(vo, parent);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f0e66f740bcd4b918e3ef478577e28f4
timeCreated: 1692273960

View File

@@ -0,0 +1,59 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 创建一个UI空对象时
/// </summary>
public static class YIUIRectFactory
{
public static RectTransform CreateUIRect(RectTransform parent)
{
var obj = new GameObject();
var rect = obj.AddComponent<RectTransform>();
if (parent != null)
rect.SetParent(parent);
return rect;
}
//重置为全屏自适应UI
public static void ResetToFullScreen(this RectTransform self)
{
self.anchorMin = Vector2.zero;
self.anchorMax = Vector2.one;
self.anchoredPosition3D = Vector3.zero;
self.pivot = new Vector2(0.5f, 0.5f);
self.offsetMax = Vector2.zero;
self.offsetMin = Vector2.zero;
self.sizeDelta = Vector2.zero;
self.localEulerAngles = Vector3.zero;
self.localScale = Vector3.one;
}
//重置位置与旋转
public static void ResetLocalPosAndRot(this RectTransform self)
{
self.localPosition = Vector3.zero;
self.localRotation = Quaternion.identity;
}
/// <summary>
/// 自动重置
/// 一般情况下就2种 全屏的 那就全部归一
/// 其他的 那就什么都不改 只修改大小就可以了
/// </summary>
public static void AutoReset(this RectTransform self)
{
if (self.anchorMax == Vector2.one && self.anchorMin == Vector2.zero)
{
self.ResetToFullScreen();
}
else
{
self.localScale = Vector3.one;
}
self.ResetLocalPosAndRot();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1a3f42862c8a4af8b51a0bd94c3b21eb
timeCreated: 1682505904

View File

@@ -0,0 +1,21 @@
using System;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 一般的普通UI 被创建必须调用 UIFactory.Destroy 同步释放资源
/// 但是有些人真的会忘记 这里额外增加一个mono脚本 摧毁时自动调用
/// 缺点就是多了一个mono脚本 肯定消耗会变高的
/// 如果你创建的对象 你知道什么时候摧毁 就不要使用这个了
/// 如果你真的不知道什么时候移除 或者 不想管理 也接受多余消耗 可以挂载他
/// UIBase 类无需
/// </summary>
public class YIUIReleaseInstantiate : MonoBehaviour
{
private void OnDestroy()
{
YIUIFactory.Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ae8f32640581423fa975430ffcc991f9
timeCreated: 1683627175

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d976e4b7292f4528b348ca309a8709d1
timeCreated: 1682320978

View File

@@ -0,0 +1,69 @@
//------------------------------------------------------------
// Author: 亦亦
// Mail: 379338943@qq.com
// Data: 2023年2月12日
//------------------------------------------------------------
using Sirenix.OdinInspector;
namespace YIUIFramework
{
//一个项目不可能随时换项目路径 这里就是强制设置的只可读 初始化项目的时候手动改这个一次就可以了
/// <summary>
/// UI静态助手
/// </summary>
public static class UIStaticHelper
{
[LabelText("YIUI根目录名称")]
public const string UIProjectName = "YIUI";
[LabelText("YIUI项目命名空间")]
public const string UINamespace = "YIUI"; //所有生成文件的命名空间
[LabelText("YIUI项目编辑器资源路径")]
public const string UIProjectEditorPath = "Assets/Editor/" + UIProjectName; //编辑器才会用到的资源
[LabelText("YIUI项目资源路径")]
public const string UIProjectResPath = "Assets/GameRes/" + UIProjectName; //玩家的预设/图片等资源存放的地方
[LabelText("YIUI项目脚本路径")]
public const string UIGenerationPath = "Assets/Scripts/YIUIGeneration"; //自动生成的代码
[LabelText("YIUI项目自定义脚本路径")]
public const string UICodeScriptsPath = "Assets/Scripts/" + UIProjectName; //玩家可编写的核心代码部分
[LabelText("YIUI框架所处位置路径")]
public const string UIFrameworkPath = "Assets/Plugins/YIUIFramework";
[LabelText("YIUI项目代码模板路径")]
public const string UITemplatePath = UIFrameworkPath + "/YIUIEditor/YIUIAutoTool/Template";
public const string UIRootPrefabPath =
UIFrameworkPath + "/YIUIEditor/UIRootPrefab/" + PanelMgr.UIRootName + ".prefab";
public const string UIBaseName = nameof(UIBase);
public const string UIBasePanelName = nameof(BasePanel);
public const string UIBaseViewName = nameof(BaseView);
public const string UIBaseComponentName = nameof(BaseComponent);
public const string UIPanelName = "Panel";
public const string UIViewName = "View";
public const string UIParentName = "Parent";
public const string UIPrefabs = "Prefabs";
public const string UIPrefabsCN = "预制";
public const string UISprites = "Sprites";
public const string UISpritesCN = "精灵";
public const string UIAtlas = "Atlas";
public const string UIAtlasCN = "图集";
public const string UISource = "Source";
public const string UISourceCN = "源文件";
public const string UIAtlasIgnore = "AtlasIgnore"; //图集忽略文件夹名称
public const string UISpritesAtlas1 = "Atlas1"; //图集1 不需要华丽的取名 每个包内的自定义图集就按顺序就好 当然你也可以自定义其他
public const string UIAllViewParentName = "AllViewParent";
public const string UIAllPopupViewParentName = "AllPopupViewParent";
public const string UIYIUIPanelSourceName = UIProjectName + UIPanelName + UISource;
public const string UIPanelSourceName = UIPanelName + UISource;
public const string UIYIUIViewName = UIProjectName + UIViewName;
public const string UIViewParentName = UIViewName + UIParentName;
public const string UIYIUIViewParentName = UIProjectName + UIViewName + UIParentName;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c5f9e4f8a168476f83efe9d4ab26cbd5
timeCreated: 1682321036

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 24abd139b3ef4dd3a13fa395cdaab207
timeCreated: 1681898366

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f34e653c7b0c4a859aae3fc27afa8246
timeCreated: 1681899168

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2be05114d96a43e4ad0b490d9afa57ee
timeCreated: 1689323021

View File

@@ -0,0 +1,243 @@
using System;
using Sirenix.OdinInspector;
using YIUIBind;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// UI基类
/// </summary>
[HideLabel]
[HideReferenceObjectPicker]
public abstract class UIBase
{
#region table表禁止public
internal UIBindCDETable m_CDETable;
protected UIBindCDETable CDETable => m_CDETable;
internal UIBindComponentTable m_ComponentTable;
protected UIBindComponentTable ComponentTable => m_ComponentTable;
internal UIBindDataTable m_DataTable;
protected UIBindDataTable DataTable => m_DataTable;
internal UIBindEventTable m_EventTable;
protected UIBindEventTable EventTable => m_EventTable;
#endregion
/// <summary>
/// 当前UI的预设对象
/// </summary>
[LabelText("UI对象")]
public GameObject OwnerGameObject;
/// <summary>
/// 当前UI的Tsf
/// </summary>
[HideInInspector]
public RectTransform OwnerRectTransform;
/// <summary>
/// 初始化状态
/// </summary>
private bool m_UIBaseInit;
public bool UIBaseInit => m_UIBaseInit;
//用这个不用.单例而已
protected PanelMgr m_PanelMgr;
/// <summary>
/// UI的资源包名
/// </summary>
public string UIPkgName => m_UIBindVo.PkgName;
/// <summary>
/// UI的资源名称
/// </summary>
public string UIResName => m_UIBindVo.ResName;
/// <summary>
/// 绑定信息
/// </summary>
private UIBindVo m_UIBindVo;
internal UIBindVo UIBindVo => m_UIBindVo;
/// <summary>
/// 当前显示状态 显示/隐藏
/// 不要使用这个设置显影
/// 应该使用控制器 或调用方法 SetActive();
/// </summary>
public bool ActiveSelf
{
get
{
if (OwnerGameObject == null) return false;
return OwnerGameObject.activeSelf;
}
}
/// <summary>
/// 初始化UIBase 由PanelMgr创建对象后调用
/// 外部禁止
/// </summary>
internal bool InitUIBase(UIBindVo uiBindVo, GameObject ownerGameObject)
{
if (ownerGameObject == null)
{
Debug.LogError($"null对象无法初始化");
return false;
}
OwnerGameObject = ownerGameObject;
OwnerRectTransform = ownerGameObject.GetComponent<RectTransform>();
m_CDETable = OwnerGameObject.GetComponent<UIBindCDETable>();
if (CDETable == null)
{
Debug.LogError($"{OwnerGameObject.name} 没有UIBindCDETable组件 这是必须的");
return false;
}
m_ComponentTable = CDETable.ComponentTable;
m_DataTable = CDETable.DataTable;
m_EventTable = CDETable.EventTable;
m_UIBaseInit = true;
m_UIBindVo = uiBindVo;
m_PanelMgr = PanelMgr.Inst;
CDETable.BindUIBase(this);
UIBaseInitialize();
return true;
}
#region
/// <summary>
/// 设置显隐
/// </summary>
public void SetActive(bool value)
{
if (OwnerGameObject == null) return;
OwnerGameObject.SetActive(value);
}
//其他的关于 RectTransform 相关的 不建议包一层
//就直接 OwnerRectTransform. 使用Unity API 就可以了 没必要包一成
//这么多方法 都有可能用到你都包一层嘛
#endregion
#region
//UIBase 生命周期顺序 2
protected virtual void UIBind()
{
}
//UIBase 生命周期顺序 3
protected virtual void Initialize()
{
}
private void UIBaseInitialize()
{
CDETable.UIBaseStart = UIBaseStart;
CDETable.UIBaseOnDestroy = UIBaseOnDestroy;
try
{
SealedInitialize();
UIBind();
Initialize();
if (ActiveSelf)
UIBaseOnEnable();
else
UIBaseOnDisable();
CDETable.UIBaseOnEnable = UIBaseOnEnable;
CDETable.UIBaseOnDisable = UIBaseOnDisable;
}
catch (Exception e)
{
Debug.LogError(e);
throw;
}
}
//UIBase 生命周期顺序 6
protected virtual void Start()
{
}
private void UIBaseStart()
{
SealedStart();
Start();
}
//UIBase 生命周期顺序 4
protected virtual void OnEnable()
{
}
private void UIBaseOnEnable()
{
OnEnable();
}
//UIBase 生命周期顺序 4
protected virtual void OnDisable()
{
}
private void UIBaseOnDisable()
{
OnDisable();
}
//UIBase 生命周期顺序 7
protected virtual void UnUIBind()
{
}
//UIBase 生命周期顺序 8
protected virtual void OnDestroy()
{
}
private void UIBaseOnDestroy()
{
UnUIBind();
OnDestroy();
SealedOnDestroy();
YIUIFactory.Destroy(this);
}
#region ()
//这是给基类用的生命周期(BasePanel,BaseView) 为了防止有人重写时不调用基类 所以直接独立
//没有什么穿插需求怎么办
//基类会重写这个类且会密封你也调用不到
//不要问为什么...
//UIBase 生命周期顺序 1
protected virtual void SealedInitialize()
{
}
//UIBase 生命周期顺序 5
protected virtual void SealedStart()
{
}
//UIBase 生命周期顺序 9
protected virtual void SealedOnDestroy()
{
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 24d50b68ce6649a0a6610ea2a05b8716
timeCreated: 1681898395

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8a2f25bf5c5441178d8817ff3edb096f
timeCreated: 1689323009

View File

@@ -0,0 +1,24 @@
namespace YIUIFramework
{
/// <summary>
/// 通用UI其他组件
/// </summary>
public partial class BaseComponent : UIBase
{
#region
protected sealed override void SealedInitialize()
{
}
protected sealed override void SealedStart()
{
}
protected sealed override void SealedOnDestroy()
{
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0903f39d5074d8abc2d5e4f94faa5d2
timeCreated: 1683862460

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 77084063f9744ffc8a6f028970bcf901
timeCreated: 1689322970

View File

@@ -0,0 +1,48 @@
namespace YIUIFramework
{
/// <summary>
/// 面板基类, 编辑器创建面板代码时自动带入
/// </summary>
public abstract partial class BasePanel : BaseWindow, IYIUIPanel
{
/// <summary>
/// 所在层级
/// </summary>
public virtual EPanelLayer Layer => EPanelLayer.Panel;
/// <summary>
/// 界面选项
/// </summary>
public virtual EPanelOption PanelOption => EPanelOption.None;
/// <summary>
/// 堆栈操作
/// </summary>
public virtual EPanelStackOption StackOption => EPanelStackOption.Visible;
/// <summary>
/// 优先级,用于同层级排序,
/// 大的在前 小的在后
/// 相同时 后添加的在前
/// </summary>
public virtual int Priority => 0;
#region
protected sealed override void SealedInitialize()
{
InitPanelViewData();
}
protected sealed override void SealedStart()
{
}
protected sealed override void SealedOnDestroy()
{
StopCountDownDestroyPanel();
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef52b803bd61401897ae5642040cd9d6
timeCreated: 1681898370

View File

@@ -0,0 +1,88 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 动画
/// </summary>
public abstract partial class BasePanel
{
protected sealed override async UniTask SealedOnWindowOpenTween()
{
if (PanelMgr.IsLowQuality || WindowBanTween)
{
OnOpenTweenEnd();
return;
}
var foreverCode = WindowAllowOptionByTween ? 0 : m_PanelMgr.BanLayerOptionForever();
try
{
await OnOpenTween();
}
catch (Exception e)
{
Debug.LogError($"{UIResName} 打开动画执行报错 {e}");
}
finally
{
m_PanelMgr.RecoverLayerOptionForever(foreverCode);
OnOpenTweenEnd();
}
}
protected sealed override async UniTask SealedOnWindowCloseTween()
{
if (!ActiveSelf || PanelMgr.IsLowQuality || WindowBanTween)
{
OnCloseTweenEnd();
return;
}
var foreverCode = WindowAllowOptionByTween ? 0 : m_PanelMgr.BanLayerOptionForever();
try
{
await OnCloseTween();
}
catch (Exception e)
{
Debug.LogError($"{UIResName} 关闭动画执行报错 {e}");
}
finally
{
m_PanelMgr.RecoverLayerOptionForever(foreverCode);
OnCloseTweenEnd();
}
}
protected override async UniTask OnOpenTween()
{
await WindowFadeAnim.In(this);
}
protected override async UniTask OnCloseTween()
{
await WindowFadeAnim.Out(this);
}
protected override void OnOpenTweenStart()
{
OwnerGameObject.SetActive(true);
}
protected override void OnOpenTweenEnd()
{
}
protected override void OnCloseTweenStart()
{
}
protected override void OnCloseTweenEnd()
{
OwnerGameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 74416b8f584e45b4a9c436d96b5cc35f
timeCreated: 1683889239

View File

@@ -0,0 +1,30 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
/// <summary>
/// 关闭
/// </summary>
public abstract partial class BasePanel
{
public void Close(bool tween = true, bool ignoreElse = false)
{
CloseAsync(tween, ignoreElse).Forget();
}
public async UniTask CloseAsync(bool tween = true, bool ignoreElse = false)
{
await m_PanelMgr.ClosePanelAsync(UIResName, tween, ignoreElse);
}
protected void Home<T>(bool tween = true) where T : BasePanel
{
m_PanelMgr.HomePanel<T>(tween).Forget();
}
protected void Home(string homeName, bool tween = true)
{
m_PanelMgr.HomePanel(homeName, tween).Forget();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 03365dc283b74259b6b1365f3507aa70
timeCreated: 1683886901

View File

@@ -0,0 +1,42 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
public abstract partial class BasePanel
{
public void CloseView<T>(bool tween = true)
where T : BaseView
{
CloseViewAsync<T>(tween).Forget();
}
public void CloseView(string resName, bool tween = true)
{
CloseViewAsync(resName, tween).Forget();
}
public async UniTask<bool> CloseViewAsync<TView>(bool tween = true)
where TView : BaseView
{
var (exist, entity) = ExistView<TView>();
if (!exist) return false;
return await CloseViewAsync(entity, tween);
}
public async UniTask<bool> CloseViewAsync(string resName, bool tween = true)
{
var (exist, entity) = ExistView(resName);
if (!exist) return false;
return await CloseViewAsync(entity, tween);
}
private async UniTask<bool> CloseViewAsync(BaseView view, bool tween)
{
if (view == null) return false;
await view.CloseAsync(tween);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8524a28809b546008658b643b82d5f8e
timeCreated: 1716112439

View File

@@ -0,0 +1,236 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
public abstract partial class BasePanel
{
#region Open PanelMgr调用
/// <summary>
/// 使用基础Open 打开类
/// </summary>
/// <returns></returns>
private async UniTask<bool> UseBaseOpen()
{
if (!WindowCanUseBaseOpen)
{
Debug.LogError($"当前传入的参数不支持 并未实现这个打开方式 且不允许使用基础Open打开 请检查");
return false;
}
return await Open();
}
public async UniTask<bool> Open()
{
SetActive(true);
var success = false;
if (!WindowHaveIOpenAllowOpen && this is IYIUIOpen)
{
Debug.LogError($"当前Panel 有其他IOpen 接口 需要参数传入 不允许直接调用Open");
return false;
}
try
{
success = await OnOpen();
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open(ParamVo param)
{
if (WindowBanParamOpen)
{
Debug.LogError($"当前禁止使用ParamOpen 请检查");
return false;
}
SetActive(true);
var success = false;
try
{
success = await OnOpen(param);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1>(P1 p1)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1> panel)
{
try
{
success = await panel.OnOpen(p1);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2>(P1 p1, P2 p2)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2> panel)
{
try
{
success = await panel.OnOpen(p1, p2);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3>(P1 p1, P2 p2, P3 p3)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3> panel)
{
try
{
success = await panel.OnOpen(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3, P4>(P1 p1, P2 p2, P3 p3, P4 p4)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3, P4> panel)
{
try
{
success = await panel.OnOpen(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3, P4, P5>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3, P4, P5> panel)
{
try
{
success = await panel.OnOpen(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f2af119f866046dc87febc299cdb2644
timeCreated: 1683799029

View File

@@ -0,0 +1,210 @@
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
using UnityEngine;
using YIUIBind;
namespace YIUIFramework
{
/// <summary>
/// 部类 界面拆分数据
/// </summary>
public abstract partial class BasePanel
{
private UIPanelSplitData m_PanelSplitData;
private Dictionary<string, BaseView> m_ExistView = new Dictionary<string, BaseView>();
private Dictionary<string, RectTransform> m_ViewParent = new Dictionary<string, RectTransform>();
private void InitPanelViewData()
{
m_ExistView.Clear();
m_ViewParent.Clear();
m_PanelSplitData = CDETable.PanelSplitData;
CreateCommonView();
AddViewParent(m_PanelSplitData.AllCommonView);
AddViewParent(m_PanelSplitData.AllCreateView);
AddViewParent(m_PanelSplitData.AllPopupView);
}
private void AddViewParent(List<RectTransform> listParent)
{
foreach (var parent in listParent)
{
var viewName = parent.name.Replace(UIStaticHelper.UIParentName, "");
m_ViewParent.Add(viewName, parent);
}
}
private void CreateCommonView()
{
foreach (var commonParentView in m_PanelSplitData.AllCommonView)
{
var viewName = commonParentView.name.Replace(UIStaticHelper.UIParentName, "");
//通用view的名称是不允许修改的 如果修改了 那么就创建一个新的
var viewTsf = commonParentView.FindChildByName(viewName);
if (viewTsf == null)
{
Debug.LogError($"{viewName} 当前通用View 不存在于父级下 所以无法自动创建 将会动态创建");
continue;
}
//通用创建 这个时候通用UI一定是没有创建的 否则就有问题
var viewBase = YIUIFactory.CreateCommon(UIPkgName, viewName, viewTsf.gameObject);
if (viewBase == null)continue;
viewTsf.gameObject.SetActive(false);
switch (viewBase)
{
case BaseView baseView:
m_ExistView.Add(viewName, baseView);
break;
default:
Debug.LogError($"{viewName} 不应该存在的错误 当前创建的View 不是BaseView");
break;
}
}
}
private RectTransform GetViewParent(string viewName)
{
m_ViewParent.TryGetValue(viewName, out var value);
return value;
}
private async UniTask<T> GetView<T>() where T : BaseView
{
var viewName = typeof(T).Name;
var parent = GetViewParent(viewName);
if (parent == null)
{
Debug.LogError($"不存在这个View 请检查 {viewName}");
return null;
}
using var asyncLock = await AsyncLockMgr.Inst.Wait(viewName.GetHashCode());
if (m_ExistView.ContainsKey(viewName))
{
return (T)m_ExistView[viewName];
}
var view = await YIUIFactory.InstantiateAsync<T>(parent);
m_ExistView.Add(viewName, view);
return view;
}
public (bool, BaseView) ExistView<T>() where T : BaseView
{
var data = UIBindHelper.GetBindVoByType<T>();
if (data == null) return (false, null);
var vo = data.Value;
var viewName = vo.ResName;
var viewParent = GetViewParent(viewName);
if (viewParent == null)
{
Debug.LogError($"不存在这个View 请检查 {viewName}");
return (false, null);
}
if (m_ExistView.TryGetValue(viewName, out var baseView))
{
return (true, baseView);
}
return (false, null);
}
public (bool, BaseView) ExistView(string viewName)
{
var viewParent = GetViewParent(viewName);
if (viewParent == null)
{
Debug.LogError($"不存在这个View 请检查 {viewName}");
return (false, null);
}
if (m_ExistView.TryGetValue(viewName, out var baseView))
{
return (true, baseView);
}
return (false, null);
}
/// <summary>
/// 打开之前
/// </summary>
private async UniTask OpenViewBefore(BaseView view)
{
if (!view.WindowFirstOpen)
{
await CloseLastView(view);
}
}
/// <summary>
/// 打开之后
/// </summary>
private async UniTask OpenViewAfter(BaseView view, bool success)
{
if (success)
{
if (view.WindowFirstOpen)
{
await CloseLastView(view);
}
}
else
{
view.Close(false);
}
}
/// <summary>
/// 关闭上一个
/// </summary>
/// <param name="view">当前</param>
private async UniTask CloseLastView(BaseView view)
{
//其他需要被忽略
if (view.ViewWindowType != EViewWindowType.View)
{
return;
}
//View只有切换没有关闭
var skipTween = view.WindowSkipOtherCloseTween;
if (u_CurrentOpenView != null && u_CurrentOpenView != view)
{
//View 没有自动回退功能 比如AView 关闭 自动吧上一个BView 给打开 没有这种需求 也不能有这个需求
//只能有 打开一个新View 上一个View的自动处理 99% 都是吧上一个隐藏即可
//外部就只需要关心 打开 A B C 即可
//因为这是View 不是 Panel
switch (u_CurrentOpenView.StackOption)
{
case EViewStackOption.None:
break;
case EViewStackOption.Visible:
u_CurrentOpenView.SetActive(false);
break;
case EViewStackOption.VisibleTween:
await u_CurrentOpenView.CloseAsync(!skipTween);
break;
default:
Debug.LogError($"新增类型未实现 {u_CurrentOpenView.StackOption}");
u_CurrentOpenView.SetActive(false);
break;
}
}
u_CurrentOpenView = view;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d35290fb77ef4c6eb52caee150b65c39
timeCreated: 1683795537

View File

@@ -0,0 +1,154 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
//打开泛型 异步
public abstract partial class BasePanel
{
protected async UniTask<T> OpenViewAsync<T>()
where T : BaseView, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open();
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<T> OpenViewAsync<T, P1>(P1 p1)
where T : BaseView, IYIUIOpen<P1>, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<T> OpenViewAsync<T, P1, P2>(P1 p1, P2 p2)
where T : BaseView, IYIUIOpen<P1, P2>, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<T> OpenViewAsync<T, P1, P2, P3>(P1 p1, P2 p2, P3 p3)
where T : BaseView, IYIUIOpen<P1, P2, P3>, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<T> OpenViewAsync<T, P1, P2, P3, P4>(P1 p1, P2 p2, P3 p3, P4 p4)
where T : BaseView, IYIUIOpen<P1, P2, P3, P4>, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<T> OpenViewAsync<T, P1, P2, P3, P4, P5>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
where T : BaseView, IYIUIOpen<P1, P2, P3, P4, P5>, new()
{
var view = await GetView<T>();
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4b4ee8db93194df8b9c7988dca3701df
timeCreated: 1685587228

View File

@@ -0,0 +1,118 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 部类 界面拆分数据
/// </summary>
public abstract partial class BasePanel
{
private async UniTask<BaseView> GetView(string viewName)
{
var parent = GetViewParent(viewName);
if (parent == null)
{
Debug.LogError($"不存在这个View 请检查 {viewName}");
return null;
}
using var asyncLock = await AsyncLockMgr.Inst.Wait(viewName.GetHashCode());
if (m_ExistView.ContainsKey(viewName))
{
return m_ExistView[viewName];
}
var value = UIBindHelper.GetBindVoByPath(UIPkgName, viewName);
if (value == null) return null;
var bindVo = value.Value;
var view = (BaseView)await YIUIFactory.InstantiateAsync(bindVo, parent);
m_ExistView.Add(viewName, view);
return view;
}
#region
protected async UniTask<BaseView> OpenViewAsync(string viewName, object param = null)
{
var view = await GetView(viewName);
if (view == null) return null;
var success = false;
await OpenViewBefore(view);
try
{
var p = ParamVo.Get(param);
success = await view.Open(p);
ParamVo.Put(p);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync(string viewName, object param1, object param2)
{
var paramList = ListPool<object>.Get();
paramList.Add(param1);
paramList.Add(param2);
var view = await OpenViewAsync(viewName, paramList);
ListPool<object>.Put(paramList);
return view;
}
protected async UniTask<BaseView> OpenViewAsync(string viewName, object param1, object param2, object param3)
{
var paramList = ListPool<object>.Get();
paramList.Add(param1);
paramList.Add(param2);
paramList.Add(param3);
var view = await OpenViewAsync(viewName, paramList);
ListPool<object>.Put(paramList);
return view;
}
protected async UniTask<BaseView> OpenViewAsync(string viewName, object param1, object param2, object param3,
object param4)
{
var paramList = ListPool<object>.Get();
paramList.Add(param1);
paramList.Add(param2);
paramList.Add(param3);
paramList.Add(param4);
var view = await OpenViewAsync(viewName, paramList);
ListPool<object>.Put(paramList);
return view;
}
protected async UniTask<BaseView> OpenViewAsync(string viewName, object param1, object param2, object param3,
object param4, params object[] paramMore)
{
var paramList = ListPool<object>.Get();
paramList.Add(param1);
paramList.Add(param2);
paramList.Add(param3);
paramList.Add(param4);
if (paramMore.Length > 0)
{
paramList.AddRange(paramMore);
}
var view = await OpenViewAsync(viewName, paramList);
ListPool<object>.Put(paramList);
return view;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2dbb82e78ed84937b1757dc057ac2678
timeCreated: 1683809072

View File

@@ -0,0 +1,148 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
public abstract partial class BasePanel
{
protected async UniTask<BaseView> OpenViewAsync(string viewName)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open();
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1>(string viewName, P1 p1)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2>(string viewName, P1 p1, P2 p2)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3>(string viewName, P1 p1, P2 p2, P3 p3)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3, P4>(string viewName, P1 p1, P2 p2, P3 p3, P4 p4)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3, P4, P5>(
string viewName, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
var view = await GetView(viewName);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 62230f4010824c21b6295a2b6aa6277a
timeCreated: 1683881474

View File

@@ -0,0 +1,47 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
/// <summary>
/// 打开泛型 同步方法 内部还是异步打开
/// 不想提供快捷操作可以删除此类
/// </summary>
public abstract partial class BasePanel
{
protected void OpenView<T>()
where T : BaseView, new()
{
OpenViewAsync<T>().Forget();
}
protected void OpenView<T, P1>(P1 p1)
where T : BaseView, IYIUIOpen<P1>, new()
{
OpenViewAsync<T, P1>(p1).Forget();
}
protected void OpenView<T, P1, P2>(P1 p1, P2 p2)
where T : BaseView, IYIUIOpen<P1, P2>, new()
{
OpenViewAsync<T, P1, P2>(p1, p2).Forget();
}
protected void OpenView<T, P1, P2, P3>(P1 p1, P2 p2, P3 p3)
where T : BaseView, IYIUIOpen<P1, P2, P3>, new()
{
OpenViewAsync<T, P1, P2, P3>(p1, p2, p3).Forget();
}
protected void OpenView<T, P1, P2, P3, P4>(P1 p1, P2 p2, P3 p3, P4 p4)
where T : BaseView, IYIUIOpen<P1, P2, P3, P4>, new()
{
OpenViewAsync<T, P1, P2, P3, P4>(p1, p2, p3, p4).Forget();
}
protected void OpenView<T, P1, P2, P3, P4, P5>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
where T : BaseView, IYIUIOpen<P1, P2, P3, P4, P5>, new()
{
OpenViewAsync<T, P1, P2, P3, P4, P5>(p1, p2, p3, p4, p5).Forget();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 360f18fc00e744489e2e5a2d15f49951
timeCreated: 1685587311

View File

@@ -0,0 +1,157 @@
using YIUIFramework;
using System;
using System.Collections.Generic;
using System.Linq;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
public abstract partial class BasePanel
{
private async UniTask<BaseView> GetView(Type viewType)
{
var viewName = viewType.Name;
return await GetView(viewName);
}
protected async UniTask<BaseView> OpenViewAsync(Type viewType)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open();
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1>(Type viewType, P1 p1)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2>(Type viewType, P1 p1, P2 p2)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3>(Type viewType, P1 p1, P2 p2, P3 p3)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3, P4>(Type viewType, P1 p1, P2 p2, P3 p3, P4 p4)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
protected async UniTask<BaseView> OpenViewAsync<P1, P2, P3, P4, P5>(
Type viewType, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
var view = await GetView(viewType);
if (view == null) return default;
var success = false;
await OpenViewBefore(view);
try
{
success = await view.Open(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError($"ResName={view.UIResName}, err={e.Message}{e.StackTrace}");
}
await OpenViewAfter(view, success);
return view;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d92b104aba75473fae7b8724eb9b2a6d
timeCreated: 1683879762

View File

@@ -0,0 +1,20 @@
namespace YIUIFramework
{
public abstract partial class BasePanel
{
//容器类界面 //比如伤害飘字 此类界面如果做到panel层会被特殊处理 建议还是不要放到panel层
public virtual bool PanelContainer => PanelOption.HasFlag(EPanelOption.Container);
//永久缓存界面 //永远不会被摧毁 与禁止关闭不同这个可以关闭 只是不销毁 也可相当于无限长的倒计时
public virtual bool PanelForeverCache => PanelOption.HasFlag(EPanelOption.ForeverCache);
//倒计时缓存界面 //被关闭后X秒之后在摧毁 否则理解摧毁
public virtual bool PanelTimeCache => PanelOption.HasFlag(EPanelOption.TimeCache);
//禁止关闭的界面 //是需要一直存在的你可以隐藏 但是你不能摧毁
public virtual bool PanelDisClose => PanelOption.HasFlag(EPanelOption.DisClose);
//忽略返回 返回操作会跳过这个界面 //他的打开与关闭不会触发返回功能 堆栈功能
public virtual bool PanelIgnoreBack => PanelOption.HasFlag(EPanelOption.IgnoreBack);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b49f828695524bdf831f77cc731818c1
timeCreated: 1689325011

View File

@@ -0,0 +1,49 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
/// <summary>
/// 倒计时摧毁面板 适用于倒计时缓存界面
/// </summary>
public abstract partial class BasePanel
{
protected virtual float CachePanelTime => 10;
private CancellationTokenSource m_Cts;
internal void CacheTimeCountDownDestroyPanel()
{
StopCountDownDestroyPanel();
m_Cts = new CancellationTokenSource();
DoCountDownDestroyPanel(m_Cts.Token).Forget();
}
internal void StopCountDownDestroyPanel()
{
if (m_Cts == null) return;
m_Cts.Cancel();
m_Cts.Dispose();
m_Cts = null;
}
private async UniTaskVoid DoCountDownDestroyPanel(CancellationToken token)
{
try
{
await UniTask.Delay(TimeSpan.FromSeconds(CachePanelTime), cancellationToken: token);
}
catch (OperationCanceledException e)
{
//取消倒计时 正常操作不需要日志
return;
}
m_Cts = null;
UnityEngine.Object.Destroy(OwnerGameObject);
PanelMgr.Inst.RemoveUIReset(UIResName);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9a45c498dabd405e9527697d9022de97
timeCreated: 1684145311

View File

@@ -0,0 +1,15 @@
namespace YIUIFramework
{
public abstract partial class BasePanel
{
/// <summary>
/// 当前已打开的UI 不包含弹窗
/// </summary>
protected BaseView u_CurrentOpenView;
/// <summary>
/// 外界可判断的当前打开的view名字
/// </summary>
public string CurrentOpenViewName => u_CurrentOpenView?.UIResName ?? "";
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aac7aa8d5f1149a9a3125d82fc54920b
timeCreated: 1683878928

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7f9458c6e64841389a6a071d118af460
timeCreated: 1689322985

View File

@@ -0,0 +1,25 @@
namespace YIUIFramework
{
public partial class BaseView : BaseWindow, IYIUIView
{
public virtual EViewWindowType ViewWindowType => EViewWindowType.View;
public virtual EViewStackOption StackOption => EViewStackOption.Visible;
#region
protected sealed override void SealedInitialize()
{
}
protected sealed override void SealedStart()
{
}
protected sealed override void SealedOnDestroy()
{
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8fce5356e45247d098a80b33ae50d355
timeCreated: 1681899010

View File

@@ -0,0 +1,85 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
public partial class BaseView
{
protected sealed override async UniTask SealedOnWindowOpenTween()
{
if (PanelMgr.IsLowQuality || WindowBanTween)
{
OnOpenTweenEnd();
return;
}
var foreverCode = WindowAllowOptionByTween ? 0 : m_PanelMgr.BanLayerOptionForever();
try
{
await OnOpenTween();
}
catch (Exception e)
{
Debug.LogError($"{UIResName} 打开动画执行报错 {e}");
}
finally
{
m_PanelMgr.RecoverLayerOptionForever(foreverCode);
OnOpenTweenEnd();
}
}
protected sealed override async UniTask SealedOnWindowCloseTween()
{
if (!ActiveSelf || PanelMgr.IsLowQuality || WindowBanTween)
{
OnCloseTweenEnd();
return;
}
var foreverCode = WindowAllowOptionByTween ? 0 : m_PanelMgr.BanLayerOptionForever();
try
{
await OnCloseTween();
}
catch (Exception e)
{
Debug.LogError($"{UIResName} 关闭动画执行报错 {e}");
}
finally
{
m_PanelMgr.RecoverLayerOptionForever(foreverCode);
OnCloseTweenEnd();
}
}
protected override async UniTask OnOpenTween()
{
await UniTask.CompletedTask;
}
protected override async UniTask OnCloseTween()
{
await UniTask.CompletedTask;
}
protected override void OnOpenTweenStart()
{
OwnerGameObject.SetActive(true);
}
protected override void OnOpenTweenEnd()
{
}
protected override void OnCloseTweenStart()
{
}
protected override void OnCloseTweenEnd()
{
OwnerGameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d10269ae02e548d393b7683b30b9d806
timeCreated: 1684119736

View File

@@ -0,0 +1,18 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public partial class BaseView
{
public void Close(bool tween = true, bool ignoreElse = false)
{
CloseAsync(tween).Forget();
}
public async UniTask CloseAsync(bool tween = true)
{
await InternalOnWindowCloseTween(tween);
OnWindowClose();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5487f84a0fa4482dab277c0ee07f415c
timeCreated: 1684119708

View File

@@ -0,0 +1,239 @@
using System;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// OpenView 由BasePanel调用
/// </summary>
public partial class BaseView
{
#region Open BasePanel调用
/// <summary>
/// 使用基础Open 打开类
/// </summary>
/// <returns></returns>
private async UniTask<bool> UseBaseOpen()
{
if (!WindowCanUseBaseOpen)
{
Debug.LogError($"当前传入的参数不支持 并未实现这个打开方式 且不允许使用基础Open打开 请检查");
return false;
}
return await Open();
}
public async UniTask<bool> Open()
{
SetActive(true);
var success = false;
if (!WindowHaveIOpenAllowOpen && this is IYIUIOpen)
{
Debug.LogError($"当前View 有其他IOpen 接口 需要参数传入 不允许直接调用Open");
return false;
}
try
{
success = await OnOpen();
}
catch (Exception e)
{
Debug.LogError($"ResName={UIResName}, err={e.Message}{e.StackTrace}");
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open(ParamVo param)
{
if (WindowBanParamOpen)
{
Debug.LogError($"当前禁止使用ParamOpen 请检查");
return false;
}
SetActive(true);
var success = false;
try
{
success = await OnOpen(param);
}
catch (Exception e)
{
Debug.LogError($"ResName={UIResName}, err={e.Message}{e.StackTrace}");
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1>(P1 p1)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1> view)
{
try
{
success = await view.OnOpen(p1);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2>(P1 p1, P2 p2)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2> view)
{
try
{
success = await view.OnOpen(p1, p2);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3>(P1 p1, P2 p2, P3 p3)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3> view)
{
try
{
success = await view.OnOpen(p1, p2, p3);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3, P4>(P1 p1, P2 p2, P3 p3, P4 p4)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3, P4> view)
{
try
{
success = await view.OnOpen(p1, p2, p3, p4);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
public async UniTask<bool> Open<P1, P2, P3, P4, P5>(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
{
SetActive(true);
var success = false;
if (this is IYIUIOpen<P1, P2, P3, P4, P5> view)
{
try
{
success = await view.OnOpen(p1, p2, p3, p4, p5);
}
catch (Exception e)
{
Debug.LogError($"ResName{UIResName}, err={e.Message}{e.StackTrace}");
}
}
else
{
return await UseBaseOpen();
}
if (success)
{
await InternalOnWindowOpenTween();
}
return success;
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 98d98381684a42899a63542d7d213fa6
timeCreated: 1683797215

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4628a306f9ce4e65bb6f641d99fb7acf
timeCreated: 1689323000

View File

@@ -0,0 +1,15 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public abstract partial class BaseWindow : UIBase
{
/// <summary>
/// 窗口选项
/// 最后由Panel View重写
/// 实现各种配置
/// 如非必要 所有属性判断可以直接去HasFlag分类中获取 不要直接判断这个
/// </summary>
public virtual EWindowOption WindowOption => EWindowOption.None;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f14db4037054efbb1e410c94f6f70e7
timeCreated: 1683798125

View File

@@ -0,0 +1,74 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
//动画
public abstract partial class BaseWindow
{
private bool m_FirstOpenTween;
internal async UniTask InternalOnWindowOpenTween(bool tween = true)
{
OnOpenTweenStart();
if (tween && !WindowBanRepetitionOpenTween || !m_FirstOpenTween)
{
m_FirstOpenTween = true;
if (WindowBanAwaitOpenTween)
{
SealedOnWindowOpenTween().Forget();
}
else
{
await SealedOnWindowOpenTween();
}
}
else
{
OnOpenTweenEnd();
}
}
private bool m_FirstCloseTween;
internal async UniTask InternalOnWindowCloseTween(bool tween = true)
{
OnCloseTweenStart();
if (tween && !WindowBanRepetitionCloseTween || !m_FirstCloseTween)
{
m_FirstCloseTween = true;
if (WindowBanAwaitCloseTween)
{
SealedOnWindowCloseTween().Forget();
}
else
{
await SealedOnWindowCloseTween();
}
}
else
{
OnCloseTweenEnd();
}
}
//由子类实现密封Async 调用End
protected abstract UniTask SealedOnWindowOpenTween();
//任何UI可重写打开与关闭动画
protected abstract UniTask OnOpenTween();
//有可能没有动画 也有可能动画被跳过 反正无论如何都会有动画结束回调
protected abstract void OnOpenTweenStart();
protected abstract void OnOpenTweenEnd();
protected abstract UniTask SealedOnWindowCloseTween();
protected abstract UniTask OnCloseTween();
protected abstract void OnCloseTweenStart();
protected abstract void OnCloseTweenEnd();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a2c237ed64024a4db33268ab930c344d
timeCreated: 1689324285

View File

@@ -0,0 +1,62 @@
namespace YIUIFramework
{
//窗口选项值 根据需求以下都可以重写 可动态改变值
//所有窗口选项的属性
//可快捷操作
//亦可重写后根据需求动态调整
public abstract partial class BaseWindow
{
/// <summary>
/// 当打开的参数不一致时
/// 是否可以使用基础Open
/// 如果允许 别人调用open了一个不存在的Open参数时
/// 也可以使用默认的open打开界面 则你可以改为true
/// </summary>
public virtual bool WindowCanUseBaseOpen => WindowOption.HasFlag(EWindowOption.CanUseBaseOpen);
/// <summary>
/// 禁止使用ParamOpen
/// </summary>
public virtual bool WindowBanParamOpen => WindowOption.HasFlag(EWindowOption.BanParamOpen);
/// <summary>
/// 我有其他IOpen时 允许用open
/// 默认fasle 我有其他iopen接口时 是不允许使用open的
/// </summary>
public virtual bool WindowHaveIOpenAllowOpen => WindowOption.HasFlag(EWindowOption.HaveIOpenAllowOpen);
//先开
public virtual bool WindowFirstOpen => WindowOption.HasFlag(EWindowOption.FirstOpen);
//后关
public virtual bool WindowLastClose => WindowOption.HasFlag(EWindowOption.LastClose);
//禁止动画
public virtual bool WindowBanTween => WindowOption.HasFlag(EWindowOption.BanTween);
//打开动画不可重复播放
public virtual bool WindowBanRepetitionOpenTween => WindowOption.HasFlag(EWindowOption.BanRepetitionOpenTween);
//关闭动画不可重复播放
public virtual bool WindowBanRepetitionCloseTween =>
WindowOption.HasFlag(EWindowOption.BanRepetitionCloseTween);
//不等待打开动画
public virtual bool WindowBanAwaitOpenTween => WindowOption.HasFlag(EWindowOption.BanAwaitOpenTween);
//不等待关闭动画
public virtual bool WindowBanAwaitCloseTween => WindowOption.HasFlag(EWindowOption.BanAwaitCloseTween);
//我关闭时跳过其他的打开动画
public virtual bool WindowSkipOtherOpenTween => WindowOption.HasFlag(EWindowOption.SkipOtherOpenTween);
//我打开时跳过其他的关闭动画
public virtual bool WindowSkipOtherCloseTween => WindowOption.HasFlag(EWindowOption.SkipOtherCloseTween);
//Home时 跳过我自己的打开动画
public virtual bool WindowSkipHomeOpenTween => WindowOption.HasFlag(EWindowOption.SkipHomeOpenTween);
//播放动画时 可以操作 默认播放动画的时候是不能操作UI的 不然容易出问题
public virtual bool WindowAllowOptionByTween => WindowOption.HasFlag(EWindowOption.AllowOptionByTween);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 70c82cb8ac4c4c218f74929ef32f8a8b
timeCreated: 1689324378

View File

@@ -0,0 +1,49 @@
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
//打开关闭
public abstract partial class BaseWindow
{
//打开有3种
//1 无参打开 OnOpen
//2 ParamVo参数打开 也叫 ParamOpen 打开内部是List<obj>参数 所以可以支持无限长度
//3 继承接口IOpen的 也叫 IOpen 打开 最高支持5个泛型参数
//前2种都会自带 第三种根据需求自己继承
/// <summary>
/// 打开UI 无参
/// </summary>
protected virtual async UniTask<bool> OnOpen()
{
await UniTask.CompletedTask;
return true;
}
/// <summary>
/// 打开UI 带参数的
/// 需要自己解析参数
/// 适合用字符串开启的 参数可字符串配置那种
/// 默认会调用onopen
/// </summary>
protected virtual async UniTask<bool> OnOpen(ParamVo param)
{
return await OnOpen();
}
internal void OnWindowClose()
{
OnClose();
}
/// <summary>
/// UI被关闭
/// 与OnDisable 不同 Disable 只是显影操作不代表被关闭
/// 与OnDestroy 不同 Destroy 是摧毁 但是因为有缓存界面的原因 当被缓存时 OnDestroy是不会来的
/// 这个时候你想要知道是不是被关闭了就必须通过OnClose
/// baseView除外 因为view的关闭就是隐藏 所以 view的 OnDisable = OnClose
/// </summary>
protected virtual void OnClose()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e8bd7dfdf2474fa2917685125f966d17
timeCreated: 1689324334

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dad8caf5e8fd4c409e39aa002b11f0fe
timeCreated: 1682474419

View File

@@ -0,0 +1,34 @@
#if UNITY_EDITOR
using System.Text;
namespace YIUIFramework
{
/// <summary>
/// 用于EDITOR时使用Get取得数据列表
/// 编译时使用Get and GenCode来生成同类型代码
/// 然后使用新生成代码里的Get来得到数据列表
/// </summary>
/// <typeparam name="T"></typeparam>
public interface ICodeGenerator<T>
{
T[] Get();
/// <summary>
/// 生成数据代码仅能在editor里执行
/// 在方法里,只要写单项的属性设置代码就行了。
/// 而要设置的代码名默认叫"v";
/// </summary>
/// <param name="info"></param>
/// <param name="sb">用于写代码的SB</param>
/// <returns></returns>
void WriteCode(T info, StringBuilder sb);
/// <summary>
/// 可能遇到他是个单例不是new的情况 所以这里可以重写
/// </summary>
/// <param name="info"></param>
/// <param name="sb"></param>
void NewCode(T info, StringBuilder sb);
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d6a0dff0c78b4939a63cd8e0ea5fd36a
timeCreated: 1682072802

View File

@@ -0,0 +1,216 @@
//#define YIUIMACRO_SIMULATE_NONEEDITOR //模拟非编辑器状态 在编辑器使用 非编辑器加载模式 用于在编辑器下测试
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// UI关联帮助类
/// </summary>
public static class UIBindHelper
{
/// <summary>
/// 根据创建时的类获取
/// </summary>
private static Dictionary<Type, UIBindVo> g_UITypeToPkgInfo = new Dictionary<Type, UIBindVo>();
/// <summary>
/// 根据 pkg + res 双字典获取
/// </summary>
private static Dictionary<string, Dictionary<string, UIBindVo>> g_UIPathToPkgInfo =
new Dictionary<string, Dictionary<string, UIBindVo>>();
/// <summary>
/// 只有panel 的信息
/// </summary>
private static Dictionary<string, UIBindVo> g_UIPanelNameToPkgInfo = new Dictionary<string, UIBindVo>();
//改为dll过后 提供给外部的方法
//1 从UI工具中自动生成绑定代码
//2 外部请直接调用此方法 UIBindHelper.InternalGameGetUIBindVoFunc = YIUICodeGenerated.UIBindProvider.Get;
public static Func<UIBindVo[]> InternalGameGetUIBindVoFunc { internal get; set; }
//初始化记录
public static bool IsInit { get; private set; }
public static Type BasePanelType = typeof(BasePanel);
/// <summary>
/// 初始化获取到所有UI相关的绑定关系
/// Editor下是反射
/// 其他 是序列化的文件 打包的时候一定要生成一次文件
/// </summary>
internal static bool InitAllBind()
{
if (IsInit)
{
Debug.LogError($"已经初始化过了 请检查");
return false;
}
#if !UNITY_EDITOR || YIUIMACRO_SIMULATE_NONEEDITOR
if (InternalGameGetUIBindVoFunc == null)
{
Debug.LogError($"使用非反射注册绑定 但是方法未实现 请检查");
return false;
}
var binds = InternalGameGetUIBindVoFunc?.Invoke();
#else
var binds = new UIBindProvider().Get();
#endif
if (binds == null || binds.Length <= 0)
{
Debug.LogError("没有找到绑定信息 或者 没有绑定信息 请检查");
return false;
}
g_UITypeToPkgInfo = new Dictionary<Type, UIBindVo>(binds.Length);
g_UIPathToPkgInfo = new Dictionary<string, Dictionary<string, UIBindVo>>();
g_UIPanelNameToPkgInfo = new Dictionary<string, UIBindVo>(binds.Length);
for (var i = 0; i < binds.Length; i++)
{
var vo = binds[i];
g_UITypeToPkgInfo[vo.CreatorType] = vo;
AddPkgInfoToPathDic(vo);
if (vo.CodeType == BasePanelType)
g_UIPanelNameToPkgInfo[vo.ResName] = vo;
}
IsInit = true;
return true;
}
private static void AddPkgInfoToPathDic(UIBindVo vo)
{
var pkgName = vo.PkgName;
var resName = vo.ResName;
if (!g_UIPathToPkgInfo.ContainsKey(pkgName))
{
g_UIPathToPkgInfo.Add(pkgName, new Dictionary<string, UIBindVo>());
}
var dic = g_UIPathToPkgInfo[pkgName];
if (dic.ContainsKey(resName))
{
Debug.LogError($"重复资源 请检查 {pkgName} {resName}");
return;
}
dic.Add(resName, vo);
}
/// <summary>
/// 得到UI包信息
/// </summary>
/// <param name="uiType"></param>
/// <returns></returns>
public static UIBindVo? GetBindVoByType(Type uiType)
{
if (uiType == null)
{
Debug.LogError($"空 无法取到这个包信息 请检查");
return null;
}
if (g_UITypeToPkgInfo.TryGetValue(uiType, out var vo))
{
return vo;
}
Debug.LogError($"未获取到这个UI包信息 请检查 {uiType.Name}");
return null;
}
/// <summary>
/// 得到UI包信息
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static UIBindVo? GetBindVoByType<T>()
{
return GetBindVoByType(typeof(T));
}
/// <summary>
/// 根据唯一ID获取
/// 由pkg+res 拼接的唯一ID
/// </summary>
public static UIBindVo? GetBindVoByPath(string pkgName, string resName)
{
if (string.IsNullOrEmpty(pkgName) || string.IsNullOrEmpty(resName))
{
Debug.LogError($"空名称 无法取到这个包信息 请检查");
return null;
}
if (!g_UIPathToPkgInfo.ContainsKey(pkgName))
{
Debug.LogError($"不存在这个包信息 请检查 {pkgName}");
return null;
}
if (g_UIPathToPkgInfo[pkgName].TryGetValue(resName, out var vo))
{
return vo;
}
Debug.LogError($"未获取到这个包信息 请检查 {pkgName} {resName}");
return null;
}
/// <summary>
/// 根据panelName获取
/// 只有是panel才会存在的信息
/// 非Panel请使用其他
/// </summary>
internal static UIBindVo? GetBindVoByPanelName(string panelName)
{
if (string.IsNullOrEmpty(panelName))
{
Debug.LogError($"空名称 无法取到这个包信息 请检查");
return null;
}
if (g_UIPanelNameToPkgInfo.TryGetValue(panelName, out var vo))
{
return vo;
}
Debug.LogError($"未获取到这个包信息 请检查 {panelName}");
return null;
}
/// <summary>
/// 重置 慎用
/// </summary>
public static void Reset()
{
if (g_UITypeToPkgInfo != null)
{
g_UITypeToPkgInfo.Clear();
g_UITypeToPkgInfo = null;
}
if (g_UIPathToPkgInfo != null)
{
g_UIPathToPkgInfo.Clear();
g_UIPathToPkgInfo = null;
}
if (g_UIPanelNameToPkgInfo != null)
{
g_UIPanelNameToPkgInfo.Clear();
g_UIPanelNameToPkgInfo = null;
}
IsInit = false;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d09de6223df6425081b47e22385f3747
timeCreated: 1682217977

View File

@@ -0,0 +1,151 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace YIUIFramework
{
internal class UIBindProvider : ICodeGenerator<UIBindVo>
{
//业务代码相关程序集的名字
//默认有Unity默认程序集 可以根据需求修改
internal static string[] LogicAssemblyNames = { "Assembly-CSharp" };
private static Type[] GetLogicTypes()
{
return AppDomain.CurrentDomain.GetTypesByAssemblyName(LogicAssemblyNames);
}
private Type m_BasePanelType = typeof(BasePanel);
private Type m_BaseViewType = typeof(BaseView);
private Type m_BaseComponentType = typeof(BaseComponent);
public UIBindVo[] Get()
{
var gameTypes = GetLogicTypes();
if (gameTypes.Length < 1)
{
return Array.Empty<UIBindVo>();
}
var panelTypes = new List<Type>(); //继承panel的
var viewTypes = new List<Type>(); //继承View的
var componentTypes = new List<Type>(); //继承Component的
var binds = new List<UIBindVo>();
foreach (var gameType in gameTypes)
{
if (m_BasePanelType.IsAssignableFrom(gameType))
{
panelTypes.Add(gameType);
}
else if (m_BaseViewType.IsAssignableFrom(gameType))
{
viewTypes.Add(gameType);
}
else if (m_BaseComponentType.IsAssignableFrom(gameType))
{
componentTypes.Add(gameType);
}
}
//panel绑定
foreach (var panelType in panelTypes)
{
if (panelType.BaseType == null)
{
continue;
}
if (GetBindVo(panelType.BaseType, panelType, m_BasePanelType, out var bindVo))
{
binds.Add(bindVo);
}
}
//view绑定
foreach (var viewType in viewTypes)
{
if (viewType.BaseType == null)
{
continue;
}
if (GetBindVo(viewType.BaseType, viewType, m_BaseViewType, out var bindVo))
{
binds.Add(bindVo);
}
}
//component绑定
foreach (var componentType in componentTypes)
{
if (componentType.BaseType == null)
{
continue;
}
if (GetBindVo(componentType.BaseType, componentType, m_BaseComponentType, out var bindVo))
{
binds.Add(bindVo);
}
}
return binds.ToArray();
}
private static bool GetBindVo(Type uiBaseType, Type creatorType, Type groupType, out UIBindVo bindVo)
{
bindVo = new UIBindVo();
if (uiBaseType == null ||
!uiBaseType.GetFieldValue("PkgName", out bindVo.PkgName) ||
!uiBaseType.GetFieldValue("ResName", out bindVo.ResName))
{
return false;
}
bindVo.CodeType = uiBaseType.BaseType;
bindVo.BaseType = uiBaseType;
bindVo.CreatorType = creatorType;
return true;
}
public void WriteCode(UIBindVo info, StringBuilder sb)
{
sb.Append(" {\r\n");
sb.AppendFormat(" PkgName = {0}.PkgName,\r\n", info.BaseType.FullName);
sb.AppendFormat(" ResName = {0}.ResName,\r\n", info.BaseType.FullName);
sb.AppendFormat(" CodeType = {0},\r\n", GetCodeTypeName(info.CodeType));
sb.AppendFormat(" BaseType = typeof({0}),\r\n", info.BaseType.FullName);
sb.AppendFormat(" CreatorType = typeof({0}),\r\n", info.CreatorType.FullName);
sb.Append(" };\r\n");
}
private string GetCodeTypeName(Type uiBaseType)
{
if (uiBaseType == m_BasePanelType)
{
return UIStaticHelper.UIBasePanelName;
}
else if (uiBaseType == m_BaseViewType)
{
return UIStaticHelper.UIBaseViewName;
}
else if (uiBaseType == m_BaseComponentType)
{
return UIStaticHelper.UIBaseComponentName;
}
else
{
Debug.LogError($"当前类型错误 是否新增了类型 {uiBaseType}");
return UIStaticHelper.UIBaseName;
}
}
public void NewCode(UIBindVo info, StringBuilder sb)
{
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e96ffe5c3d54fef915c3a7845173cb1
timeCreated: 1682218117

View File

@@ -0,0 +1,25 @@
using System;
namespace YIUIFramework
{
/// <summary>
/// UI资源绑定信息
/// </summary>
public struct UIBindVo
{
//基类
public Type CodeType; //Panel/View/Component
//当前继承类
public Type BaseType; //他继承的类 就是 当前 + Base
//当前类
public Type CreatorType;
//包名/模块名
public string PkgName;
//资源名
public string ResName;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e6d04d42ac04fcd8433e8eeaeb75889
timeCreated: 1682218000

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: af93bc2020e44d85a4c9353fc1a60f80
timeCreated: 1681898432

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 13b1b428c583478b88e85cff6663d5dc
timeCreated: 1681899208

View File

@@ -0,0 +1,75 @@
using Sirenix.OdinInspector;
namespace YIUIFramework
{
//不要修改值 否则已存在的界面会错误
//只能新增 不允许修改
/// <summary>
/// 层级类型
/// </summary>
[LabelText("层级类型")]
public enum EPanelLayer
{
/// <summary>
/// 最高层
/// 一般新手引导之类的
/// </summary>
[LabelText("最高层")]
Top = 0,
/// <summary>
/// 提示层
/// 一般 提示飘字 确认弹窗 跑马灯之类的
/// </summary>
[LabelText("提示层")]
Tips = 1,
/// <summary>
/// 弹窗层
/// 一般是非全屏界面,可同时存在的
/// </summary>
[LabelText("弹窗层")]
Popup = 2,
/// <summary>
/// 普通面板层
/// 全屏界面 所有Panel打开关闭受回退功能影响
/// </summary>
[LabelText("面板层")]
Panel = 3,
/// <summary>
/// 场景层
/// 比如 血条飘字不是做在3D时 用2D实现时的层
/// 比如 头像 ...
/// </summary>
[LabelText("场景层")]
Scene = 4,
/// <summary>
/// 最低层
/// 要显示的这个就是最低的层级
/// </summary>
[LabelText("最低层")]
Bottom = 5,
/// <summary>
/// 缓存层 需要缓存的暂存的丢这里
/// 这个界面不做显示 会被强制隐藏的
/// </summary>
[LabelText("")]
Cache = 6,
/// <summary>
/// 只是用来记录数量,不可用
/// </summary>
[LabelText("")]
Count = 7,
/// <summary>
/// 所有层,不可用
/// </summary>
[LabelText("")]
Any = 8,
}
}

Some files were not shown because too many files have changed in this diff Show More