Пример #1
0
    // Use this for initialization
    private IEnumerator StartAssetBundleUpdate()
    {
        mUpdating = true;
        if (ABGlobal.abCheck)
        {
            ABUtil.Log("start modify ab check");
            yield return(StartCoroutine(mABChekcer.StartCheck()));
        }

        if (mABChekcer.ModifyABs != null && mABChekcer.ModifyABs.Count > 0)
        {
            ABUtil.Log("start download modify abs");
            yield return(StartCoroutine(mABDownloader.DownloadAndCacheABList(mABChekcer.ModifyABs)));

            ABUtil.Log("finish download modify abs");
            if (mABDownloader.Err == ABDownLoadError.ERR_None)
            {
                mABChekcer.UpdateClientJsonFile();
            }
            else
            {
                ABUtil.Log("update modify ab failed");
            }
        }
        else
        {
            ABUtil.Log("Load local Asset bundles");
            yield return(StartCoroutine(LoadLocalAssetBundle()));

            ABUtil.Log("Load local Asset bundles finished");
        }
        yield return(new WaitForSeconds(1f));

        mUpdating = false;
    }
Пример #2
0
    /// <summary>
    /// 生成文件
    /// </summary>
    /// <param name="abManif"></param>
    private static void GenFile(AssetBundleManifest abManif)
    {
        string filePath = ABSettings.AssetBundleCompareFilePath();

        FileStream   fs            = new FileStream(filePath, FileMode.Create);
        StreamWriter mStreamWriter = new StreamWriter(fs, System.Text.Encoding.UTF8);

        ABHashCollection abHashCollection = new ABHashCollection();
        ABHashInfo       abHashInfo       = null;

        string[] abs = abManif.GetAllAssetBundles();
        for (int i = 0; i < abs.Length; i++)
        {
            abHashInfo      = new ABHashInfo();
            abHashInfo.ab   = abs[i];
            abHashInfo.hash = abManif.GetAssetBundleHash(abs[i]).ToString();
            abHashCollection.abHashList.Add(abHashInfo);
        }

        string jsonStr = JsonUtility.ToJson(abHashCollection);

        ABUtil.Log("Gen Json Success: " + jsonStr);
        mStreamWriter.Write(jsonStr);

        mStreamWriter.Close();
        fs.Close();
    }
Пример #3
0
    public List <string> CalModifyAB(ABHashCollection serverABHashCollection)
    {
        List <string> modifyABList = new List <string>();
        Dictionary <string, ABHashInfo> clientABHashDict = new Dictionary <string, ABHashInfo>();

        for (int i = 0; i < abHashList.Count; i++)
        {
            clientABHashDict.Add(abHashList[i].ab, abHashList[i]);
        }

        ABHashInfo tempS, tempC;

        for (int i = 0; i < serverABHashCollection.abHashList.Count; i++)
        {
            tempC = null;
            tempS = serverABHashCollection.abHashList[i];

            clientABHashDict.TryGetValue(tempS.ab, out tempC);
            if (tempC == null || !tempS.hash.Equals(tempC.hash))
            {
                modifyABList.Add(tempS.ab);
                ABUtil.Log(string.Format("modify ab: {0}", tempS.ab));
            }
        }
        return(modifyABList);
    }
Пример #4
0
    /// <summary>
    /// 读取Json对比文件
    /// </summary>
    public ABHashCollection ReadABCompareFile()
    {
        ABHashCollection abHashCollection = new ABHashCollection();
        string           filePath         = ClientCompareFilePath();

        if (!File.Exists(filePath))
        {
            return(abHashCollection);
        }

        try
        {
            FileStream   fs           = new FileStream(filePath, FileMode.Open);
            StreamReader streamReader = new StreamReader(fs);

            string jsonStr = streamReader.ReadToEnd();
            abHashCollection = JsonUtility.FromJson <ABHashCollection>(jsonStr);

            streamReader.Close();
            fs.Close();
        }
        catch (Exception e)
        {
            ABUtil.Log(e.Message);
        }
        return(abHashCollection);
    }
Пример #5
0
    /// <summary>
    /// 获取AB Name
    /// </summary>
    public static void GetNames()
    {
        var names = AssetDatabase.GetAllAssetBundleNames();

        foreach (var name in names)
        {
            ABUtil.Log("AssetBundle: " + name);
        }
    }
