コード例 #1
0
        internal void AddBundle(string name, string asset = null)
        {
            foreach (string res in mListRes)
            {
                if (res == name)
                {
                    return;
                }
            }

            if (name.Length == 0)
            {
                Logger.GetFile(LogFile.Res).LogError(" ResList:AddBundle name can't empty");
                return;
            }
            GOEBundle bundle = ResourceMgr.Instance().GetBundle(name);

            if (bundle == null)
            {
                UnityEngine.Debug.LogError("Cannot find bundle " + name);
            }
            mListRes.Add(name);

            if (asset == null)
            {
                asset = bundle.Files.ElementAt(bundle.Files.Count - 1);
            }
            mListAsset.Add(asset);
            foreach (var i in bundle.DependsOn)
            {
                GOEBundle dep = ResourceMgr.Instance().GetBundle(i);
                mListRes.Add(i);
                mListAsset.Add(dep.FirstAsset);
            }
        }
コード例 #2
0
        internal GOEBundle GetBundle(string name)
        {
            GOEBundle bundle = null;
            if (mDicBundle.TryGetValue(name.GetHashCode(), out bundle))
            {
                return bundle;
            }

            return null;
        }
コード例 #3
0
        public bool AppendRead(string stream)
        {
            StringReader sr   = new StringReader(stream);
            string       line = sr.ReadLine();

            while (null != line)
            {
                if (line.StartsWith(BUNDLE_INFO_PREFIX))
                {
                    byte[]       buf = Convert.FromBase64String(line.Substring(BUNDLE_INFO_PREFIX.Length + 1));
                    MemoryStream ms  = new MemoryStream(buf);
                    BinaryReader br  = new BinaryReader(ms);

                    int bundleCnt = br.ReadInt32();
                    for (int i = 0; i < bundleCnt; i++)
                    {
                        string           name       = br.ReadString();
                        int              size       = br.ReadInt32();
                        int              assetCnt   = br.ReadInt32();
                        HashSet <string> assets     = new HashSet <string>();
                        string           firstAsset = null;
                        for (int j = 0; j < assetCnt; j++)
                        {
                            string assetName = br.ReadString();

                            if (firstAsset == null)
                            {
                                firstAsset = assetName;
                            }
                            ResourceMgr.Instance().RegisterBundleIdx(assetName, name, size);
                        }
                        GOEBundle bundle = ResourceMgr.Instance().GetBundle(name);
                        bundle.FirstAsset = firstAsset;
                        int dependCnt = br.ReadInt32();
                        for (int j = 0; j < dependCnt; j++)
                        {
                            string depName = br.ReadString();
                            bundle.DependsOn.Add(depName);
                        }
                    }
                }
                else
                {
                    GOEBundleMapItem bmi = new GOEBundleMapItem();
                    bmi.FromString(line);
                    if (!_bundleMap.ContainsKey(bmi.Name))
                    {
                        _bundleMap.Add(bmi.Name, bmi);
                    }
                }
                line = sr.ReadLine();
            }
            return(true);
        }
コード例 #4
0
        internal void RegisterBundleIdx(string asset, string bundleName, int size = 0)
        {
            GOEBundle bundle = this.GetBundle(bundleName);
            if (bundle == null)
            {
                bundle = new GOEBundle();
                mListBundle.Add(bundle);
                mDicBundle.Add(bundleName.GetHashCode(), bundle);
                bundle.mName = bundleName;
                bundle.Size = size;
            }

            bundle.AddFile(asset);
        }
コード例 #5
0
        public void UnRegisterIdxByBundleName(string bundleName)
        {
            GOEBundle bundle = rbl.GetBundle(bundleName);
            ResIdxMap idxMap = rim;

            if (bundle != null)
            {
                foreach (string asset in bundle.Files)
                {
                    idxMap.UnRegisterByAssetName(asset);
                }
            }

            rbl.UnRegisterByBundleName(bundleName);
        }
コード例 #6
0
        public void CacheSceneBundleDependency(GOEBundle bundle)
        {
            GOEBundleResource newRes = new GOEBundleResource();

            newRes.BundleInfo    = bundle;
            newRes.IsSceneBundle = true;
            foreach (var i in bundle.DependsOn)
            {
                GOEBundleResource res;
                if (cachedBundles.TryGetValue(i, out res))
                {
                    newRes.AddDependency(res);
                }
            }
            CacheAssetBundle(newRes);
        }
