添加输入系统帮助
This commit is contained in:
@@ -14,10 +14,20 @@ using Component = UnityEngine.Component;
|
||||
namespace XericUI.FlipPage
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻页组件管理器
|
||||
///
|
||||
/// 对翻页组件的管理
|
||||
/// 翻页组件管理器(UI层)
|
||||
/// </summary>
|
||||
/// <code>
|
||||
/// 翻页组件层(UI)脚本,约束基本用法:
|
||||
///
|
||||
/// FlipPageComponentManager : XericFlipPageIndexVesselBase
|
||||
/// |-PageComponentInfo 页面组件结构
|
||||
/// | |-ItemComponentInfo 项目组件结构
|
||||
///
|
||||
/// 组件层使用组件容器封装,预设的组件引用可以实现类似下面的样式
|
||||
/// |< < 2,3,4 > >|
|
||||
/// 两侧是固定的按钮,中间是一个横向的排列容器,在指定了按钮对象池后,将会自动生成绑定好的按钮用于翻页。
|
||||
/// 页数按钮需要让button在预制体最外层,它的子集中需要包含一个TMP_Text。
|
||||
/// </code>
|
||||
public class FlipPageComponentManager : XericFlipPageIndexVesselBase
|
||||
{
|
||||
#region 界面属性
|
||||
|
||||
@@ -12,10 +12,22 @@ using XericUI.Core.Vessel;
|
||||
namespace XericUI.FlipPage
|
||||
{
|
||||
/// <summary>
|
||||
/// 翻页管理器
|
||||
/// 翻页管理器(逻辑层)
|
||||
/// </summary>
|
||||
/// <code>
|
||||
/// 翻页允许按页,按项目进行管理。
|
||||
/// 翻页逻辑层脚本,约束基本用法:
|
||||
///
|
||||
/// XericFlipPageIndexVesselBase 逻辑层管理器
|
||||
/// |-PageInfo 页面数据结构
|
||||
/// | |-ItemInfo 项目数据结构
|
||||
///
|
||||
/// 基本用法应该是,添加数据项目,这会自动分配到有效的页面中;
|
||||
/// 如果页面项目已满,则新建一个页面继续填充项目。
|
||||
/// 或者直接创建页面,将需要的数据项目直接写在页面数据中。
|
||||
///
|
||||
/// 使用FlipPage()翻页,这会立刻执行,并触发OnFlipPage函数,
|
||||
/// currentPageIndex可以获取当前页数,Currentpage获取当前页面数据;
|
||||
/// 在页面数据中pageNumber可以获取自己所在的页数,itemInfos获取页面中的所有数据项目。
|
||||
/// </code>
|
||||
public class XericFlipPageIndexVesselBase : XericUIBehaciour
|
||||
{
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1b1471c80dc411bb9c2745a091dc801
|
||||
timeCreated: 1753776687
|
||||
@@ -0,0 +1,110 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using XericLibrary.Runtime.MacroLibrary;
|
||||
|
||||
namespace XericUI.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// UI输入系统帮助
|
||||
/// </summary>
|
||||
public static class EventSystemHelper
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
private static int raycastResultsFrameIndex = -1;
|
||||
public static List<RaycastResult> raycastResults = new List<RaycastResult>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助功能
|
||||
|
||||
/// <summary>
|
||||
/// 根据重载可选覆盖返回的事件系统
|
||||
/// </summary>
|
||||
/// <param name="overrideEventSystem"></param>
|
||||
/// <returns></returns>
|
||||
private static EventSystem GetEventSystem(EventSystem overrideEventSystem = null)
|
||||
=> overrideEventSystem == null
|
||||
? EventSystem.current
|
||||
: overrideEventSystem;
|
||||
|
||||
/// <summary>
|
||||
/// 当前是否步进帧
|
||||
/// </summary>
|
||||
/// <param name="frameIndex"></param>
|
||||
/// <param name="holdon">保持状态</param>
|
||||
/// <returns></returns>
|
||||
private static bool IsFrameIndexChange(ref int frameIndex, bool holdon = false)
|
||||
{
|
||||
if (frameIndex == Time.frameCount)
|
||||
return false;
|
||||
if (holdon)
|
||||
return true;
|
||||
frameIndex = Time.frameCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 光标在其上
|
||||
|
||||
/// <summary>
|
||||
/// 判断当前光标是否处于任意UI对象上
|
||||
/// </summary>
|
||||
/// <param name="overrideEventSystem"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsPointerOverGameObject(EventSystem overrideEventSystem = null)
|
||||
{
|
||||
overrideEventSystem = GetEventSystem(overrideEventSystem);
|
||||
return overrideEventSystem.IsPointerOverGameObject();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动更新射线监测
|
||||
/// </summary>
|
||||
/// <param name="overrideEventSystem"></param>
|
||||
/// <returns></returns>
|
||||
public static List<RaycastResult> GetRaycastAllResults(EventSystem overrideEventSystem = null)
|
||||
{
|
||||
if (!IsFrameIndexChange(ref raycastResultsFrameIndex))
|
||||
return raycastResults;
|
||||
|
||||
overrideEventSystem = GetEventSystem(overrideEventSystem);
|
||||
var pointerData = new PointerEventData(overrideEventSystem)
|
||||
{
|
||||
position = Input.mousePosition
|
||||
};
|
||||
overrideEventSystem.RaycastAll(pointerData, raycastResults);
|
||||
return raycastResults;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断当前光标是否处于特定组件上
|
||||
/// </summary>
|
||||
/// <param name="component">返回找到的组件</param>
|
||||
/// <param name="compatibility">是否启用兼容性,当在所有击中的元素上找不到目标时,继续向上查找</param>
|
||||
/// <param name="overrideEventSystem"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static bool IsPointerOverUIWithComponent<T>(out T component, bool compatibility = true, EventSystem overrideEventSystem = null)
|
||||
where T : Component
|
||||
{
|
||||
var results = GetRaycastAllResults(overrideEventSystem);
|
||||
if (results.Count <= 0)
|
||||
{
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
component = results
|
||||
.Select(a => a.gameObject.GetComponent<T>())
|
||||
.FirstOrDefault(a => a != null);
|
||||
if (compatibility && component == null)
|
||||
component = results[^1].gameObject.GetComponentInParent<T>();
|
||||
return component != null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2386c74c7b74a18b9656a435572352d
|
||||
timeCreated: 1753776710
|
||||
Reference in New Issue
Block a user