Beispiel #1
0
    /// <summary>
    /// 将更新过的md5更新到本地
    /// </summary>
    public void Updated(string subPath)
    {
        // AppLog.d(Tag, "Updated: {0}", subPath);
        //lock(mDiffListLock)
        {
            var newi  = mDiffList.Find(i => i == subPath);
            var hash  = mRemoteManifest.GetAssetBundleHash(newi).ToString();
            var binfo = mLocalManifest.Find(i => i.Name == subPath);
            if (binfo == null)
            {
                binfo = new BundleInfo()
                {
                    Name = subPath,
                    Hash = hash
                };
                mLocalManifest.Add(binfo);
            }
            if (newi != null)
            {
                AppLog.d(Tag, "Updated: {0} {1}=>{2}", newi, binfo.Hash, hash);
                binfo.Hash = hash;
                SaveManifest(mLocalManifest, LocalManifestPath);

                mDiffList.Remove(newi);
            }

            AssetSys.UnloadBundle(subPath, false);
            AssetSys.GetBundleSync(subPath);
        }
    }
Beispiel #2
0
    public static T InstanceRuntime()
    {
        if (mInstance == null)
        {
            // from bundle
            var assetSubPath = AssetPath.Replace("Assets/", "config/");
            var cachePath    = AssetSys.CacheRoot + AssetSys.GetBundlePath(assetSubPath);
            if (File.Exists(cachePath))
            {
                var bundle = AssetBundle.LoadFromFile(cachePath);
                mInstance = bundle.LoadAsset <T>(BuildConfig.BundleResRoot + assetSubPath);
            }
            // from resources
            else
            {
                var respath = AssetPath.Replace("Assets/", "").Replace(".asset", "");
                mInstance = Resources.Load <T>(respath);
            }

            if (mInstance == null)
            {
                mInstance = CreateInstance <T>();
            }
            mInstance.Init();
        }
        return(mInstance);
    }
Beispiel #3
0
    /// <summary>
    /// 下载差异资源
    /// </summary>
    public IEnumerator DownloadDiffFiles()
    {
        int count = 0;

        for (var idx = 0; idx < mDiffList.Count; ++idx)
        {
            var i         = mDiffList[idx];
            var subPath   = i.Replace("assets/appres/", "");
            var cachePath = AssetSys.CacheRoot + subPath;

            var dir = Path.GetDirectoryName(cachePath);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            yield return(AssetSys.Download(subPath, subPath, fs =>
            {
                Updated(subPath);
                ++count;
                if (count == mDiffList.Count)
                {
                    mAllDownloadOK = true;
                }
            }));
        }
    }
Beispiel #4
0
    public override IEnumerator Init()
    {
        AppLog.isEditor = Application.isEditor;
        AppLog.d(Tag, "App.Awake 0");

        yield return(AssetSys.Instance.Init());

        yield return(LuaSys.Instance.Init());

        string luas = AssetSys.GetStreamingAsset("config.lua") as string;

        LuaSys.Instance.DoString(luas, "config");

        yield return(SdkSys.Instance.Init());

        // download boot res
        {
            var ifix_patch_path = $"ifix/{AssetSys.PlatformName()}/Assembly-CSharp.patch.ifix";
            yield return(AssetSys.GetAsset <IFixAsset>(ifix_patch_path, asset =>
            {
                if (asset != null)
                {
                    try
                    {
                        PatchManager.Load(new MemoryStream(asset.data));
                        IFixPatched = true;
                        StartCoroutine(IFixTest());
                    }
                    catch (Exception e)
                    {
                        UnityEngine.Debug.LogError(e);
                    }
                }
                else
                {
                    Debug.LogError($"AppResourceManager.Load({ifix_patch_path}) failed.");
                }
            }));

            yield return(AssetSys.GetAsset("lua/utility/util.lua"));

            yield return(AssetSys.GetAsset("ui/loading/loading.prefab"));

            yield return(AssetSys.GetAsset("ui/dialog/dialog01.prefab"));

            yield return(AssetSys.GetAsset("common/config/config.lua"));

            yield return(AssetSys.GetAsset("common/root/root.prefab"));
        }

        yield return(AssetSys.GetAsset <GameObject>("common/root/root.prefab", asset =>
        {
            var obj = GameObject.Instantiate(asset);
            obj.transform.localPosition = Vector3.zero;
            obj.transform.eulerAngles = Vector3.zero;
        }));

        yield return(base.Init());
    }
