diff --git a/Runtime/Helper/GridLayoutCalculator.cs b/Runtime/Helper/GridLayoutCalculator.cs
index 503389d..c86f21d 100644
--- a/Runtime/Helper/GridLayoutCalculator.cs
+++ b/Runtime/Helper/GridLayoutCalculator.cs
@@ -32,7 +32,7 @@ namespace XericUI.Helper
/// 子项对齐
///
public static List CalculateGridLayout(
- List layoutItems,
+ ref List layoutItems,
int childCount,
Vector2 containerSize,
Vector2 cellSize,
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute.meta
new file mode 100644
index 0000000..ca52e5a
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 29bdb71088ff44dd85e7485c8df8cd69
+timeCreated: 1777358662
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/IXuiavrgAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/IXuiavrgAttribute.cs
similarity index 100%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/IXuiavrgAttribute.cs
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/IXuiavrgAttribute.cs
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/IXuiavrgAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/IXuiavrgAttribute.cs.meta
similarity index 100%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/IXuiavrgAttribute.cs.meta
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/IXuiavrgAttribute.cs.meta
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgAttribute.cs
similarity index 93%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgAttribute.cs
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgAttribute.cs
index 80a349a..146995b 100644
--- a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgAttribute.cs
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgAttribute.cs
@@ -13,7 +13,6 @@ namespace XericUI.ReflectionUIGenerator
public readonly string LabelName;
public readonly string UIPropertyName;
public readonly string UnitLabelName;
- public readonly bool MustFillIn;
public readonly int InspectorOrder;
public readonly string GroupName;
public readonly string OnTriggerCall;
@@ -30,13 +29,12 @@ namespace XericUI.ReflectionUIGenerator
/// 属性组名称(可以是以/&\分割的路径)
/// 属性附加的动作,调用此内联反射调用的函数
/// 属性组名称(可以是以/&\分割的路径)
- public XuiavrgAttribute(string labelName, string uiPropertyName, string unitLabelName, bool mustFillin,
+ public XuiavrgAttribute(string labelName, string uiPropertyName, string unitLabelName,
int inspectorOrder = 0, string groupName = null, string onTriggerCall = "", XuiavrgSize size = XuiavrgSize.Normal)
{
LabelName = labelName;
UIPropertyName = uiPropertyName;
UnitLabelName = unitLabelName;
- MustFillIn = mustFillin;
InspectorOrder = inspectorOrder;
GroupName = groupName;
OnTriggerCall = onTriggerCall;
@@ -52,7 +50,6 @@ namespace XericUI.ReflectionUIGenerator
property.labelName = LabelName;
property.uiPropertyName = UIPropertyName;
property.unitLabelName = UnitLabelName;
- property.mustFillIn = MustFillIn;
property.inspectorOrder = InspectorOrder;
property.groupName = GroupName;
property.onTriggerCall = OnTriggerCall;
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgAttribute.cs.meta
similarity index 100%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgAttribute.cs.meta
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgAttribute.cs.meta
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs
new file mode 100644
index 0000000..da28c4a
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs
@@ -0,0 +1,28 @@
+using System;
+
+namespace XericUI.ReflectionUIGenerator
+{
+ ///
+ /// 集合检查
+ ///
+ public class XuiavrgCollectionCheckAttribute : Attribute, IXuiavrgAttribute
+ {
+ public readonly int minCount;
+ public readonly int maxCount;
+ public readonly bool notEmpty;
+
+ public XuiavrgCollectionCheckAttribute(int minCount, int maxCount, bool notEmpty)
+ {
+ this.minCount = minCount;
+ this.maxCount = maxCount;
+ this.notEmpty = notEmpty;
+ }
+
+ public void BindProperty(XuiavrgInspectorProperty property)
+ {
+ property.collectionMinCount = minCount;
+ property.collectionMaxCount = maxCount;
+ property.collectionNotEmpty = notEmpty;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs.meta
new file mode 100644
index 0000000..e4211a9
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgCollectionCheckAttribute.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 4ec4224cb3844c439dd5fdb6b31c9730
+timeCreated: 1777363387
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgHideAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgHideAttribute.cs
similarity index 100%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgHideAttribute.cs
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgHideAttribute.cs
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgHideAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgHideAttribute.cs.meta
similarity index 100%
rename from Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgHideAttribute.cs.meta
rename to Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgHideAttribute.cs.meta
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs
new file mode 100644
index 0000000..3e56035
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace XericUI.ReflectionUIGenerator
+{
+ ///
+ /// 不可为空
+ ///
+ public class XuiavrgNotEmptyAttribute : Attribute, IXuiavrgAttribute
+ {
+ public void BindProperty(XuiavrgInspectorProperty property)
+ {
+ property.notEmpty = true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs.meta
new file mode 100644
index 0000000..031e93f
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNotEmptyAttribute.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 89e35e544d66421c8cc524d3b4d7b943
+timeCreated: 1777360693
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs
new file mode 100644
index 0000000..db02e91
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs
@@ -0,0 +1,25 @@
+using System;
+
+namespace XericUI.ReflectionUIGenerator
+{
+ ///
+ /// 数值检查
+ ///
+ public class XuiavrgNumberCheckAttribute : Attribute, IXuiavrgAttribute
+ {
+ public readonly float minValue;
+ public readonly float maxValue;
+
+ public XuiavrgNumberCheckAttribute(float minValue, float maxValue)
+ {
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ }
+
+ public void BindProperty(XuiavrgInspectorProperty property)
+ {
+ property.numberMinValue = minValue;
+ property.numberMaxValue = maxValue;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs.meta
new file mode 100644
index 0000000..86aa0ae
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgNumberCheckAttribute.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: d5b533c6d6ca4de8811adc3913d1fd9b
+timeCreated: 1777362005
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs
new file mode 100644
index 0000000..03c16a7
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace XericUI.ReflectionUIGenerator
+{
+ ///
+ /// 必填
+ ///
+ public class XuiavrgRequiredAttribute : Attribute, IXuiavrgAttribute
+ {
+ public void BindProperty(XuiavrgInspectorProperty property)
+ {
+ property.required = true;
+ property.notEmpty = true;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs.meta
new file mode 100644
index 0000000..51f13ad
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgRequiredAttribute.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: bcc4b8b735e84251b11ef87e9fe5b2cb
+timeCreated: 1777358718
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs
new file mode 100644
index 0000000..0d53691
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs
@@ -0,0 +1,48 @@
+using System;
+using UnityEngine;
+
+namespace XericUI.ReflectionUIGenerator
+{
+ ///
+ /// 字符串检查
+ ///
+ public class XuiavrgStringCheckAttribute : Attribute, IXuiavrgAttribute
+ {
+ public readonly int minLength;
+ public readonly int maxLength;
+ public readonly string regexPattern;
+ public readonly bool onlyLetters;
+ public readonly bool onlyNumber;
+ public readonly bool onlyEmail;
+ public readonly bool onlyPhone;
+ public readonly bool onlyUrl;
+
+ public XuiavrgStringCheckAttribute(
+ int minLength = 0, int maxLength = int.MaxValue,
+ string regexPattern = "",
+ bool onlyLetters = false, bool onlyNumber = false, bool onlyEmail = true, bool onlyPhone = true,
+ bool onlyUrl = true)
+ {
+ this.minLength = minLength;
+ this.maxLength = maxLength;
+ this.regexPattern = regexPattern;
+ this.onlyLetters = onlyLetters;
+ this.onlyNumber = onlyNumber;
+ this.onlyEmail = onlyEmail;
+ this.onlyPhone = onlyPhone;
+ this.onlyUrl = onlyUrl;
+ }
+
+ public void BindProperty(XuiavrgInspectorProperty property)
+ {
+ property.stringMinLength = minLength;
+ property.stringMaxLength = maxLength;
+ property.stringRegexPattern = regexPattern;
+ property.stringOnlyLetters = onlyLetters;
+ property.stringOnlyNumber = onlyNumber;
+ property.stringOnlyEmail = onlyEmail;
+ property.stringOnlyPhone = onlyPhone;
+ property.stringOnlyUrl = onlyUrl;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs.meta b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs.meta
new file mode 100644
index 0000000..54e4288
--- /dev/null
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/Attribute/XuiavrgStringCheckAttribute.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0a0e34665ed24a7c87e5eb84a45f6ef6
+timeCreated: 1777360997
\ No newline at end of file
diff --git a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgInspectorProperty.cs b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgInspectorProperty.cs
index 972a807..8623c00 100644
--- a/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgInspectorProperty.cs
+++ b/Runtime/InterfaceAttributeReflectionGenerator/Scripts/XuiavrgInspectorProperty.cs
@@ -1,5 +1,6 @@
using System;
using System.Reflection;
+using UnityEngine;
using UnityEngine.Serialization;
namespace XericUI.ReflectionUIGenerator
@@ -10,22 +11,48 @@ namespace XericUI.ReflectionUIGenerator
[Serializable]
public class XuiavrgInspectorProperty
{
+ #region 字段属性
+
public object valueTarget;
public bool isProperty;
public PropertyInfo propertyInfo;
public FieldInfo fieldInfo;
- public string labelName;
- public string uiPropertyName;
- public string unitLabelName;
- public bool mustFillIn;
- public int inspectorOrder;
- public string groupName;
- public string onTriggerCall;
- public XuiavrgSize argumentSize;
- public bool hideInInspector;
+ // 基本信息
+ public string labelName; // 字段名称
+ public string uiPropertyName; // ui属性名称
+ public string unitLabelName; // 单位名称
+ public bool required; // 项目必填
+ public bool notEmpty; // 不可为空
+ public int inspectorOrder; // 显示在检查器上的顺序
+ public string groupName; // 编组名称
+ public string onTriggerCall; // 值变更时触发的反射
+ public XuiavrgSize argumentSize; // 属性尺寸
+ public bool hideInInspector; // 在检查器上隐藏显示
+
+ // 字符串检查
+ public int stringMinLength; // 最小长度
+ public int stringMaxLength = int.MaxValue; // 最大长度
+ public string stringRegexPattern = ""; // 正则检查
+ public bool stringOnlyLetters; // 允许字符
+ public bool stringOnlyNumber; // 允许数字
+ public bool stringOnlyEmail = true; // 允许邮箱
+ public bool stringOnlyPhone = true; // 允许电话号码
+ public bool stringOnlyUrl = true; // 允许网址
+ // 数值检查
+ public float numberMinValue; // 最小值
+ public float numberMaxValue; // 最大值
+
+ // 集合检查
+ public int collectionMinCount; // 集合的最小尺寸
+ public int collectionMaxCount = int.MaxValue; // 集合的最大尺寸
+ public bool collectionNotEmpty; // 集合不可为空
+
+ #endregion
+ #region 检查方法
+
///
/// 绑定到数据端
///
@@ -138,5 +165,7 @@ namespace XericUI.ReflectionUIGenerator
public void Clear()
{
}
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/Runtime/OverrideLayout/XericScrollRect.cs b/Runtime/OverrideLayout/XericScrollRect.cs
index 8c82b51..3403376 100644
--- a/Runtime/OverrideLayout/XericScrollRect.cs
+++ b/Runtime/OverrideLayout/XericScrollRect.cs
@@ -136,13 +136,15 @@ namespace XericUI.OverrideLayout
protected void RefreshPivot()
{
- if (!item)
+ var itemRect = itemRectTransform;
+ if (!itemRect)
{
Debug.LogError($"滚动视图的实体对象在刷新前并未指定,请先指定{nameof(item)}后再调用{nameof(RefreshPivot)}");
}
- parentScrollRect.UpdateChildPivot(layout, item.RectTransform());
- itemRectTransform.anchoredPosition = layout.position;
+ parentScrollRect.UpdateChildPivot(layout, itemRect);
+ itemRect.anchoredPosition = layout.position;
+ itemRect.SetDeltaSize(layout.size);
}
public void UpdateLayout(GridLayoutCalculator.LayoutItem layoutData)
@@ -311,19 +313,19 @@ namespace XericUI.OverrideLayout
// 将视口尺寸转换到content本地空间
// 手动计算视口在content空间的矩形
viewport.GetWorldCorners(viewportVertex);
+ var preloadMarginVec2 = new Vector3(m_preloadMargin, m_preloadMargin);
var viewportRect = new Rect(
- viewportVertex[0],
- viewportVertex[2] - viewportVertex[0]);
+ viewportVertex[0] - preloadMarginVec2,
+ viewportVertex[2] - viewportVertex[0] + preloadMarginVec2 + preloadMarginVec2);
+
+ // 扩展可见区域边界
+ visibleMin = viewportRect.min;
+ visibleMax = viewportRect.max;
var contentRect = content.rect;
// 计算预加载边距(考虑content缩放)
// var scaledMargin = preloadMargin / ((content.lossyScale.x + content.lossyScale.y) * 0.5f);
- // 扩展可见区域边界
- var preloadMarginVec2 = new Vector2(m_preloadMargin, m_preloadMargin);
- visibleMin = viewportRect.min - preloadMarginVec2;
- visibleMax = viewportRect.max + preloadMarginVec2;
-
// 获取当前滚动归一化位置
// var scrollPos = new Vector2(
// horizontal ? horizontalScrollbar?.value ?? 0 : 0,
@@ -363,14 +365,7 @@ namespace XericUI.OverrideLayout
}
}
- bool CheckIsVisibal(Vector2 pos)
- {
- return
- pos.x >= visibleMin.x &&
- pos.x <= visibleMax.x &&
- pos.y >= visibleMin.y &&
- pos.y <= visibleMax.y;
- }
+ bool CheckIsVisibal(Vector2 pos) => viewportRect.Contains(pos);
}
#endregion
@@ -485,35 +480,19 @@ namespace XericUI.OverrideLayout
private void RefreshContentSizeByChildrenLayouts(List layoutItems)
{
if (layoutItems.Count == 0) return;
-
- var first = layoutItems[0];
- var last = layoutItems[^1];
-
- var size = first.position - last.position;
- size = size.Abs();
-
- // 计算实际使用的行列数
- int maxRow = (int)GridLayoutCalculator.Grid.x;
- int maxColumn = (int)GridLayoutCalculator.Grid.y;
- foreach (var item in layoutItems)
- {
- maxRow = Mathf.Max(maxRow, item.rowIndex);
- maxColumn = Mathf.Max(maxColumn, item.columnIndex);
- }
-
- int actualCellCountX = maxColumn + 1;
- int actualCellCountY = maxRow + 1;
-
- var spacing = new Vector2((actualCellCountX - 1) * m_spacing.x, (actualCellCountY - 1) * m_spacing.y);
+ var size = Vector2.zero;
+ var spacing = new Vector2(
+ GridLayoutCalculator.Grid.y * m_spacing.x,
+ GridLayoutCalculator.Grid.x * m_spacing.y);
switch (m_startAxis)
{
case GridLayoutGroup.Axis.Horizontal:
- size.x = Mathf.Max(size.x, viewport.rect.width);
- size.y = Mathf.Max(size.y + m_spacing.y, m_cellSize.y);
+ size.x = Mathf.Max(spacing.x, viewport.rect.width);
+ size.y = Mathf.Max(spacing.y, m_cellSize.y);
break;
case GridLayoutGroup.Axis.Vertical:
- size.x = Mathf.Max(size.x + m_spacing.x, m_cellSize.x);
- size.y = Mathf.Max(size.y, viewport.rect.height);
+ size.x = Mathf.Max(spacing.x, m_cellSize.x);
+ size.y = Mathf.Max(spacing.y, viewport.rect.height);
break;
}
@@ -568,7 +547,7 @@ namespace XericUI.OverrideLayout
constraintCount = m_constraintCount;
return GridLayoutCalculator.CalculateGridLayout(
- _layoutItems,
+ ref _layoutItems,
childCount: childrenCount,
containerSize: ContextSize,
cellSize: m_cellSize,