Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: internal void UpdateVisible()
{
//If there are no objects in the scene or a mask, exit
if (!MaskArea || ChildObjects == null || ChildObjects.Length < 1 || _screensContainer.childCount < 1)
{
return;
}
_maskSize = _isVertical ? MaskArea.rect.height : MaskArea.rect.width;
_halfNoVisibleItems = (int)Math.Round(_maskSize / (_childSize * MaskBuffer), MidpointRounding.AwayFromZero) / 2;
_bottomItem = _topItem = 0;
//work out how many items below the current page can be visible
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
{
_bottomItem = _currentPage - i < 0 ? 0 : i;
if (_bottomItem > 0) break;
}
//work out how many items above the current page can be visible
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
{
_topItem = _screensContainer.childCount - _currentPage - i < 0 ? 0 : i;
if (_topItem > 0) break;
}
//Set the active items active
for (int i = CurrentPage - _bottomItem; i < CurrentPage + _topItem; i++)
{
try
{
ChildObjects[i].SetActive(true);
}
catch
{
Debug.Log("Failed to setactive child [" + i + "]");
}
}
//Deactivate items out of visibility at the bottom of the ScrollRect Mask (only on scroll)
if (_currentPage > _halfNoVisibleItems) ChildObjects[CurrentPage - _bottomItem].SetActive(false);
//Deactivate items out of visibility at the top of the ScrollRect Mask (only on scroll)
if (_screensContainer.childCount - _currentPage > _topItem) ChildObjects[CurrentPage + _topItem].SetActive(false);
}
{
//If there are no objects in the scene or a mask, exit
if (!MaskArea || ChildObjects == null || ChildObjects.Length < 1 || _screensContainer.childCount < 1)
{
return;
}
_maskSize = _isVertical ? MaskArea.rect.height : MaskArea.rect.width;
_halfNoVisibleItems = (int)Math.Round(_maskSize / (_childSize * MaskBuffer), MidpointRounding.AwayFromZero) / 2;
_bottomItem = _topItem = 0;
//work out how many items below the current page can be visible
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
{
_bottomItem = _currentPage - i < 0 ? 0 : i;
if (_bottomItem > 0) break;
}
//work out how many items above the current page can be visible
for (int i = _halfNoVisibleItems + 1; i > 0; i--)
{
_topItem = _screensContainer.childCount - _currentPage - i < 0 ? 0 : i;
if (_topItem > 0) break;
}
//Set the active items active
for (int i = CurrentPage - _bottomItem; i < CurrentPage + _topItem; i++)
{
try
{
ChildObjects[i].SetActive(true);
}
catch
{
Debug.Log("Failed to setactive child [" + i + "]");
}
}
//Deactivate items out of visibility at the bottom of the ScrollRect Mask (only on scroll)
if (_currentPage > _halfNoVisibleItems) ChildObjects[CurrentPage - _bottomItem].SetActive(false);
//Deactivate items out of visibility at the top of the ScrollRect Mask (only on scroll)
if (_screensContainer.childCount - _currentPage > _topItem) ChildObjects[CurrentPage + _topItem].SetActive(false);
}