コード例 #7
0
        void BeginPreload()
        {
            GOEBundle bundle = ResourceMgr.Instance().GetBundle(mName);

            pendingDependencies = null;
            if (bundle != null)
            {
                foreach (var dep in bundle.DependsOn)
                {
                    if (pendingDependencies == null)
                    {
                        pendingDependencies = new HashSet <string>();
                    }
                    pendingDependencies.Add(dep);
                    GOERoot.ResMgr.PreloadBundle(dep, OnPreloadBundle, Priority, true);
                }
            }
        }
コード例 #8
0
        public void SampleLoadEvent(string bn, int eventID)
        {
            GOEAssetBundleProfileInfo pi = null;
            float time = Time.realtimeSinceStartup;

            if (info.TryGetValue(bn, out pi))
            {
                switch (eventID)
                {
                case 2:
                    pi.WWWStartTime = time;
                    break;

                case 3:
                    pi.WWWFinishTime = time;
                    break;

                case 4:
                    pi.ResourceReadyTime = time;
                    break;

                case 5:
                    pi.AssetLoadStartTime = time;
                    break;

                case 6:
                    pi.AssetLoadFinishTime = time;
                    break;

                case 7:
                    pi.EndTime = time;
                    break;
                }
            }
            else if (eventID == 1)
            {
                pi            = new GOEAssetBundleProfileInfo();
                pi.BundleName = bn;
                GOEBundle bundle = ResourceMgr.Instance().GetBundle(bn);
                pi.BundleSize = bundle.Size;
                pi.StartTime  = time;
                info[bn]      = pi;
            }
        }
コード例 #9
0
        protected virtual Resource CreateResource(string name, LoadPriority priority)
        {
            Resource res = new Resource();

            res.Name            = name;
            res.Loader.Priority = priority;
            mDownResource.Add(res);

            GOEBundle bundle = ResourceMgr.GetBundle(name);

            if (bundle != null)
            {
                res.Size = bundle.Size;
            }

            res.AddGotWWWCallback(this.OnLoadWWW);

            return(res);
        }
コード例 #10
0
        protected override void OnLoadAssetBundle(string name, AssetBundle www, bool dependencyResource)
        {
            if (www == null)
            {
                Logger.GetFile(LogFile.Res).LogError(name + " assetBundel == null");
                return;
            }
            string sceneName = GetSceneName(name);

            cachedBundles.Add(www);
            cachedNames.Add(sceneName);
            GOEBundle bundle = ResourceMgr.GetBundle(name);

            ResourceMgr.CacheSceneBundleDependency(bundle);
            if (sceneName == mCurScene)
            {
                this.LoadScene(sceneName);
            }
        }
コード例 #11
0
        internal ResourceState PreloadBundle(string bundleName, Action <string, AssetBundle> callback, LoadPriority priority = LoadPriority.Default, bool dependencyResource = false)
        {
            GOEBundle bundle = ResourceMgr.Instance().GetBundle(bundleName);

            if (cacheMgr.Cache[bundleName] != null)
            {
                if (callback != null)
                {
                    callback(bundleName, null);
                }
                return(ResourceState.OK);
            }
            Resource res = this.GetDownloadResource(bundleName);

            if (res == null)
            {
                if (!cacheMgr.HasLoadingInfo(bundleName))
                {
                    res = this.CreateResource(bundleName, priority);
                    res.DependencyResource = dependencyResource;
                    res.LoadRes();
                }
                cacheMgr.AddCallbackToDic(bundleName, callback);
            }
            else if (res.ResOK)
            {
                if (callback != null)
                {
                    callback(bundleName, res.Loader.AssetBundle);
                }
                return(ResourceState.OK);
            }
            else
            {
                cacheMgr.AddCallbackToDic(bundleName, callback);
                if (res.Loader.Priority < priority)
                {
                    this.ResourceMgr.GOELoaderMgr.SetLoaderPriority(res.Loader, priority);
                }
            }
            return(ResourceState.Wait);
        }
