Skip to content

Commit

Permalink
Suggestion from qiankanglai#33
Browse files Browse the repository at this point in the history
  • Loading branch information
qiankanglai committed Jan 10, 2018
1 parent 89773fd commit 2ddadfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Assets/Scripts/LoopScrollPrefabSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,11 @@ public virtual GameObject GetObject()
}
return SG.ResourceManager.Instance.GetObjectFromPool(prefabName);
}

public virtual void ReturnObject(Transform go)
{
go.SendMessage("ScrollCellReturn", SendMessageOptions.DontRequireReceiver);
SG.ResourceManager.Instance.ReturnObjectToPool(go.gameObject);
}
}
}
17 changes: 6 additions & 11 deletions Assets/Scripts/LoopScrollRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,6 @@ protected LoopScrollRect()
}

//==========LoopScrollRect==========
private void ReturnObjectAndSendMessage(Transform go)
{
go.SendMessage("ScrollCellReturn", SendMessageOptions.DontRequireReceiver);
SG.ResourceManager.Instance.ReturnObjectToPool(go.gameObject);
}

public void ClearCells()
{
Expand All @@ -292,7 +287,7 @@ public void ClearCells()
objectsToFill = null;
for (int i = content.childCount - 1; i >= 0; i--)
{
ReturnObjectAndSendMessage(content.GetChild(i));
prefabSource.ReturnObject(content.GetChild(i));
}
}
}
Expand Down Expand Up @@ -376,7 +371,7 @@ public void RefreshCells()
}
else
{
ReturnObjectAndSendMessage(content.GetChild(i));
prefabSource.ReturnObject(content.GetChild(i));
i--;
}
}
Expand All @@ -395,7 +390,7 @@ public void RefillCellsFromEnd(int offset = 0)

for (int i = m_Content.childCount - 1; i >= 0; i--)
{
ReturnObjectAndSendMessage(m_Content.GetChild(i));
prefabSource.ReturnObject(m_Content.GetChild(i));
}

float sizeToFill = 0, sizeFilled = 0;
Expand Down Expand Up @@ -434,7 +429,7 @@ public void RefillCells(int offset = 0)
// Don't `Canvas.ForceUpdateCanvases();` here, or it will new/delete cells to change itemTypeStart/End
for (int i = m_Content.childCount - 1; i >= 0; i--)
{
ReturnObjectAndSendMessage(m_Content.GetChild(i));
prefabSource.ReturnObject(m_Content.GetChild(i));
}

float sizeToFill = 0, sizeFilled = 0;
Expand Down Expand Up @@ -501,7 +496,7 @@ protected float DeleteItemAtStart()
{
RectTransform oldItem = content.GetChild(0) as RectTransform;
size = Mathf.Max(GetSize(oldItem), size);
ReturnObjectAndSendMessage(oldItem);
prefabSource.ReturnObject(oldItem);

itemTypeStart++;

Expand Down Expand Up @@ -568,7 +563,7 @@ protected float DeleteItemAtEnd()
{
RectTransform oldItem = content.GetChild(content.childCount - 1) as RectTransform;
size = Mathf.Max(GetSize(oldItem), size);
ReturnObjectAndSendMessage(oldItem);
prefabSource.ReturnObject(oldItem);

itemTypeEnd--;
if (itemTypeEnd % contentConstraintCount == 0 || content.childCount == 0)
Expand Down

0 comments on commit 2ddadfd

Please sign in to comment.