Пример #1
0
    /// <summary>
    /// 读取应用程序版本号
    /// </summary>
    private void ReadAppVersion()
    {
        string    appconfigfilepath = GameCommon.GetAppStreamingAssetPath() + "AppConfig.ini";
        INIParser ini = new INIParser();

        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(appconfigfilepath);
            while (!www.isDone)
            {
            }
            ini.OpenFromString(www.text);
            www.Dispose();
        }
        else
        {
            ini.Open(appconfigfilepath);
        }
        m_strAppVersion = ini.ReadValue("Config", "AppVer", "1.0");
        ini.Close();
    }
Пример #2
0
    /// <summary>
    /// 从保存的容器中获取资源包
    /// </summary>
    /// <param name="url">下载地址</param>
    /// <param name="version">版本号</param>
    /// <returns>返回获取的资源包</returns>
    public static AssetBundle GetAssetBundle(string abname)
    {
        AssetBundleRef abRef;

        if (dictAssetBundleRefs.TryGetValue(abname, out abRef))    //将空的abRef传递进去
        {
            return(abRef.assetBundle);
        }
        else
        {
            //尝试加载一下
#if ScFish
            if (!LoadAssetBundleFromLocal(GameCommon.GetAppStreamingAssetPath(), abname))
#else
            if (!LoadAssetBundleFromLocal(GameDefine.AssetBundleSavePath, abname))
#endif
            { return(null); }
            else
            {
                dictAssetBundleRefs.TryGetValue(abname, out abRef);
            }
        }
        return(abRef.assetBundle);
    }
Пример #3
0
    private static bool LoadDependenciesAssetBundle(string srcABName)
    {
        if (ManifestAsssetbundle == null)
        {
#if ScFish
            string path = GameCommon.GetAppStreamingAssetPath() + GameDefine.DependenciesAssetBundleName;
#else
            string path = GameDefine.AssetBundleSavePath + GameDefine.DependenciesAssetBundleName;
#endif


#if UNITY_EDITOR || UNITY_STANDALONE_WIN
            if (!Luancher.UpdateWithLuncher)
            {
#if UNITY_IOS
                path = Application.dataPath + "/AssetBundles/IOS/IOS";
#elif UNITY_ANDROID
                path = Application.dataPath + "/AssetBundles/Android/Android";
#else
                path = Application.dataPath + "/AssetBundles/Windows/Windows";
#endif
            }
#endif
            AssetBundle ab = AssetBundle.LoadFromFile(path);
            if (ab == null)
            {
                return(false);
            }
            ManifestAsssetbundle = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            ab.Unload(false);
            if (ManifestAsssetbundle == null)
            {
                return(false);
            }
        }

        try
        {
            //获取加载ab的依赖信息,参数为ab名称,如cube.ab
            string[] dependsFile = ManifestAsssetbundle.GetAllDependencies(srcABName);
            if (dependsFile.Length > 0)
            {
                string desppath = GameDefine.AssetBundleSavePath;
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
                if (!Luancher.UpdateWithLuncher)
                {
#if UNITY_IOS
                    desppath = Application.dataPath + "/AssetBundles/IOS/";
#elif UNITY_ANDROID
                    desppath = Application.dataPath + "/AssetBundles/Android/";
#else
                    desppath = Application.dataPath + "/AssetBundles/Windows/";
#endif
                }
#endif
                //根据获取到的依赖信息加载所有依赖资源ab
                for (int i = 0; i < dependsFile.Length; i++)
                {
                    if (dictAssetBundleRefs.ContainsKey(dependsFile[i]))
                    {
                        continue;
                    }
                    AssetBundle bundle = AssetBundle.LoadFromFile(desppath + dependsFile[i]);
                    if (bundle == null)
                    {
                        return(false);
                    }

                    AssetBundleRef abRef = new AssetBundleRef(desppath, dependsFile[i], 1);
                    abRef.assetBundle = bundle;
                    AddAssetBundle(dependsFile[i], abRef);
                }
            }
        }
        catch (InvalidCastException e)
        {
            Debug.LogException(e);
        }
        return(true);
    }
Пример #4
0
    IEnumerator UnzipAssetFile()
    {
        string src = GameCommon.GetAppStreamingAssetPath() + GameDefine.AssetsZipFile;
        string des = GameDefine.AssetBundleSavePath + GameDefine.AssetsZipFile;

        Debug.Log("load zip:" + src + "->" + des);

        float percent = 0.5f;

        if (Application.platform == RuntimePlatform.Android)
        {
            WWW www = new WWW(src);

            while (!www.isDone)
            {
                DownloadProcessBarImg.fillAmount = www.progress * percent;

                yield return(null);
            }

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.Log("www.error:" + www.error);
            }
            else
            {
                try
                {
                    if (File.Exists(des))
                    {
                        File.Delete(des);
                    }
                    FileStream fsDes = File.Create(des);
                    fsDes.Write(www.bytes, 0, www.bytes.Length);
                    fsDes.Flush();
                    fsDes.Close();
                    fsDes.Dispose();
                }
                catch (Exception ex)
                {
                    DownloadProcessUpdatetextObj.GetComponent <Text>().text = ex.ToString();
                    eLuancherState = LUANCHERSTATE.LuancherState_Over;
                }
            }
            www.Dispose();
        }
        else if (File.Exists(src))
        {
            yield return(CopyFileToDesPath(src, GameDefine.AssetsZipFile, GameDefine.AssetBundleSavePath, percent));
        }

        percent = 0.4f;
        yield return(UnZip(des, GameDefine.AssetBundleSavePath, null, percent, true));

        DownloadProcessBarImg.fillAmount = 0.9f;

        yield return(null);

        WriteLocalResConfig();

        DownloadProcessBarImg.fillAmount = 0.95f;

        yield return(null);

        DownHotfixAndSerABCsvFile();

        DownloadProcessBarImg.fillAmount = 1f;

        yield return(null);

        ResourceUpdateVerify();
    }