Beispiel #1
0
 public IEnumerator DownloadAndCacheABList(List <string> modifyABs)
 {
     for (int i = 0; i < modifyABs.Count; i++)
     {
         mABHandler = new ConfigAB(modifyABs[i]);
         yield return(StartCoroutine(DownloadAndCache(mABHandler)));
     }
 }
Beispiel #2
0
        public void ABHandlerTests()
        {
            var counter = Substitute.For <IStructSizeCounter>();

            counter.GetSize(typeof(Envelope)).Returns(4);
            var h      = new ABHandler();
            var reader = new MessageReader(h, counter, GetABId);
            var bytes  = stackalloc byte[10];
            var chunk  = new ByteChunk(bytes, 10);

            Assert.AreEqual(0, h.CounterA);
            Assert.AreEqual(0, h.CounterB);
            reader.MessageHandlerImpl(ATypeId, chunk);
            Assert.AreEqual(1, h.CounterA);
            Assert.AreEqual(0, h.CounterB);
            reader.MessageHandlerImpl(BTypeId, chunk);
            Assert.AreEqual(1, h.CounterA);
            Assert.AreEqual(1, h.CounterB);
        }
Beispiel #3
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)
    }