Beispiel #5
0
    public IEnumerator GetRemoteVersion()
    {
        var remoteVersionUrl = AssetSys.WebRoot + AssetSys.PlatformName() + "/" + "resversion.txt";

        AppLog.d(Tag, remoteVersionUrl);

        var temp = Path.GetTempFileName().upath();

        yield return(AssetSys.Download(remoteVersionUrl, temp));

        mRemoteVersion = new Version(File.ReadAllText(temp));
        AppLog.d(Tag, "RemoteVersion {0}", mRemoteVersion.ToString());
        yield return(null);
    }
Beispiel #6
0
    public LuaTable GetLuaTable(byte[] textBytes, LuaTable env, string name)
    {
        //sweep utf bom
        AssetSys.TrimBom(ref textBytes);

        var table = luaEnv.DoString(Encoding.UTF8.GetString(textBytes), name, env);

        if (table != null && table.Length > 0)
        {
            var luaTable = table[0] as LuaTable;
            return(luaTable);
        }
        else
        {
            return(null);
        }
    }
Beispiel #7
0
    public IEnumerator GetRemoteManifest()
    {
        var remoteManifestUrl = AssetSys.WebRoot + AssetSys.PlatformName() + "/" + mRemoteVersion + "/" + AssetSys.PlatformName();

        var old = AssetBundle.GetAllLoadedAssetBundles().ToList().Find(i => i.name == ""); //AssetBundleManifest);

        if (old)
        {
            AppLog.d(Tag, $"unload AssetBundleManifest {old.name}:{old}");
            old.Unload(true);
        }

        var temp = Path.GetTempFileName().upath();

        yield return(AssetSys.Download(remoteManifestUrl, temp, fs =>
        {
            mRemoteManifest = AssetBundle.LoadFromStream(fs).LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        }));
    }
Beispiel #8
0
    public byte[] Require(string luapath, string search = "", int retry = 0)
    {
        if (string.IsNullOrEmpty(luapath))
        {
            return(null);
        }

        var LuaExtension = BuildConfig.LuaExtension;

        if (luapath.EndsWith(LuaExtension))
        {
            luapath = luapath.Remove(luapath.LastIndexOf(LuaExtension));
        }

        byte[] bytes     = null;
        var    assetName = search + luapath.Replace(".", "/") + LuaExtension;

        // AppLog.d(Tag, "require: " + assetName);
#if UNITY_EDITOR
        if (!BuildConfig.Instance().UseBundle)
        {
            if (File.Exists(BuildConfig.BundleResRoot + assetName))
            {
                bytes = File.ReadAllBytes(BuildConfig.BundleResRoot + assetName);
            }
        }
        else
#endif
        {
            var data = AssetSys.GetAssetSync <TextAsset>(assetName);
            if (data != null)
            {
                bytes = data.bytes;
            }
        }

        if (bytes == null && retry < PackagePath.Length)
        {
            bytes = Require(luapath, PackagePath[retry], 1 + retry);
        }
        return(bytes);
    }
Beispiel #9
0
    /// <summary>
    /// 检查更新
    /// </summary>
    public IEnumerator CheckUpdate()
    {
        LocalManifestPath = AssetSys.CacheRoot + "manifest.yaml";
        #if UNITY_EDITOR
        var UseBundle = BuildConfig.Instance().UseBundle;
        if (!UseBundle)
        {
            yield break;
        }
        #endif

        // var isOK = false;
        // 是否需要更新
        yield return(GetLocalVersion());

        yield return(GetRemoteVersion());

        //if(LocalVersion != RemoteVersion)// 允许回档到历史版本?
        {
            // download md5 list & uncompress & clean zip
            yield return(GetLocalManifest());

            yield return(GetRemoteManifest());

            Diff();

            // yield return DownloadDiffFiles();


            // 更新完成后保存
            var cacheUrl         = AssetSys.CacheRoot + "resversion.txt";
            var strRemoteVersion = mRemoteVersion.ToString();
            // File.WriteAllText(cacheUrl, strRemoteVersion);
            byte[] bytes = System.Text.Encoding.Default.GetBytes(strRemoteVersion);
            AssetSys.AsyncSave(cacheUrl, bytes);
        }

        yield return(null);
    }