1.  NGUIMath.cs 의 맨 하단에 아래의 코드를 추가 한다.

static public Bounds CalculateRelativeWidgetBounds2 ( Transform root, Transform firstTemplate, Transform lastTemplate )

{

if( firstTemplate == null || lastTemplate == null )

return new Bounds(Vector3.zero, Vector3.zero);

UIWidget[] widgets1 = firstTemplate.GetComponentsInChildren<UIWidget>(true) as UIWidget[];

UIWidget[] widgets2 = lastTemplate.GetComponentsInChildren<UIWidget>(true) as UIWidget[];

if (widgets1.Length == 0 || widgets2.Length == 0 ) return new Bounds(Vector3.zero, Vector3.zero);

 

Vector3 vMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

Vector3 vMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);

 

Matrix4x4 toLocal = root.worldToLocalMatrix;

 

for (int i = 0, imax = widgets1.Length; i < imax; ++i)

{

UIWidget w = widgets1[i];

Vector2 size = w.relativeSize;

Vector2 offset = w.pivotOffset;

Transform toWorld = w.cachedTransform;

 

float x = (offset.x + 0.5f) * size.x;

float y = (offset.y - 0.5f) * size.y;

size *= 0.5f;

// Start with the corner of the widget

Vector3 v = new Vector3(x - size.x, y - size.y, 0f);

// Transform the coordinate from relative-to-widget to world space

v = toWorld.TransformPoint(v);

// Now transform from world space to relative-to-parent space

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

// Repeat for the other 3 corners

v = new Vector3(x - size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y - size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

}

for (int i = 0, imax = widgets2.Length; i < imax; ++i)

{

UIWidget w = widgets2[i];

Vector2 size = w.relativeSize;

Vector2 offset = w.pivotOffset;

Transform toWorld = w.cachedTransform;

 

float x = (offset.x + 0.5f) * size.x;

float y = (offset.y - 0.5f) * size.y;

size *= 0.5f;

// Start with the corner of the widget

Vector3 v = new Vector3(x - size.x, y - size.y, 0f);

// Transform the coordinate from relative-to-widget to world space

v = toWorld.TransformPoint(v);

// Now transform from world space to relative-to-parent space

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

// Repeat for the other 3 corners

v = new Vector3(x - size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y - size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

 

v = new Vector3(x + size.x, y + size.y, 0f);

v = toWorld.TransformPoint(v);

v = toLocal.MultiplyPoint3x4(v);

 

vMax = Vector3.Max(v, vMax);

vMin = Vector3.Min(v, vMin);

}

 

Bounds b = new Bounds(vMin, Vector3.zero);

b.Encapsulate(vMax);

return b;

}


2. SpringPanel.cs 에 아래의 코드를 추가 한다.

static public SpringPanel Begin (GameObject go, Vector3 pos, float strength, OnFinished finish )

{

 SpringPanel sp = go.GetComponent<SpringPanel>();

 if (sp == null) sp = go.AddComponent<SpringPanel>();

 sp.target = pos;

 sp.strength = strength;

 sp.onFinished = finish;

 if (!sp.enabled)

 {

  sp.mThreshold = 0f;

  sp.enabled = true;

 }

 

 return sp;

}


3. 첨부한 3개의 파일을 프로젝트에 포함 시킨다.

cUIScrollListBase.cs


UIDraggablePanel2.cs


UIListItem.cs



4. UIDraggablePanel.cs 에서 에러가 날 것이다.. 

virtual 을 해서 없애도 되고~ 

UIDraggablePanel.cs


위 파일로 교체를 해도 된다.~~


5. 사용 방법은 

transform.GetComponent<UIDraggablePanel2>().Init( count, delegate(UIListItem item, int index) {

CMsgUserItem scr = item.Target.GetComponent<CMsgUserItem>();

scr.transform.name = "clip_"+index;

scr.transform.localScale = Vector3.one;

} );


6. 마지막 가장 중요한 감사의 마음을 표시 한다.~ 

나 말고~ http://idmanner.blog.me/70176641036  

위에 링크 블러그 주인한테 감사의 마음을 표시 한다.~~~


감사 합니다.~!~!~!

^^ 즐코딩 하세요~!

+ Recent posts