コード例 #1
0
        private AppearancePart CreatPart(SkinnedMeshRenderer meshRenderer)
        {
            AppearancePart part = new AppearancePart(meshRenderer.name);

            //获取材质球
            part.Materials.AddRange(meshRenderer.materials);
            //获取mesh
            for (int sub = 0; sub < meshRenderer.sharedMesh.subMeshCount; sub++)
            {
                CombineInstance instance = new CombineInstance();
                instance.mesh         = meshRenderer.sharedMesh;
                instance.subMeshIndex = sub;
                part.CombineInstances.Add(instance);
            }

            //获取骨架
            for (int j = 0; j < meshRenderer.bones.Length; j++)
            {
                for (int k = 0; k < skeletonTransforms.Length; k++)
                {
                    if (skeletonTransforms[k].name.Equals(meshRenderer.bones[j].name))
                    {
                        part.Bones.Add(skeletonTransforms[k]);
                        break;
                    }
                }
            }
            GameObject root = meshRenderer.transform.root.gameObject;

            if (root != skeleton)
            {
                GameObject.Destroy(meshRenderer.transform.root.gameObject);
            }
            return(part);
        }
コード例 #2
0
        private void AddRendererData(SkinnedMeshRenderer newMeshRenderer)
        {
            if (appearanceParts.ContainsKey(newMeshRenderer.name))
            {
                Debug.LogWarningFormat("Appearance part **{0}** has exited!", newMeshRenderer.name);
                return;
            }
            AppearancePart part = CreatPart(newMeshRenderer);

            appearanceParts.Add(part.Name, part);
        }
コード例 #3
0
        private Dictionary <string, AppearancePart> GetParts(List <SkinnedMeshRenderer> renderers)
        {
            Dictionary <string, AppearancePart> parts = new Dictionary <string, AppearancePart>();

            for (int i = 0; i < renderers.Count; i++)
            {
                SkinnedMeshRenderer smr  = renderers[i];
                AppearancePart      part = CreatPart(smr);
                parts.Add(part.Name, part);
            }
            return(parts);
        }