Skip to content

Commit

Permalink
新增View 相关操作
Browse files Browse the repository at this point in the history
  • Loading branch information
LiShengYang-yiyi committed May 19, 2024
1 parent 89d8a9e commit f2c9692
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 19 deletions.
42 changes: 42 additions & 0 deletions YIUIFramework/Panel/Base/Panel/BasePanel_CloseView.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
3 changes: 3 additions & 0 deletions YIUIFramework/Panel/Base/Panel/BasePanel_CloseView.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion YIUIFramework/Panel/Base/Panel/BasePanel_OpenView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private RectTransform GetViewParent(string viewName)
return value;
}

private async UniTask<T> GetView<T>() where T : BaseView, new()
private async UniTask<T> GetView<T>() where T : BaseView
{
var viewName = typeof(T).Name;
var parent = GetViewParent(viewName);
Expand All @@ -99,6 +99,45 @@ private RectTransform GetViewParent(string viewName)
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>
Expand Down
17 changes: 0 additions & 17 deletions YIUIFramework/Panel/Mgr/PanelMgr_API.cs

This file was deleted.

69 changes: 69 additions & 0 deletions YIUIFramework/Panel/Mgr/PanelMgr_Active.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace YIUIFramework
{
public partial class PanelMgr
{
#region 判断Panel是否存在且显示

public bool ActiveSelf(string panelName)
{
var info = GetPanelInfo(panelName);
return info?.ActiveSelf ?? false;
}

public bool ActiveSelf<T>() where T : BasePanel
{
var info = GetPanelInfo<T>();
return info?.ActiveSelf ?? false;
}

#endregion

#region 判断指定Panel的指定View是否存在且显示

public bool ActiveSelfView(string panelName, string viewName)
{
var info = GetPanelInfo(panelName);
if (info == null) return false;
if (info.UIBasePanel == null) return false;
var (exist, entity) = info.UIBasePanel.ExistView(viewName);
if (!exist) return false;
return entity.ActiveSelf;
}

public bool ActiveSelfView<TPanel, TView>()
where TPanel : BasePanel
where TView : BaseView
{
var info = GetPanelInfo<TPanel>();
if (info == null) return false;
if (info.UIBasePanel == null) return false;
var (exist, entity) = info.UIBasePanel.ExistView<TView>();
if (!exist) return false;
return entity.ActiveSelf;
}

public bool ActiveSelfViewByViewName<TPanel>(string viewName)
where TPanel : BasePanel
{
var info = GetPanelInfo<TPanel>();
if (info == null) return false;
if (info.UIBasePanel == null) return false;
var (exist, entity) = info.UIBasePanel.ExistView(viewName);
if (!exist) return false;
return entity.ActiveSelf;
}

public bool ActiveSelfViewByPanelName<TView>(string panelName)
where TView : BaseView
{
var info = GetPanelInfo(panelName);
if (info == null) return false;
if (info.UIBasePanel == null) return false;
var (exist, entity) = info.UIBasePanel.ExistView<TView>();
if (!exist) return false;
return entity.ActiveSelf;
}

#endregion
}
}
69 changes: 68 additions & 1 deletion YIUIFramework/Panel/Mgr/PanelMgr_Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{
public partial class PanelMgr
{
#region 获取指定Panel 必须是存在的 但不一定是打开的有可能是隐藏

//字符串类型获取 需要自己转换 建议不要使用
public BasePanel GetPanel(string panelName)
{
Expand All @@ -22,7 +24,72 @@ public T GetPanel<T>() where T : BasePanel
{
return (T)info.UIBasePanel;
}

return null;
}

#endregion

#region 获取指定Panel的指定View 必须是存在的 但不一定是打开的有可能是隐藏

//字符串类型获取 需要自己转换 建议不要使用
public BaseView GetPanelView(string panelName, string viewName)
{
var info = GetPanelInfo(panelName);
if (info == null) return null;
if (info.UIBasePanel == null) return null;
var (exist, view) = info.UIBasePanel.ExistView(viewName);
if (exist == false) return null;
return view;
}

/// <summary>
/// 获取指定Panel的指定View
/// 必须是存在的 但不一定是打开的有可能是隐藏
/// 这个只能表示对象存在
/// 不应该滥用 UI与UI之间还是应该使用消息通信 这个是为了解决部分问题
/// </summary>
public TView GetPanelView<TPanel, TView>()
where TPanel : BasePanel
where TView : BaseView
{
var info = GetPanelInfo<TPanel>();
if (info == null) return null;
if (info.UIBasePanel == null) return null;
var (exist, view) = info.UIBasePanel.ExistView<TView>();
if (exist == false) return null;
return (TView)view;
}

//字符串类型获取 需要自己转换 建议不要使用
public BaseView GetPanelViewByViewName<TPanel>(string viewName)
where TPanel : BasePanel
{
var info = GetPanelInfo<TPanel>();
if (info == null) return null;
if (info.UIBasePanel == null) return null;
var (exist, view) = info.UIBasePanel.ExistView(viewName);
if (!exist) return null;
return view;
}

/// <summary>
/// 获取指定Panel的指定View
/// 必须是存在的 但不一定是打开的有可能是隐藏
/// 这个只能表示对象存在
/// 不应该滥用 UI与UI之间还是应该使用消息通信 这个是为了解决部分问题
/// </summary>
public TView GetPanelViewByPanelName<TView>(string panelName)
where TView : BaseView
{
var info = GetPanelInfo(panelName);
if (info == null) return null;
if (info.UIBasePanel == null) return null;
var (exist, view) = info.UIBasePanel.ExistView<TView>();
if (exist == false) return null;
return (TView)view;
}

#endregion
}
}
}

0 comments on commit f2c9692

Please sign in to comment.