Пример #6
0
 /// <summary>
 /// 删除AssetBundle
 /// </summary>
 public static void RemoveAssetBundle()
 {
     try
     {
         Directory.Delete(ABSettings.AssetBundleFetchPath(), true);
         Directory.CreateDirectory(ABSettings.AssetBundleFetchPath());
     }
     catch (Exception e) {
         ABUtil.Log(e.Message);
     }
     ABUtil.Log("remove asset bundle success");
 }
Пример #7
0
    /// <summary>
    /// 删除对比文件
    /// </summary>
    public static void RemoveLocalCompareFile()
    {
        string filePath = ABSettings.LocalCompareFilePath();

        try
        {
            File.Delete(filePath);
            ABUtil.Log("Delete AB Compare File Success");
        }
        catch (Exception e) {
            ABUtil.Log(e.Message);
        }
    }
Пример #8
0
    /// <summary>
    /// 生成Json对比文件
    /// </summary>
    public static void GenABCompareFile()
    {
        string assetBundlePath = ABSettings.FolderAssetBundleFetchPath();

        AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath);

        if (assetBundle == null)
        {
            ABUtil.Log("Failed to load AssetBundle!");
            return;
        }

        AssetBundleManifest abManif = assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;

        GenFile(abManif);
        assetBundle.Unload(false);
    }
Пример #9
0
    /// <summary>
    /// 将服务器的Json更新到客户端
    /// </summary>
    /// <param name="text"></param>
    public void UpdateClientJsonFile()
    {
        string jsonStr = JsonUtility.ToJson(mServerHashCollection);

        try {
            string       filePath     = ClientCompareFilePath();
            FileStream   fs           = new FileStream(filePath, FileMode.Create);
            StreamWriter streamWriter = new StreamWriter(fs);
            streamWriter.Write(jsonStr);
            streamWriter.Close();
            fs.Close();
            ABUtil.Log("Update Client Json Compare File Success");
        }
        catch (System.Exception e) {
            throw new System.Exception(e.Message);
        }
    }
Пример #10
0
    /// <summary>
    /// 读取本地Local文件的比较文件
    /// </summary>
    public static void ReadABCompareFile()
    {
        ABHashCollection abHashCollection = new ABHashCollection();
        string           filePath         = ABSettings.LocalCompareFilePath();

        try
        {
            FileStream   fs           = new FileStream(filePath, FileMode.Open);
            StreamReader streamReader = new StreamReader(fs);

            string jsonStr = streamReader.ReadToEnd();
            ABUtil.Log("read jsonStr: " + jsonStr);
            streamReader.Close();
            fs.Close();
        }
        catch (Exception e)
        {
            ABUtil.Log(e.Message);
        }
    }
Пример #11
0
    private IEnumerator DownloadAndCache(ABHandler abHandler)
    {
        bool cached = Caching.IsVersionCached(ABGlobal.abURL + abHandler.ABName(), ABGlobal.abVersion);

        ABUtil.Log(cached ? "read ab " : "download ab " + abHandler.ABName());
        // Wait for the Caching system to be ready
        while (!Caching.ready)
        {
            yield return(null);
        }

        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using (WWW www = WWW.LoadFromCacheOrDownload(ABGlobal.abURL + abHandler.ABName(), ABGlobal.abVersion))
        {
            yield return(www);

            if (www.error != null)
            {
                string err = string.Format("WWW download error: {0}, name:{1}", www.error, abHandler.ABName());
                ABUtil.Log(err);
                mErr = ABDownLoadError.ERR_URL;
                yield break;
            }


            AssetBundle bundle = www.assetBundle;
            if (bundle == null)
            {
                ABUtil.Log("Null bundle: " + abHandler.ABName());
                mErr = ABDownLoadError.ERR_LoadAB;
                yield break;
            }

            abHandler.Handle(bundle);
            bundle.Unload(false);
            ABUtil.Log(cached ? "finish read ab " : "finish download ab " + abHandler.ABName());
        } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }
Пример #12
0
 private void OnBtnCleanCacheClick()
 {
     CleanLog();
     Caching.CleanCache();
     ABUtil.Log("Clean Cache Success");
 }
Пример #13
0
 /// <summary>
 /// 清除AssetBundle缓存
 /// </summary>
 public static void ClearABCache()
 {
     Caching.CleanCache();
     ABUtil.Log("Clean Cache Success");
 }