示例#1
0
        public static void CreateAvatarPrefab(GameObject pfb_go, string dir, string middir)
        {
            string pfb_dir_asset_path = EAvatarConst.PREFAB_ASSET_PATH + "/" + middir + "/";
            string material_dir_path  = EAvatarConst.MAT_ASSET_PATH + middir + "/";

            EDirectoryHelper.CreateDirectory(pfb_dir_asset_path);
            // 实例化并且格式化
            GameObject go = Object.Instantiate <GameObject>(pfb_go);

            // 创建子部件
            List <Material> materials = EDirectoryHelper.CollectAll <Material>(material_dir_path);

            SkinnedMeshRenderer[] skinneds = go.GetComponentsInChildren <SkinnedMeshRenderer>(true);



            /* Dictionary<string, SkinnedMeshRenderer> skinned_map = new Dictionary<string, SkinnedMeshRenderer>();
             * for (int i = 0; i < skinneds.Length; i++)
             *   skinned_map.Add(skinneds[i].gameObject.name, skinneds[i]);*/
            /*for (int i = 0; i < materials.Count; i++)
             * {
             *  Material mat = materials[i];
             *
             *  for (int j = 0; j < skinneds.Length; j++)
             *  {
             *      if (mat == null) continue;
             *      if (!mat.name.Contains(obj.name))continue;
             *  }
             *
             * }*/
            foreach (SkinnedMeshRenderer smr in skinneds)
            {
                GameObject new_part_go = Object.Instantiate <GameObject>(smr.gameObject);

                Material mat = FindMaterialByName(materials, smr.gameObject.name);
                TransformHelper.Normalizle(new_part_go);

                SkinnedMeshRenderer newrenderer = new_part_go.GetComponentInChildren <SkinnedMeshRenderer>();
                newrenderer.material = mat;


                EPrefabHelper.CreatePrefab(pfb_dir_asset_path + "/" + new_part_go.name.ToLower() + EAvatarConst.PREAFAB_SUFFIX, new_part_go);
            }
        }
示例#2
0
        public static void CreateSkeletonPrefab(GameObject pfb_go, string dir, string middir)
        {
            string pfb_dir_asset_path = EAvatarConst.PREFAB_ASSET_PATH + "/" + middir + "/";

            EDirectoryHelper.CreateDirectory(pfb_dir_asset_path);
            // 实例化并且格式化
            GameObject go = Object.Instantiate <GameObject>(pfb_go);

            go.name = middir + EAvatarConst.SKELETON_SUFFIX;
            TransformHelper.Normalizle(go);

            // 剔除SkinnedMeshRenderer
            foreach (SkinnedMeshRenderer smr in go.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                Object.DestroyImmediate(smr.gameObject);
            }

            // 创建Prefab
            EPrefabHelper.CreatePrefab(pfb_dir_asset_path + "/" + go.name.ToLower() + EAvatarConst.PREAFAB_SUFFIX, go);
        }