Exemple #1
0
        private static void _Combine(CombineInfo combineInfo)
        {
            List <Mesh> meshList = new List <Mesh>();

            try
            {
                CharacterAsset         item = null;
                int                    i, j, k, count, count1, count2;
                List <CombineInstance> combineInstances = new List <CombineInstance>();
                List <Transform>       bones            = new List <Transform>();
                Transform[]            transforms       = combineInfo.root.GetComponentsInChildren <Transform>();


                TexInfo[]           texInfo = new TexInfo[combineInfo.items.Count];
                SkinnedMeshRenderer smr     = null;
                CombineInstance     ci;
                string[]            strs = null;
                string    str            = null;
                Transform transform;
                count2 = transforms.Length;
                count  = (short)combineInfo.items.Count;
                for (i = 0; i < count; i++)
                {
                    item = combineInfo.items[i];
                    smr  = item.GetSkinnedMeshRenderer();
                    if (smr == null)
                    {
                        return;
                    }
                    Mesh mesh = Mesh.Instantiate(smr.sharedMesh) as Mesh;
                    for (j = 0, count1 = smr.sharedMesh.subMeshCount; j < count1; j++)
                    {
                        ci              = new CombineInstance();
                        ci.mesh         = mesh;
                        ci.subMeshIndex = j;
                        combineInstances.Add(ci);
                    }

                    strs = item.GetBoneNames();
                    for (j = 0, count1 = strs.Length; j < count1; j++)
                    {
                        str = strs[j];
                        for (k = 0; k < count2; k++)
                        {
                            transform = transforms[k];
                            if (transform.name != str)
                            {
                                continue;
                            }
                            bones.Add(transform);
                            break;
                        }
                    }

                    meshList.Add(mesh);

                    Object.Destroy(smr.gameObject);
                }

                TempLoad tl     = null;
                string[] strArr = new string[count];

                string destName;
                string path;
                int    size;
                bool   encrypt;
                Example.VersionFile.Type fileType;
                for (i = 0; i < count; i++)
                {
                    item                = combineInfo.items[i];
                    strs                = item.GetTexNames();
                    tl                  = new TempLoad();
                    tl.texInfo          = texInfo;
                    tl.index            = (short)i;
                    tl.combineInstances = combineInstances;
                    tl.bones            = bones;
                    tl.meshList         = meshList;
                    tl.endCombine       = combineInfo.endCombine;
                    tl.endParam         = combineInfo.endParam;
                    tl.root             = combineInfo.root;
                    tl.over             = false;
                    tl.plus             = combineInfo.plus;
                    tl.sub              = combineInfo.sub;
                    tl.autoTemp         = combineInfo.autoTemp;
                    tl.texName          = strArr;
                    tl.light            = combineInfo.light;

                    GameUtils.stringBuilder.Remove(0, GameUtils.stringBuilder.Length);
                    GameUtils.stringBuilder.Append(strs[0]);

                    ResUpdate.GetLoadDetails(GameUtils.stringBuilder.ToString(), out destName, out path, out size, out encrypt, out fileType);
                    strArr[i] = GameUtils.stringBuilder.ToString();
                    ResLoader.LoadByPath(strArr[i], destName, path, fileType, size, OnLoad, tl, combineInfo.autoTemp);
                }
            }
            catch (System.Exception e)
            {
                for (int i = 0; i < meshList.Count; i++)
                {
                    Object.Destroy(meshList[i]);
                }
                if (combineInfo != null && combineInfo.endCombine != null)
                {
                    combineInfo.endCombine(null, -1, -1, combineInfo.endParam);
                }
                Debug.LogError("combine error->" + e.ToString());
            }
        }
        private static void _Combine_NPT(CombineInfo combineInfo)
        {
            List <Mesh> meshList = new List <Mesh>();

            try
            {
                CharacterAsset         item = null;
                int                    i, j, k, count, count1, count2;
                List <CombineInstance> combineInstances = new List <CombineInstance>();
                List <Transform>       bones            = new List <Transform>();
                List <Material>        materials        = new List <Material>();
                Transform[]            transforms       = combineInfo.root.GetComponentsInChildren <Transform>();

                SkinnedMeshRenderer smr = null;
                CombineInstance     ci;
                string[]            strs = null;
                string    str            = null;
                Transform transform;
                count2 = transforms.Length;
                count  = combineInfo.items.Count;
                for (i = 0; i < count; i++)
                {
                    item = combineInfo.items[i];
                    smr  = item.GetSkinnedMeshRenderer();
                    if (smr == null)
                    {
                        return;
                    }

                    materials.AddRange(smr.materials);

                    Mesh mesh = Mesh.Instantiate(smr.sharedMesh) as Mesh;
                    for (j = 0, count1 = smr.sharedMesh.subMeshCount; j < count1; j++)
                    {
                        ci              = new CombineInstance();
                        ci.mesh         = mesh;
                        ci.subMeshIndex = j;
                        combineInstances.Add(ci);
                    }

                    strs = item.GetBoneNames();
                    for (j = 0, count1 = strs.Length; j < count1; j++)
                    {
                        str = strs[j];
                        for (k = 0; k < count2; k++)
                        {
                            transform = transforms[k];
                            if (transform.name != str)
                            {
                                continue;
                            }
                            bones.Add(transform);
                            break;
                        }
                    }

                    meshList.Add(mesh);

                    Object.Destroy(smr.gameObject);
                }

                TempLoad_NPT tl = new TempLoad_NPT();
                tl.combineInstances = combineInstances;
                tl.bones            = bones;
                tl.meshList         = meshList;
                tl.materials        = materials;
                tl.endCombine       = combineInfo.endCombine;
                tl.endParam         = combineInfo.endParam;
                tl.root             = combineInfo.root;
                tl.plus             = combineInfo.plus;
                tl.sub   = combineInfo.sub;
                tl.light = combineInfo.light;

                ProcessCombine(tl);
            }
            catch (System.Exception e)
            {
                if (combineInfo != null && combineInfo.endCombine != null)
                {
                    combineInfo.endCombine(null, -1, -1, combineInfo.endParam);
                }
                Debug.LogError("combine error->" + e.ToString() + "\r\n" + e.StackTrace);
            }
        }