Ejemplo n.º 1
0
        private static void OnLoad(UnityEngine.Object asset, System.Object obj)
        {
            TempLoad tl = (TempLoad)obj;

            try
            {
                Texture2D tex = (Texture2D)asset;

                TexInfo texInfo = new TexInfo();
                texInfo.tex          = tex;
                texInfo.w            = (short)tex.width;
                texInfo.h            = (short)tex.height;
                tl.texInfo[tl.index] = texInfo;

                bool    over = true;
                int     i, count;
                TexInfo ti;
                for (i = 0, count = tl.texInfo.Length; i < count; i++)
                {
                    ti = tl.texInfo[i];
                    if (ti == null)
                    {
                        over = false;
                        break;
                    }
                }
                tl.over = over;

                if (over)
                {
                    if (tl.autoTemp)
                    {
                        PackCombineTexture(tl);
                    }
                    else
                    {
                        Texture2D texture = new Texture2D(1, 1);

                        Rect[] rect = CreateTex(texture, tl.texInfo);

                        ProcessCombine(tl, texture, rect);
                    }
                }
            }
            catch (System.Exception e)
            {
                for (int i = 0; i < tl.meshList.Count; i++)
                {
                    Object.Destroy(tl.meshList[i]);
                }
                if (tl.endCombine != null)
                {
                    tl.endCombine(null, tl.plus, tl.sub, tl.endParam);
                }

                Debug.LogError("combine load e->" + asset.name + "^" + e.ToString());
            }
        }
Ejemplo n.º 2
0
    public void LoadDataFile(string FileName)
    {
        try
        {
            //首先检查用户数据目录里是否有该文件//
            //string file_name = CUtility.GetFullFilePath(FileName);
            string file_name = TempLoad.GetResFullPath(FileName);
            int    item_size = 0;
            buffer = File.ReadAllBytes(file_name);
            int data_start = 0;
            if (buffer.Length > 38 && buffer[0] == 'M' && buffer[1] == 'p' && buffer[2] == 'd' && buffer[3] == '\n')
            {
                //取md5码
                int index = 4;
                while (buffer[index] != '\n' && index < 38) //MD5一般32位
                {
                    index++;
                }
                string md5 = System.Text.Encoding.Default.GetString(buffer, 4, index - 4);
                if (md5 != GetProtoMd5())
                {
                    Debug.LogError(string.Format("Load file({0}) failed, data md5 {1} != {2} (code md5), protobuf struct dismatch.", FileName, md5, GetProtoMd5()));
                }

                //取svn版本号
                data_start = index + 1;
                while (buffer.Length > data_start && buffer[data_start] != '\n' && data_start < 50)
                {
                    data_start++;
                }
                //Log.Debug("svn ver:{0}", System.Text.Encoding.Default.GetString(buffer, index+1, data_start - index - 1));

                data_start++;//跳过 \n 后面才是数据正文
                byte[] tbuf = buffer;
                buffer = new byte[tbuf.Length - data_start];
                Buffer.BlockCopy(tbuf, data_start, buffer, 0, tbuf.Length - data_start);
            }

            NetMsg       message  = new NetMsg(0, buffer);
            TDataArray   datas    = message.GetBody <TDataArray>();
            List <TData> dataList = GetDataList(datas);
            int          count    = dataList.Count;

            data = new Dictionary <uint, TData>(count);
            for (int i = 0; i < count; ++i)
            {
                try
                {
                    data.Add(GetKey(dataList[i]), dataList[i]);
                }
                catch (System.Exception e)
                {
                    Debug.LogError(string.Format("Load file({0}) data add key{1} failed, error({2})", FileName, GetKey(dataList[i]), e.ToString()));
                }
            }

            buffer = null;
        }
        catch (System.Exception e)
        {
            Debug.LogError(string.Format("Load file({0}) failed, error({1})", FileName, e.ToString()));
        }
    }