コード例 #12
0
 internal override void Start()
 {
     foreach (string name in mListRes)
     {
         GOEBundle bundle = ResourceMgr.Instance().GetBundle(name);
         if (bundle == null)
         {
             Logger.GetFile(LogFile.Res).LogError(name + " not find in FireBundle");
         }
         else
         {
             mTotalSize += bundle.Size;
         }
         progressMap[name] = 0;
     }
     if (mListRes.Count == 0)
     {
         Logger.GetFile(LogFile.Res).LogError(" mListRes.Count == 0");
     }
 }
コード例 #13
0
        void StartLoadAssets(AssetBundleAssetLoadingInfo info)
        {
            try
            {
                GOEBundle gBundle = ResourceMgr.Instance().GetBundle(info.BundleName);
                var       bundle  = info.AssetBundle;
                if (!bundle)
                {
                    Debug.LogError(string.Format("AssetBundle {0} is null", gBundle.mName));
                    return;
                }
                info.Requests = new List <AssetRequestInfo>();
                bool shouldAsync = true;
                info.IsAsync = shouldAsync;
#if DEBUG_BUNDLE_CACHE
                ResourceMgr.Instance().SampleLoadEvent(info.BundleName, 5);
#endif
                foreach (string str in gBundle.Files)
                {
                    AssetRequestInfo ar = new AssetRequestInfo();
                    ar.AssetName = str;
                    if (shouldAsync)
                    {
                        ar.Request = bundle.LoadAssetAsync(str);
                    }
                    else
                    {
                        ar.Asset = bundle.LoadAsset(str);
                    }
                    info.Requests.Add(ar);
                }
                assetLoading.Add(info);
            }
            catch
            {
                Debug.LogError("Cannot load assetbundle:" + info.BundleName);
            }
        }
コード例 #14
0
        internal void EnsureDependencies(string name)
        {
            string bundleName = ResourceMgr.GetBundleName(name);

            if (!string.IsNullOrEmpty(bundleName))
            {
                GOEBundle bundle = ResourceMgr.GetBundle(bundleName);
                if (bundle != null)
                {
                    foreach (var dep in bundle.DependsOn)
                    {
                        GOEBundle depBundle = ResourceMgr.GetBundle(dep);
                        if (depBundle == null)
                        {
                            continue;
                        }
                        if (!HasLoaded(depBundle.FirstAsset))
                        {
                            GOERoot.ResMgr.PreloadBundle(dep, null);
                        }
                    }
                }
            }
        }
コード例 #15
0
        internal override void Update()
        {
            base.Update();
            if (mListRes.Count == 0)
            {
                return;
            }
            if (mDone)
            {
                Action endf = OnEnd;
                Clear();
                if (endf != null)
                {
                    endf();
                }
            }
            int downloadsize = 0;

            foreach (string name in mListRes)
            {
                GOEBundle bundle = ResourceMgr.Instance().GetBundle(name);
                if (bundle == null)
                {
                    continue;
                }

                if (this.IsBundleCached(name))
                {
                    downloadsize += bundle.Size;
                    UpdateProgress(name, 1f);
                }
                else
                {
                    Resource res = this.GetRes(name);
                    if (res != null)
                    {
                        float prog = res.Loader.Progress;
                        UpdateProgress(name, prog);
                        downloadsize += (int)((prog) * bundle.Size);
                    }
                    else
                    {
                        float prog;
                        if (progressMap.TryGetValue(name, out prog))
                        {
                            downloadsize += (int)((prog) * bundle.Size);
                        }
                    }
                }
            }
            if (mTotalSize == 0)
            {
                mProgerss = 0;
                mDone     = true;
            }
            else if (downloadsize == mTotalSize)
            {
                mProgerss = 1.0f;
                mDone     = true;
            }
            else
            {
                mProgerss = downloadsize * 1.0f / mTotalSize;
            }
            if (ProgressHandler != null)
            {
                ProgressHandler(mProgerss);
            }
        }
コード例 #16
0
        public void CacheSceneBundleDependency(GOEBundle bundle)
        {
            AssetBundleGroup group = abg;

            group.CacheSceneBundleDependency(bundle);
        }
コード例 #17
0
 internal void CacheSceneBundleDependency(GOEBundle bundle)
 {
     cacheMgr.Cache.CacheSceneBundleDependency(bundle);
 }