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  

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


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

^^ 즐코딩 하세요~!



ngui 사용시 위와 같은 이미지 자른 후에 1~2픽셀의 공간이 생기는 현상이 있습니다. 

흔히 모든 해상도에 대응을 하게 되면 생기는 현상 같기도 하구요..


이 문제점을 해결 하는 방법은 ngui 의 Atlas 텍스쳐의 Filter Mode를 Point로 변경 하면 해결 됩니다. ㅜㅜ


너무 힘들었네요 이 부분 찾느라 ~ 


그럼 즐 코딩 하세요~

Unity3D를 하면서 2D게임을 만들려고 하면 거의 NGUI를 사용 하게 된다. 사용을 안하더라도 들어는 봤을 것이다. 


이 NGUI에서 ScrollView 또한 지원 해준다 ..


Atlas 에서 UISprite 와 UILabel UIButton을 Panel에 add 하면 정상적으로 작동은 한다 .그런데 


외부 이미지를 가져 와서 빈 cube 오브젝트를 생성 한후 add 하면 clipping 이 정상적으로 되지 않는 것을 알수 있다. 


그래서 보통 이미지를 곧바로 


동적 으로 Texture를 해줄때..


 string nameShader = "Unlit/Transparent";

Texture bumpMap = Resources.LoadAssetAtPath("Assets/Resources/pet_1.png",typeof(Texture)) as Texture;

MeshRenderer render  = clip.FindChild("mcThumb").gameObject.GetComponent<MeshRenderer>();

render.material.shader = Shader.Find (nameShader);

// npcMaterial.SetTexture("pet_1.png",bumpMap);

clip.FindChild("mcThumb").gameObject.renderer.material.SetTexture("_MainTex",bumpMap);

clip.FindChild("mcThumb").transform.localScale = new Vector3(bumpMap.width,bumpMap.height,0);


보통 이렇게 texture를 씌워 준다 다른 방법이 있으면 가르쳐 주세요 ㅜㅜ

근데 이런씩으로 texture를 하여 add 하면 clipping이 작동 하지 않아서 새로운 방법을 찾게 된다. 


찾다 보니 NGUI도 UITexture class가 있어서 이 class를 사용 하면 된다. ~


Texture bumpMap = Resources.LoadAssetAtPath("Assets/Resources/pet_1.png",typeof(Texture)) as Texture;

UITexture ut = NGUITools.AddWidget<UITexture>(clip.FindChild("mcThumb").gameObject);

ut.material = new Material(Shader.Find("Unlit/Transparent Colored"));

ut.material.mainTexture = bumpMap;

Transform temp = clip.FindChild("mcThumb").FindChild("Texture").transform;

// temp.localRotation = new Quaternion(0,0,180,0);

temp.localPosition = new Vector3(0,10,-5.5f);

temp.localScale = new Vector3(bumpMap.width,bumpMap.height,0);

ut.MakePixelPerfect();


흠.... 상당히 이미지 한장 부여 하는 데도 많이 들어 간다 ~!~!~!~!~!

위 방식으로 적용 하면... 잘된다. 


그런데 여기서 


 "Unlit/Transparent";

"Unlit/Transparent Colored"

의 차이점을 아시는분 ~~~~ ?.?

댓글 부탁드립니다.~






+ Recent posts