资源简介
Unity Avatar角色换装实例,在同时也附带了一篇博客blog.liujunliang.com.cn
代码片段和文件信息
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//mesh-materials\bones\
[RequireComponent (typeof(SkinnedMeshRenderer))]
public class AvatarGenerater : MonoBehaviour {
public Listject> EyeList = new Listject>();
public Listject> FaceList = new Listject>();
public Listject> HairList = new Listject>();
public Listject> PantsList = new Listject>();
public Listject> ShoesList = new Listject>();
public Listject> TopList = new Listject>();
private Mesh mesh;
private List materialList = new List();
private List boneList = new List();
private List ciList = new List();
private SkinnedMeshRenderer smr;
private Transform[] selfBones;
// Use this for initialization
void Start () {
smr = GetComponent();
Random.seed = (int)Time.time;
selfBones = GetComponentsInChildren();
Generate();
}
void Reset()
{
ciList.Clear();
materialList.Clear ();
boneList.Clear ();
}
void Generate()
{
Reset ();
RandomSelect(EyeList);
RandomSelect(FaceList);
RandomSelect(HairList);
RandomSelect(PantsList);
RandomSelect(ShoesList);
RandomSelect(TopList);
mesh = new Mesh();
mesh.CombineMeshes(ciList.ToArray() false false);
smr.sharedMesh = mesh;
smr.materials = materialList.ToArray();
smr.bones = boneList.ToArray();
}
void RandomSelect(Listject> target)
{
if(target.Count > 0)
{
Gameobject go = target[Random.Range (0 target.Count)];
SkinnedMeshRenderer goSMR = go.GetComponent();
if(goSMR)
{
CombineInstance ci = new CombineInstance();
ci.mesh = goSMR.sharedMesh;
ciList.Add(ci);
materialList.AddRange (goSMR.materials);
MatchBones(goSMR.bones);
}
}
}
void MatchBones(Transform[] bones)
{
foreach(Transform t in bones)
{
foreach(Transform s in selfBones)
{
if(s.name.Equals(t.name))
{
boneList.Add (s);
break;
}
}
}
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown (KeyCode.Space))
{
Generate ();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2230 2016-07-12 21:14 Assets\Mat\AvatarGenerater.cs
..A..H. 263 2016-07-05 19:10 Assets\Mat\AvatarGenerater.cs.me
文件 38408 2016-07-12 21:09 Assets\Mat\example.unity
..A..H. 175 2016-07-05 19:37 Assets\Mat\example.unity.me
文件 1675280 2015-03-07 15:00 Assets\Mat\Female\Female.FBX
..A..H. 6780 2016-07-05 19:06 Assets\Mat\Female\Female.FBX.me
文件 1597808 2015-03-07 15:01 Assets\Mat\Female\Female@idle1.FBX
..A..H. 16990 2016-07-12 21:01 Assets\Mat\Female\Female@idle1.FBX.me
文件 1706848 2015-03-07 15:01 Assets\Mat\Female\Female@item_boots.fbx
..A..H. 5817 2016-07-05 14:48 Assets\Mat\Female\Female@item_boots.fbx.me
文件 1619504 2015-03-07 14:57 Assets\Mat\Female\Female@item_pants.fbx
..A..H. 5817 2016-07-05 14:48 Assets\Mat\Female\Female@item_pants.fbx.me
文件 1600992 2015-03-07 14:59 Assets\Mat\Female\Female@item_shirt.fbx
..A..H. 5817 2016-07-05 14:48 Assets\Mat\Female\Female@item_shirt.fbx.me
文件 1848256 2015-03-07 15:00 Assets\Mat\Female\Female@walk.fbx
..A..H. 5748 2016-07-05 14:48 Assets\Mat\Female\Female@walk.fbx.me
文件 1646800 2015-03-07 15:01 Assets\Mat\Female\Female@walkin.fbx
..A..H. 5746 2016-07-05 14:48 Assets\Mat\Female\Female@walkin.fbx.me
文件 4896 2016-07-05 19:06 Assets\Mat\Female\Materials\female_eyes.mat
..A..H. 180 2016-07-05 19:06 Assets\Mat\Female\Materials\female_eyes.mat.me
文件 4900 2016-07-05 11:58 Assets\Mat\Female\Materials\female_eyes_blue.mat
..A..H. 180 2016-07-05 14:48 Assets\Mat\Female\Materials\female_eyes_blue.mat.me
文件 4980 2016-07-12 21:08 Assets\Mat\Female\Materials\female_face-1.mat
..A..H. 180 2016-07-05 14:48 Assets\Mat\Female\Materials\female_face-1.mat.me
文件 4980 2016-07-12 21:08 Assets\Mat\Female\Materials\female_face-2.mat
..A..H. 180 2016-07-05 14:48 Assets\Mat\Female\Materials\female_face-2.mat.me
文件 4980 2016-07-12 21:08 Assets\Mat\Female\Materials\female_hair-1.mat
..A..H. 180 2016-07-05 19:06 Assets\Mat\Female\Materials\female_hair-1.mat.me
文件 4904 2016-07-05 11:58 Assets\Mat\Female\Materials\female_hair-1_red.mat
..A..H. 180 2016-07-05 14:48 Assets\Mat\Female\Materials\female_hair-1_red.mat.me
............此处省略794个文件信息
- 上一篇:免费微信投票管理系统源码
- 下一篇:图解算法pdf中文高清版
评论
共有 条评论