Skip to content

Commit

Permalink
https://github.com/qiankanglai/LoopScrollRect/issues/5
Browse files Browse the repository at this point in the history
Fix GridLayout, thanks to @wumiliu
  • Loading branch information
qiankanglai committed Sep 20, 2016
1 parent 753ab70 commit 4902dae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
13 changes: 11 additions & 2 deletions Assets/Scripts/LoopHorizontalScrollRect.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using UnityEngine;
using System.Collections;


namespace UnityEngine.UI
{
public class LoopHorizontalScrollRect : LoopScrollRect
{
protected override float GetSize(RectTransform item)
{
return LayoutUtility.GetPreferredWidth(item) + contentSpacing;
float size = contentSpacing;
if (m_GridLayout != null)
{
size += m_GridLayout.cellSize.x;
}
else
{
size += LayoutUtility.GetPreferredWidth(item);
}
return size;
}

protected override float GetDimension(Vector2 vector)
Expand Down
10 changes: 4 additions & 6 deletions Assets/Scripts/LoopScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public abstract class LoopScrollRect : UIBehaviour, IInitializePotentialDragHand
protected int directionSign = 0;

private float m_ContentSpacing = -1;
protected GridLayoutGroup m_GridLayout = null;
protected float contentSpacing
{
get
Expand All @@ -51,13 +52,10 @@ protected float contentSpacing
{
m_ContentSpacing = layout1.spacing;
}
else
m_GridLayout = content.GetComponent<GridLayoutGroup>();
if (m_GridLayout != null)
{
GridLayoutGroup layout2 = content.GetComponent<GridLayoutGroup>();
if (layout2 != null)
{
m_ContentSpacing = GetDimension(layout2.spacing);
}
m_ContentSpacing = GetDimension(m_GridLayout.spacing);
}
}
return m_ContentSpacing;
Expand Down
13 changes: 11 additions & 2 deletions Assets/Scripts/LoopVerticalScrollRect.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;


namespace UnityEngine.UI
{
public class LoopVerticalScrollRect : LoopScrollRect
{
protected override float GetSize(RectTransform item)
{
return LayoutUtility.GetPreferredHeight(item) + contentSpacing;
float size = contentSpacing;
if (m_GridLayout != null)
{
size += m_GridLayout.cellSize.y;
}
else
{
size += LayoutUtility.GetPreferredHeight(item);
}
return size;
}

protected override float GetDimension(Vector2 vector)
Expand Down

0 comments on commit 4902dae

Please sign in to comment.