Ejemplo n.º 3
0
 private static void PackCombineTexture(TempLoad tl)
 {
 }
Ejemplo n.º 4
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());
            }
        }
Ejemplo n.º 5
0
        private static void ProcessCombine(TempLoad tl, Texture2D texture, Rect[] rect)
        {
            lock (lockCombine)
            {
                int       i, count, j = 0, k = 0, count1;
                Rect      rt;
                TexInfo   ti;
                Mesh      mesh;
                Vector2[] uvs;

                for (i = 0, count = tl.meshList.Count; i < count; i++)
                {
                    rt   = rect[i];
                    ti   = tl.texInfo[i];
                    mesh = tl.meshList[i];

                    uvs    = mesh.uv;
                    count1 = uvs.Length;
                }

                try
                {
                    texture.Compress(false);
                    if (rect == null)
                    {
                        Debug.LogError("rect is null");
                        return;
                    }

                    Vector2 v2;
                    Vector2 nuv;

                    for (i = 0, count = tl.meshList.Count; i < count; i++)
                    {
                        rt   = rect[i];
                        ti   = tl.texInfo[i];
                        mesh = tl.meshList[i];

                        uvs = mesh.uv;

                        count1 = uvs.Length;
                        for (j = 0; j < count1; j++)
                        {
                            v2     = uvs[j];
                            nuv    = new Vector2(rt.xMin + v2.x * ti.w / texture.width, rt.yMin + v2.y * ti.h / texture.height);
                            uvs[j] = nuv;
                        }
                        mesh.uv = uvs;
                    }

                    SkinnedMeshRenderer r = tl.root.GetComponent <SkinnedMeshRenderer>();
                    r.sharedMesh = new Mesh();
                    r.sharedMesh.CombineMeshes(tl.combineInstances.ToArray(), true, false);
                    r.bones = tl.bones.ToArray();

                    Material material = new Material("xx");
                    material.mainTexture = texture;

                    r.materials = new Material[] { material };

                    CombineObj co = new CombineObj();
                    co.obj     = tl.root;
                    co.combine = true;
                    if (!combinedDic2.ContainsKey(tl.plus))
                    {
                        Dictionary <int, List <CombineObj> > dic = new Dictionary <int, List <CombineObj> >();
                        List <CombineObj> list = new List <CombineObj>();
                        list.Add(co);
                        dic.Add(tl.sub, list);
                        combinedDic2.Add(tl.plus, dic);
                    }
                    else
                    {
                        Dictionary <int, List <CombineObj> > dic = combinedDic2[tl.plus];
                        if (dic.ContainsKey(tl.sub))
                        {
                            dic[tl.sub].Add(co);
                        }
                        else
                        {
                            List <CombineObj> list = new List <CombineObj>();
                            list.Add(co);
                            dic.Add(tl.sub, list);
                        }
                    }

                    //add first, then avoid to del
                    if (tl.endCombine != null)
                    {
                        tl.endCombine(tl.root, tl.plus, tl.sub, tl.endParam);
                    }

                    //Mesh mesh;
                    for (i = 0, count = tl.meshList.Count; i < count; i++)
                    {
                        Object.Destroy(tl.meshList[i]);
                    }

                    for (i = 0, count = tl.texName.Length; i < count; i++)
                    {
                        ResLoader.RemoveAssetCacheByName(tl.texName[i]);
                    }
                }
                catch (System.Exception e)
                {
                    for (i = 0, count = tl.meshList.Count; i < count; i++)
                    {
                        Object.Destroy(tl.meshList[i]);
                    }

                    for (i = 0, count = tl.texName.Length; i < count; i++)
                    {
                        ResLoader.RemoveAssetCacheByName(tl.texName[i]);
                    }

                    if (tl.endCombine != null)
                    {
                        tl.endCombine(null, tl.plus, tl.sub, tl.endParam);
                    }

                    Debug.LogError("process combine error->" + e.ToString());
                }
            }
        }