Exemplo n.º 1
0
        /// <summary>
        /// 取bundle完整路径
        /// </summary>
        /// <param name="pi"></param>
        /// <returns></returns>
        string GetBundleFullPath(BundlePackInfo pi, bool withHeader)
        {
#if UNITY_EDITOR && !UNITY_EDITOR_OSX
            // 在PC上用Windows的Shader包,解决材质丢失问题
            if (pi.Path == "Shaders.ab")
            {
                if (withHeader)
                {
                    return(string.Format("file:///{0}/../../IFS/Build/Win/shaders.ab", Application.dataPath));
                }
                else
                {
                    return(string.Format("{0}/../../IFS/Build/Win/shaders.ab", Application.dataPath));
                }
            }
            else
#endif
            {
                if (pi.Outside)
                {
                    if (withHeader)
                    {
                        return(FileUtil.CombinePath(FileUtil.GetIFSExtractPathWithHeader(), pi.Path));
                    }
                    else
                    {
                        return(FileUtil.CombinePath(FileUtil.GetIFSExtractPath(), pi.Path));
                    }
                }
                else
                {
                    if (withHeader)
                    {
                        return(FileUtil.GetStreamingAssetsPathWithHeader(pi.Path));
                    }
                    else
                    {
                        return(FileUtil.CombinePath(Application.streamingAssetsPath, pi.Path));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 从IFS或StreamingAssets目录同步加载资源
        /// </summary>
        public void Load(string pkgPath, bool outside)
        {
            if (outside)
            {
                Load(FileUtil.GetIFSExtractPath(), pkgPath);
            }
            else
            {
                // load from StreamingAssets
#if UNITY_ANDROID && !UNITY_EDITOR
                string realPath = FileUtil.CombinePath(pkgPath, OriginPath);
                byte[] data     = NativeUtil.Android_ReadFileInAssets(realPath);
                if (data != null)
                {
                    OnBinaryLoaded(data);
                }
#else
                Load(FileUtil.GetStreamingAssetsPath(), pkgPath);
#endif
            }
        }
Exemplo n.º 3
0
        public bool ClearResCachePath()
        {
            string[] clearExtFiles = new string[] { ".json", ".res", ".bytes", ".txt" };
            string[] clearPaths    = new string[] { FileUtil.IFSExtractFolder };
            string   cachePath     = FileUtil.GetCachePath();

#if UNITY_EDITOR
            FileUtil.ClearDirectory(cachePath, clearExtFiles, clearPaths);
            return(true);
#else
            int tryCount = 0;
            while (true)
            {
                bool   isClearSuc   = FileUtil.ClearDirectory(cachePath, clearExtFiles, clearPaths);
                bool   isDirExsit   = true;
                string notClearFile = "";

                try
                {
                    if (isClearSuc)
                    {
                        string resCachePath = FileUtil.GetIFSExtractPath();
                        isDirExsit = FileUtil.IsDirectoryExist(resCachePath);
                        if (!isDirExsit)
                        {
                            bool     filesClear = true;
                            string[] files      = System.IO.Directory.GetFiles(cachePath);
                            for (int i = 0; i < files.Length; i++)
                            {
                                for (int j = 0; j < clearExtFiles.Length; j++)
                                {
                                    if (files[i].Contains(clearExtFiles[j]))
                                    {
                                        notClearFile = files[i];
                                        filesClear   = false;
                                        break;
                                    }
                                }

                                if (!filesClear)
                                {
                                    break;
                                }
                            }

                            if (filesClear)
                            {
                                return(true);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    JW.Common.Log.LogE("CleanCache Exception : {0}", ex.ToString());
                }

                ++tryCount;

                if (tryCount >= 3)
                {
                    JW.Common.Log.LogE("CleanCache Res Cache Failed isClearSuc : {0}, isDirExsit : {1}, notClearFile : {2}",
                                       isClearSuc, isDirExsit, notClearFile);
                    return(false);
                }
                else
                {
                    JW.Common.Log.LogE("CleanCache Res Cache Failed [Have Chance : {0}] isClearSuc : {1}, isDirExsit : {2}, notClearFile : {3}",
                                       tryCount, isClearSuc, isDirExsit, notClearFile);
                }
            }
#endif
        }