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