修复显示bug
This commit is contained in:
parent
7ea22e0f05
commit
78aa102238
@ -945,9 +945,8 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 1076934826281074923}
|
- component: {fileID: 1076934826281074923}
|
||||||
- component: {fileID: 5301118011458687740}
|
|
||||||
- component: {fileID: 8755480884770592513}
|
- component: {fileID: 8755480884770592513}
|
||||||
- component: {fileID: 2032849314590666560}
|
- component: {fileID: 841870042491869694}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: ListContent
|
m_Name: ListContent
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -967,39 +966,13 @@ RectTransform:
|
|||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 683708360215293002}
|
m_Father: {fileID: 7980721957373656544}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
m_AnchorMax: {x: 0, y: 0}
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!114 &5301118011458687740
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1591183619690481046}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 30649d3a9faa99c48a7b1166b86bf2a0, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_Padding:
|
|
||||||
m_Left: 0
|
|
||||||
m_Right: 0
|
|
||||||
m_Top: 0
|
|
||||||
m_Bottom: 0
|
|
||||||
m_ChildAlignment: 3
|
|
||||||
m_Spacing: 0
|
|
||||||
m_ChildForceExpandWidth: 0
|
|
||||||
m_ChildForceExpandHeight: 0
|
|
||||||
m_ChildControlWidth: 1
|
|
||||||
m_ChildControlHeight: 1
|
|
||||||
m_ChildScaleWidth: 0
|
|
||||||
m_ChildScaleHeight: 0
|
|
||||||
m_ReverseArrangement: 0
|
|
||||||
--- !u!114 &8755480884770592513
|
--- !u!114 &8755480884770592513
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -1016,7 +989,7 @@ MonoBehaviour:
|
|||||||
CustomComponentName: ListContent
|
CustomComponentName: ListContent
|
||||||
CustomComment:
|
CustomComment:
|
||||||
mComponentName: RectTransform
|
mComponentName: RectTransform
|
||||||
--- !u!114 &2032849314590666560
|
--- !u!114 &841870042491869694
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
@ -1025,17 +998,17 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 1591183619690481046}
|
m_GameObject: {fileID: 1591183619690481046}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
|
m_Script: {fileID: 11500000, guid: 04acbd8265ebc9e4b8824e08b084e953, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_IgnoreLayout: 0
|
m_Padding:
|
||||||
m_MinWidth: -1
|
m_Left: 0
|
||||||
m_MinHeight: -1
|
m_Right: 0
|
||||||
m_PreferredWidth: -1
|
m_Top: 0
|
||||||
m_PreferredHeight: -1
|
m_Bottom: 0
|
||||||
m_FlexibleWidth: -1
|
m_ChildAlignment: 0
|
||||||
m_FlexibleHeight: -1
|
spacingX: 0
|
||||||
m_LayoutPriority: 1
|
spacingY: 0
|
||||||
--- !u!1 &2074544796856548067
|
--- !u!1 &2074544796856548067
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -3369,9 +3342,9 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 1}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 1}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 32.504997, y: 107.39996}
|
m_AnchoredPosition: {x: 14.999878, y: 88}
|
||||||
m_SizeDelta: {x: 35.01, y: 19.61}
|
m_SizeDelta: {x: 80.03, y: 19.61}
|
||||||
m_Pivot: {x: 0.5, y: 1}
|
m_Pivot: {x: -0.00000017136335, y: 0.00000078976154}
|
||||||
--- !u!222 &8371822126990485976
|
--- !u!222 &8371822126990485976
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -4030,7 +4003,7 @@ RectTransform:
|
|||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 1076934826281074923}
|
- {fileID: 7980721957373656544}
|
||||||
- {fileID: 8633842398434044872}
|
- {fileID: 8633842398434044872}
|
||||||
m_Father: {fileID: 7693151069151688728}
|
m_Father: {fileID: 7693151069151688728}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
@ -4266,8 +4239,8 @@ RectTransform:
|
|||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 1}
|
m_AnchorMin: {x: 0, y: 1}
|
||||||
m_AnchorMax: {x: 0, y: 1}
|
m_AnchorMax: {x: 0, y: 1}
|
||||||
m_AnchoredPosition: {x: 17.505, y: -9.805}
|
m_AnchoredPosition: {x: 40.015, y: -9.805}
|
||||||
m_SizeDelta: {x: 35.01, y: 19.61}
|
m_SizeDelta: {x: 80.03, y: 19.61}
|
||||||
m_Pivot: {x: 0.5, y: 0.5}
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
--- !u!222 &1941232802810836953
|
--- !u!222 &1941232802810836953
|
||||||
CanvasRenderer:
|
CanvasRenderer:
|
||||||
@ -4297,7 +4270,7 @@ MonoBehaviour:
|
|||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
m_text: "\u808C\u8089/"
|
m_text: "\u808C\u8089/123123"
|
||||||
m_isRightToLeft: 0
|
m_isRightToLeft: 0
|
||||||
m_fontAsset: {fileID: 11400000, guid: 97936a7b3a86809479ac89371e95b079, type: 2}
|
m_fontAsset: {fileID: 11400000, guid: 97936a7b3a86809479ac89371e95b079, type: 2}
|
||||||
m_sharedMaterial: {fileID: 168401102475399263, guid: 97936a7b3a86809479ac89371e95b079, type: 2}
|
m_sharedMaterial: {fileID: 168401102475399263, guid: 97936a7b3a86809479ac89371e95b079, type: 2}
|
||||||
@ -4697,6 +4670,90 @@ MonoBehaviour:
|
|||||||
m_FillOrigin: 0
|
m_FillOrigin: 0
|
||||||
m_UseSpriteMesh: 0
|
m_UseSpriteMesh: 0
|
||||||
m_PixelsPerUnitMultiplier: 1
|
m_PixelsPerUnitMultiplier: 1
|
||||||
|
--- !u!1 &8460087031516395123
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 7980721957373656544}
|
||||||
|
- component: {fileID: 5416135810207341871}
|
||||||
|
- component: {fileID: 7839656811540880901}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: GameObject
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!224 &7980721957373656544
|
||||||
|
RectTransform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8460087031516395123}
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children:
|
||||||
|
- {fileID: 1076934826281074923}
|
||||||
|
m_Father: {fileID: 683708360215293002}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
|
m_AnchorMax: {x: 0, y: 0}
|
||||||
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
|
m_Pivot: {x: 0.5, y: 0.5}
|
||||||
|
--- !u!114 &5416135810207341871
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8460087031516395123}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 59f8146938fff824cb5fd77236b75775, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_Padding:
|
||||||
|
m_Left: 0
|
||||||
|
m_Right: 0
|
||||||
|
m_Top: 0
|
||||||
|
m_Bottom: 0
|
||||||
|
m_ChildAlignment: 0
|
||||||
|
m_Spacing: 0
|
||||||
|
m_ChildForceExpandWidth: 1
|
||||||
|
m_ChildForceExpandHeight: 0
|
||||||
|
m_ChildControlWidth: 1
|
||||||
|
m_ChildControlHeight: 1
|
||||||
|
m_ChildScaleWidth: 0
|
||||||
|
m_ChildScaleHeight: 0
|
||||||
|
m_ReverseArrangement: 0
|
||||||
|
--- !u!114 &7839656811540880901
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 8460087031516395123}
|
||||||
|
m_Enabled: 0
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
m_IgnoreLayout: 0
|
||||||
|
m_MinWidth: -1
|
||||||
|
m_MinHeight: 25
|
||||||
|
m_PreferredWidth: -1
|
||||||
|
m_PreferredHeight: -1
|
||||||
|
m_FlexibleWidth: -1
|
||||||
|
m_FlexibleHeight: -1
|
||||||
|
m_LayoutPriority: 1
|
||||||
--- !u!1 &8477438582353967822
|
--- !u!1 &8477438582353967822
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
93
Assets/Scripts/Tools/CustomWrapGrid.cs
Normal file
93
Assets/Scripts/Tools/CustomWrapGrid.cs
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
[ExecuteAlways]
|
||||||
|
public class CustomWrapGrid : LayoutGroup
|
||||||
|
{
|
||||||
|
public float spacingX = 0f;
|
||||||
|
public float spacingY = 0f;
|
||||||
|
|
||||||
|
private float _containerWidth;
|
||||||
|
private Vector2 _currentPos;
|
||||||
|
// 新增变量记录总高度
|
||||||
|
private float _totalHeight;
|
||||||
|
protected override void OnEnable()
|
||||||
|
{
|
||||||
|
base.OnEnable();
|
||||||
|
CalculateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetLayoutHorizontal()
|
||||||
|
{
|
||||||
|
CalculateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetLayoutVertical()
|
||||||
|
{
|
||||||
|
// 这里需要空实现,因为布局逻辑在SetLayoutHorizontal中完成
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void CalculateLayoutInputVertical()
|
||||||
|
{
|
||||||
|
CalculateLayout();
|
||||||
|
float minHeight = _totalHeight;
|
||||||
|
SetLayoutInputForAxis(minHeight, minHeight, 0, 1); // 修正参数设置
|
||||||
|
}
|
||||||
|
|
||||||
|
void CalculateLayout()
|
||||||
|
{
|
||||||
|
_totalHeight = 0f; // 重置总高度
|
||||||
|
if (rectChildren.Count == 0) return;
|
||||||
|
|
||||||
|
_containerWidth = rectTransform.rect.width - padding.horizontal;
|
||||||
|
_currentPos = new Vector2(padding.left, -padding.top);
|
||||||
|
float rowHeight = 0f;
|
||||||
|
foreach (RectTransform child in rectChildren)
|
||||||
|
{
|
||||||
|
// 跳过隐藏的对象
|
||||||
|
if (!child.gameObject.activeSelf) continue;
|
||||||
|
|
||||||
|
// 获取子物体尺寸
|
||||||
|
float childWidth = LayoutUtility.GetPreferredWidth(child);
|
||||||
|
float childHeight = LayoutUtility.GetPreferredHeight(child);
|
||||||
|
|
||||||
|
// 换行判断
|
||||||
|
if (_currentPos.x + childWidth > _containerWidth - padding.right)
|
||||||
|
{
|
||||||
|
StartNewRow(ref _currentPos, ref rowHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置子物体位置
|
||||||
|
SetChildAlongAxis(child, 0, _currentPos.x, childWidth);
|
||||||
|
SetChildAlongAxis(child, 1, _currentPos.y, childHeight);
|
||||||
|
|
||||||
|
// 更新当前行状态
|
||||||
|
_currentPos.x += childWidth + spacingX;
|
||||||
|
rowHeight = Mathf.Max(rowHeight, childHeight);
|
||||||
|
}
|
||||||
|
// 最终加上最后一行高度
|
||||||
|
_totalHeight = Mathf.Abs(_currentPos.y) + rowHeight - padding.top;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartNewRow(ref Vector2 pos, ref float rowHeight)
|
||||||
|
{
|
||||||
|
pos.x = padding.left;
|
||||||
|
pos.y += rowHeight + spacingY;
|
||||||
|
rowHeight = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当子物体变化时自动刷新
|
||||||
|
protected override void OnRectTransformDimensionsChange()
|
||||||
|
{
|
||||||
|
base.OnRectTransformDimensionsChange();
|
||||||
|
CalculateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
protected override void OnValidate()
|
||||||
|
{
|
||||||
|
base.OnValidate();
|
||||||
|
CalculateLayout();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
11
Assets/Scripts/Tools/CustomWrapGrid.cs.meta
Normal file
11
Assets/Scripts/Tools/CustomWrapGrid.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 04acbd8265ebc9e4b8824e08b084e953
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
x
Reference in New Issue
Block a user