纳金网
标题:
Unity3D入门一:人物换装初探
[打印本页]
作者:
.
时间:
2013-1-16 17:08
标题:
Unity3D入门一:人物换装初探
今天先把我这几天关于人物换装的研究做个总结
参考资料
http://blog.csdn.net/libeifs/article/details/6751312
http://unity3d.com/support/resources/example-projects/charactercustomization模型我用得是官方Example里的模型
我这个Demo主要是基于SkinnedMeshRenderer,对其中元素做修改达到改变模型外形与装饰的效果。 Cloths.js◦//换贴图,直接把这段代码加在要换贴图的模型上即可;
◦private var eyeindex=0;
◦var eyestextures : Texture2D[];//贴图集合
◦private var type:int[];
◦private var index:int[];
◦var face1textures : Texture2D[];
◦var face2textures : Texture2D[];
◦var hair1textures : Texture2D[];
◦var hair2textures : Texture2D[];
◦var pants1textures : Texture2D[];
◦var pants2textures : Texture2D[];
◦var shoes1textures : Texture2D[];
◦var shoes2textures : Texture2D[];
◦var top1textures : Texture2D[];
◦var top2textures : Texture2D[];
◦
◦function Awake(){
◦ type=new int[5];
◦ index=new int[5];
◦}
◦
◦function Update ()
◦{
◦}
◦
◦//换装方法因模型而异
◦function changeCloth(name1 : String,name2 : String,texture1:Texture2D[] ,texture2:Texture2D[] ,idx,lens){
◦ if(index[idx]<lens-1){
◦ index[idx]++;
◦ }else {
◦ index[idx]=0;
◦ if(type[idx]==0){
◦ transform.Find(name1).GetComponent(SkinnedMeshRenderer).enabled=false;
◦ transform.Find(name2).GetComponent(SkinnedMeshRenderer).enabled=***e;
◦ type[idx]=1;
◦ }else{
◦ transform.Find(name2).GetComponent(SkinnedMeshRenderer).enabled=false;
◦ transform.Find(name1).GetComponent(SkinnedMeshRenderer).enabled=***e;
◦ type[idx]=0;
◦ }
◦ }
◦ if(type[idx]==0)
◦ transform.Find(name1).GetComponent(SkinnedMeshRenderer).material.mainTexture=texture1[index[idx]];
◦ else
◦ transform.Find(name2).GetComponent(SkinnedMeshRenderer).material.mainTexture=texture2[index[idx]];
◦}
◦
◦function OnGUI(){
◦ GUILayout.Label("");
◦ if(GUILayout.Button ("eye")) {
◦ if(eyeindex<2)
◦ eyeindex++;
◦ else
◦ eyeindex=0;
◦ transform.Find("eyes").GetComponent(SkinnedMeshRenderer).material.mainTexture=eyestextures[eyeindex];
◦ }else if(GUILayout.Button ("face")){
◦ changeCloth("face-1","face-2",face1textures,face2textures,0,1);
◦ }else if(GUILayout.Button ("hair")){
◦ changeCloth("hair-1","hair-2",hair1textures,hair2textures,1,3);
◦ }else if(GUILayout.Button ("pant")){
◦ changeCloth("pants-1","pants-2",pants1textures,pants2textures,2,3);
◦ }else if(GUILayout.Button ("shoes")){
◦ changeCloth("shoes-1","shoes-2",shoes1textures,shoes2textures,3,3);
◦ }else if(GUILayout.Button ("top")){
◦ changeCloth("top-1","top-2",top1textures,top2textures,4,3);
◦ }
◦}
这个是绑定在模型上的脚本,设置好XXXtextures参数,绑定相应的贴图
RoundCamera.js◦function Update () {
◦transform.RotateAround (Vector3.zero, Vector3.up, 100 * Time.deltaTime);
◦}
这个是绑定摄像机的,让它围绕人物转动,换装的时候能更加直观 Demo比较简单 就不细讲了,只是提供一个思路 换装方法有很多,因模型而异。 下面的工程下载链接http://download.csdn.net/detail/genius840215/4173638【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
欢迎光临 纳金网 (http://rs.narkii.com/club/)
Powered by Discuz! X2.5