Beispiel #1
0
    /// <summary>
    ///   清理
    /// </summary>
    IEnumerator StartDispose()
    {
        UpdateCompleteValue(0f, 1f);

        if (ErrorCode != EmErrorCode.None)
        {
            //缓存已下载内容,便于下次继续下载
            SaveDownloadCacheData();
        }
        else
        {
            //删除缓存目录
            if (Directory.Exists(DownLoadCommon.CACHE_PATH))
            {
                Directory.Delete(DownLoadCommon.CACHE_PATH, true);
            }

            //重启AssetBundleManager
            ZTAssetBundleManager.GetInstance().Relaunch();
        }

        //ab包重新启动
        while (!ZTAssetBundleManager.GetInstance().WaitForLaunch())
        {
            yield return(null);
        }

        UpdateCompleteValue(1f, 1f);
        yield return(0);
    }
Beispiel #2
0
    /// <summary>
    ///   初始化更新器
    /// </summary>
    IEnumerator StartInitialize()
    {
        Debug.Log("AssetUpdater:StartInitialize");
        if (ErrorCode != EmErrorCode.None)
        {
            yield break;
        }

        UpdateCompleteValue(0f, 1f);

        //创建缓存目录
        if (!Directory.Exists(DownLoadCommon.CACHE_PATH))
        {
            Directory.CreateDirectory(DownLoadCommon.CACHE_PATH);
        }
        ZTAssetBundleManager.GetInstance().Relaunch();

        //ab包启动
        while (!ZTAssetBundleManager.GetInstance().WaitForLaunch())
        {
            UpdateCompleteValue(ZTAssetBundleManager.GetInstance().InitCurrent, ZTAssetBundleManager.GetInstance().InitTotal);
            yield return(null);
        }
        UpdateCompleteValue(1f, 1f);
        yield return(null);
    }
Beispiel #3
0
    /*
     * @brief 加载资源
     * @param path 资源路径
     * @param callback 回调函数
     */
    public static void LoadAsset(string path, UnityAction <Object, string> callback = null, System.Type type = null)
    {
        // Windows 平台分隔符为 '/', OS 平台 路径分隔符为 '\', 此处是一个大坑
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = path.Replace('\\', '/');
        }

#if UNITY_EDITOR
        ZTSceneManager.GetInstance().StartCoroutine(AnsyLoadAsset(path, callback, type));
#else
        string fileName   = System.IO.Path.GetFileName(path);
        string fileNameEx = System.IO.Path.GetFileNameWithoutExtension(path);
        string abName     = path.Replace(fileName, "").Replace('/', '_');
        abName = abName.Substring(0, abName.Length - 1).ToLower();

        ZTAssetBundleManager.GetInstance().LoadAssetInBundleSync(abName, fileNameEx, (Object gameObject) =>
        {
            //加载assetBundleManifest文件
            if (null != gameObject)
            {
                callback(gameObject, path);
                return;
            }
            callback(null, path);
        }, type);
#endif
    }
Beispiel #4
0
    /// <summary>
    ///   更新AssetBundle
    /// </summary>
    IEnumerator StartUpdateAssetBundle()
    {
        Debug.Log("AssetUpdater:StartUpdateAssetBundle");
        if (ErrorCode != EmErrorCode.None)
        {
            yield break;
        }

        UpdateCompleteValue(0f, 0f);

        ////载入MainManifest
        AssetBundleManifest manifest = ZTAssetBundleManager.GetInstance().MainManifest;
        //载入新的ResourcesManifest
        string file = DownLoadCommon.GetCacheFileFullName(DownLoadCommon.MAIN_MANIFEST_FILE_NAME);
        AssetBundleManifest new_manifest = DownLoadCommon.LoadMainManifestByPath(file);

        if (new_manifest == null)
        {
            Error(EmErrorCode.LoadNewMainManifestFailed
                  , "Can't find new version MainManifest!");
            yield break;
        }

        ////获取需下载的资源列表与删除的资源的列表
        List <string> download_files = new List <string>();
        List <string> delete_files   = new List <string>();

        CompareAssetBundleDifference(ref download_files, ref delete_files
                                     , manifest, new_manifest);

        //删除已废弃的文件
        if (delete_files.Count > 0)
        {
            for (int i = 0; i < delete_files.Count; ++i)
            {
                string full_name = DownLoadCommon.GetFileFullName(delete_files[i]);
                if (File.Exists(full_name))
                {
                    File.Delete(full_name);
                    yield return(0);
                }
            }
        }

        //更新所有需下载的资源
        _ab_download = new AssetBundleDownloader(_current_ab_url);
        _ab_download.Start(DownLoadCommon.PATH, download_files);
        while (!_ab_download.IsDone)
        {
            UpdateCompleteValue(_ab_download.CompletedSize, _ab_download.TotalSize);
            yield return(0);
        }
        if (_ab_download.IsFailed)
        {
            Error(EmErrorCode.DownloadAssetBundleFailed);
            yield break;
        }
    }
Beispiel #5
0
    /*
     * @brief 加载资源
     * @param path 资源路径
     * @param callback 回调函数
     */
    public static byte[] LoadLuaAsset(string path)
    {
        // Windows 平台分隔符为 '/', OS 平台 路径分隔符为 '\', 此处是一个大坑
        if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            path = path.Replace('\\', '/');
        }

#if UNITY_EDITOR
        Object obj = null;
        //lua ab包地址
        path = PathManager.LuaPath + "/" + path;
        //编辑器模式下 资源获取
        obj = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path);
        TextAsset text = (TextAsset)obj;
        if (null != text)
        {
            return(text.bytes);
        }
        return(null);
#else
        string filename = DownLoadCommon.GetLuaHotFullName(path);
        if (File.Exists(filename))
        {
            try
            {
                string res = File.ReadAllText(filename);
                return(System.Text.Encoding.UTF8.GetBytes(res));
            }catch (System.Exception e)
            {
                Debug.Log("LoadLuaAsset=====3>>" + e.ToString());
            }
        }

        Object        obj2       = null;
        string        fileNameEx = System.IO.Path.GetFileNameWithoutExtension(path);
        ZTAssetBundle bundle     = ZTAssetBundleManager.GetInstance().LoadAssetBundleAndDependencies("luascript");
        //加载assetBundleManifest文件
        if (null != bundle)
        {
            obj2 = bundle.GetAsset(fileNameEx);
        }
        TextAsset text2 = (TextAsset)obj2;
        if (null != text2)
        {
            return(text2.bytes);
        }

        return(null);
#endif
    }