Exemplo n.º 1
0
        public static void LoadByName(string name, ResourceLoader.EndLoadBundle endLoad, System.Object obj, bool assetBundle = false)
        {
            if (instance == null || instance.platformLoader == null)
            {
                return;
            }

            string destName;
            string path;
            int    size;
            bool   encrypt;

            Example.VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null)
            {
                Debugger.LogWarning("load name is not exist in version->" + name);
                if (endLoad != null)
                {
                    endLoad(null, obj);
                }
                return;
            }

            LoadByPath(name, destName, path, fileType, size, endLoad, obj, assetBundle);
        }
Exemplo n.º 2
0
        private void _AsynReadBytesByName(string name, EndReadBytes endRead, System.Object obj, bool cb_whatever = false)
        {
            if (name == null || name == "")
            {
                return;
            }
            string destName;
            string path;
            int    size;
            bool   encrypt;

            VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null)
            {
                if (cb_whatever)
                {
                    if (endRead != null)
                    {
                        endRead(null, obj);
                    }
                }
                return;
            }

            __AsynReadBytesByPath(name, destName, path, fileType, endRead, obj, cb_whatever, encrypt);
        }
Exemplo n.º 3
0
        private static string GenerateTempPath()
        {
            if (tempPath == null)
            {
                string path = ResUpdate.GetAssetPath();
                tempPath = path + "temp/";

                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }

                Directory.CreateDirectory(tempPath);
            }

            return(tempPath + System.Guid.NewGuid().ToString());
        }
Exemplo n.º 4
0
        private IResourceFileStream _LoadFileStreamByName(string name)
        {
            string destName;
            string path;
            int    size;
            bool   encrypt;

            VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);

            if (path == null)
            {
                return(null);
            }

            return(LoadFileStreamByPath(path));
        }
Exemplo n.º 5
0
        public static byte[] SyncDownloadBytes(string path, bool removeImpurity = true)
        {
            byte[] rawBytes = null;
            using (UnityWebRequest www = UnityWebRequest.Get(path))
            {
                www.Send();
                while (true)
                {
                    if (www.isNetworkError || www.isHttpError)
                    {
                        Debugger.LogError("failed to load path->" + path);
                        break;
                    }

                    if (www.isDone)
                    {
                        break;
                    }
                }

                try
                {
                    if (www.isDone && (!www.isNetworkError && !www.isHttpError))
                    {
                        rawBytes = www.downloadHandler.data;
                        if (removeImpurity)
                        {
                            _RemoveImpurity(rawBytes, null, false);
                        }

                        return(rawBytes);
                    }
                    else
                    {
                        Debug.LogError("sync read file error->" + www.error + "^" + ResUpdate.ConvertPathToName(path));
                    }
                }
                catch (Exception e)
                {
                    Debugger.LogError("syn read bytes failed->" + e.ToString());
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public static byte[] SyncReadBytesByName(string name)
        {
            if (instance == null || instance.platformLoader == null)
            {
                return(null);
            }
            string destName;
            string path;
            int    size;
            bool   encrypt;

            VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null)
            {
                return(null);
            }
            return(__SyncReadBytesByPath(name, destName, path, fileType, encrypt));
        }
Exemplo n.º 7
0
        private void _AsynReadUTF8ByName(string name, Action <string, System.Object> endRead, System.Object obj, bool cb_whatever = false)
        {
            if (name == null || name == "")
            {
                return;
            }
            string destName;
            string path;
            int    size;
            bool   encrypt;

            VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null)
            {
                if (cb_whatever)
                {
                    if (endRead != null)
                    {
                        endRead(null, obj);
                    }
                }
                return;
            }

            __AsynReadBytesByPath(name, destName, path, fileType, (bytes, @object) =>
            {
                if (bytes != null)
                {
                    string temp = System.Text.Encoding.UTF8.GetString(bytes);
                    if (endRead != null)
                    {
                        endRead(temp, @object);
                    }
                }
            }, obj, cb_whatever, encrypt);
        }
Exemplo n.º 8
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());
            }
        }
