원본 블로그 주소 : http://idmanner.blog.me/70176641036
원본 블로그의 코드에서 수정한 코드입니다.
원본 블로그의 코드는 세로로 1개의 컬럼으로 ( 카톡게임 친구 창 ) 스크롤을 하는 방법입니다.
제가 하고자 한 것은 보여지는 아이콘이 4x4인 세로 스크롤 인벤토리입니다.
그래서 코드를 수정하게 되었고, 코드 정리 및 주석을 추가하였습니다.
( 세로 스크롤만 구현이 되었습니다. )
문제가 있을 시 삭제하겠습니다~
사용 방법 :
위 블로그에 들어가시면 나와있습니다만,
UIDraggablePanel2
- UIGrid
- items..
의 구조로 , Items는 cUIScrollListBase를 상속받는 객체로 프리팹이어야 합니다.
UIGrid에서 Max Per Line에 가로에 보여질 개수
Cell Width, Cell Height에 해당 items의 간격 크기를 설정합니다.
--------------------------------------------------------------------------------------------------------
업데이트 할 때마다 프리팹을 생성해야 하는 것이 부담스럽기 때문에,
생성된 객체를 재 사용하도록 코드를 수정하였다.
------------------------------------------------------------------------------------------------------------
아이템 간격의 가운데에서 스크롤 상 , 하를 조금씩 이동하면 계속 갱신하게 되어 깜빡임 문제가 발생하였다.
index가 head부터, tail 부터 다르게 인식이 되어 index가 꼬여버리는 문제가 원인.
UpdateCurrentPosition 함수 수정
재사용 스크롤 업데이트 및 NGUI 3.5 버전 대응
http://idmanner.blog.me/70176641036
UIScrollView2.cs 222 RestrictWithinBounds 함수 수정
- UpdateCurrentPosition 함수를 호출 하기 위해 override가 되었으나 호출이 안되는 RestrictWithinBounds(bool)함수를 override함
- 스프링에 의해 튕겨져서 아이템이 보여질 때 아이템아 안보이던 문제때문에 , 스프링 효과로 다시 되돌아 올 때 UpdateCurretPosition함수를 호출 하기 위함.
UIScrollView2.cs
/// <summary>
/// panel의 bounds 값 이내에 있는 객체만 스크롤이 가능 하도록한다.
/// </summary>
public override bool RestrictWithinBounds(bool instant, bool horizontal, bool vertical, SpringPanel.OnFinished finish = null)
{
return base.RestrictWithinBounds(instant, horizontal, vertical, UpdateCurrentPosition);
}
UIScrollView.cs
/// <summary>
/// Restrict the scroll view's contents to be within the scroll view's bounds.
/// </summary>
public bool RestrictWithinBounds (bool instant) { return RestrictWithinBounds(instant, true, true); }
/// <summary>
/// Restrict the scroll view's contents to be within the scroll view's bounds.
/// </summary>
public virtual bool RestrictWithinBounds (bool instant, bool horizontal, bool vertical, SpringPanel.OnFinished finish = null)
{
Bounds b = bounds;
Vector3 constraint = mPanel.CalculateConstrainOffset(b.min, b.max);
if (!horizontal) constraint.x = 0f;
if (!vertical) constraint.y = 0f;
if (constraint.sqrMagnitude > 0.1f)
{
if (!instant && dragEffect == DragEffect.MomentumAndSpring)
{
// Spring back into place
Vector3 pos = mTrans.localPosition + constraint;
pos.x = Mathf.Round(pos.x);
pos.y = Mathf.Round(pos.y);
SpringPanel.Begin(mPanel.gameObject, pos, 13f, finish);
}
else
{
// Jump back into place
MoveRelative(constraint);
mMomentum = Vector3.zero;
mScroll = 0f;
}
return true;
}
return false;
}
'Programming > Unity3D' 카테고리의 다른 글
[NGUI] TweenCount 구현 (0) | 2014.05.20 |
---|---|
[Unity3d] Unsupported enum type error (0) | 2014.04.05 |
[Unity3d] NGUI - scroll view 재사용 객체 (1) | 2014.03.24 |
[Unity3d] AssetDatabase save at runtime (0) | 2014.03.20 |
[Android] native 코드 확장하기 (BackButton) (0) | 2014.01.22 |
[Android] eclipse 빌드 오류 (0) | 2014.01.22 |