Exemplo n.º 9
0
        private IEnumerator CreateAssetBundle_Offset(string name, string path, ulong offset, Request request, EndLoadBundle endLoad, System.Object ud, bool assetBundle)//, bool cb_whatever)
        {
            if (Config.Detail_Debug_Log())
            {
                Debug.LogWarning("begin create asset ---------->" + name);
            }

            AssetBundleCreateRequest result = AssetBundle.LoadFromFileAsync(path, 0, offset);

            yield return(result);

            if (Config.Detail_Debug_Log())
            {
                Debug.LogWarning("end create asset ----------->" + name);
            }

            if (!result.isDone || result.assetBundle == null)
            {
                if (Config.Debug_Log())
                {
                    Debugger.LogError("Failed to create asset bundle: " + path + "^" + ResUpdate.ConvertPathToName(path));
                }
                cache.Remove(name);
                ProcessRequest(request, (System.Object)endLoad, ud);
                yield break;
            }
            if (!assetBundle)
            {
                request.asset = result.assetBundle.mainAsset;
                if (Config.Detail_Debug_Log())
                {
                    if (result.assetBundle.mainAsset != null)
                    {
                        Debug.LogWarning("create asset bundle type->" + result.assetBundle.mainAsset);
                    }
                }
            }
            else
            {
                request.asset = result.assetBundle;
            }

            if (request.asset == null)
            {
                UnityEngine.Object[] arr = result.assetBundle.LoadAllAssets();
                if (arr != null && arr.Length > 0)
                {
                    request.asset = arr[0];
                    if (arr.Length > 1)
                    {
                        for (int i = 1, count = arr.Length; i < count; i++)
                        {
                            Resources.UnloadAsset(arr[i]);
                        }
                    }
                }
            }

            if (request.asset == null)
            {
                if (Config.Debug_Log())
                {
                    Debugger.LogError("Failed to load asset:%s, asset is null", ResUpdate.ConvertPathToName(path));
                }
            }

            request.referenceNum++;
            ProcessRequest(request, (System.Object)endLoad, ud);

            if (!assetBundle)
            {
                CoroutineHelper.CreateCoroutineHelper(AsynUnloadAssetBundle(result.assetBundle));
            }
        }
Exemplo n.º 10
0
        private static void RequestAtlas(short index, System.Action callback, AtlasUnloadType unloadType, float param_f)
        {
            if (index < 0 || index >= atlasList.Count)
            {
                Debugger.LogError("request atlas is invalid->" + index);
                return;
            }

            AtlasData data = atlasList[index];

            if (data.atlas != null)
            {
                if (data.referenceNum < 0)
                {
                    data.referenceNum = 0;
                }
                data.referenceNum++;
                ProcessAtlasUnloadType(data, unloadType, param_f);
                if (callback != null)
                {
                    callback();
                }
                return;
            }
            if (index < 0)
            {
                return;
            }

            if (!atlasIndexToName.ContainsKey(index))
            {
                return;
            }

            string name = atlasIndexToName[index];

            string destName;
            string path;
            int    size;
            bool   encrypt;

            Example.VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null || path == "")
            {
                Debugger.LogError("ui atlas is null->" + name);
                return;
            }

            if (!loadCallDic.ContainsKey(index))
            {
                loadCallDic.Add(index, new List <System.Action>());
            }

            List <System.Action> list = loadCallDic[index];

            list.Add(callback);
            UnloadData ulData = unloadList[index];

            if (ulData.count >= 0)
            {
                ulData.count = -1;
            }
            if (list.Count == 1)
            {
                ResLoader.LoadByPath(name, destName, path, fileType, size, (asset, param) =>
                {
                    if (param == null)
                    {
                        return;
                    }

                    GameObject go = (GameObject)asset;
                    Object.DontDestroyOnLoad(go);
                    UIAtlas a = go.GetComponent <UIAtlas>();
                    if (a == null)
                    {
                        Debugger.LogError("ui atlas is invalid->" + name);
                    }
                    ProcessAtlas(a, index, unloadType, param_f);
                }, index);
            }
        }
Exemplo n.º 11
0
        private static void RequestTexture(short index, System.Action callback)
        {
            if (index < 0 || index >= textureList.Count)
            {
                Debugger.LogError("request texture is invalid->" + index);
                return;
            }


            TextureData data = textureList[index];

            if (data.texture != null)
            {
                if (data.referenceNum < 0)
                {
                    data.referenceNum = 0;
                }
                data.referenceNum++;
                if (callback != null)
                {
                    callback();
                }
                return;
            }

            if (index < 0)
            {
                return;
            }

            string name;

            if (!textureIndexToName.TryGetValue(index, out name))
            {
                return;
            }
            string destName;
            string path;
            int    size;
            bool   encrypt;

            Example.VersionFile.Type fileType;
            ResUpdate.GetLoadDetails(name, out destName, out path, out size, out encrypt, out fileType);
            if (path == null || path == "")
            {
                Debugger.LogError("ui texture is null->" + name);
                return;
            }

            if (!loadTextureCallDic.ContainsKey(index))
            {
                loadTextureCallDic.Add(index, new List <System.Action>());
            }

            List <System.Action> list = loadTextureCallDic[index];

            list.Add(callback);
            UnloadTexData ulData = unloadTexList[index];

            if (ulData.count >= 0)
            {
                ulData.count = -1;
            }
            if (list.Count == 1)
            {
                ResLoader.LoadByPath(name, destName, path, fileType, size, (asset, param) =>
                {
                    if (param == null)
                    {
                        return;
                    }

                    Texture tex = (Texture)asset;
                    ProcessTexture(tex, index);
                }, index);
            }
        }