예제 #1
0
 /// <summary>
 /// 从cache中加载bundle
 /// </summary>
 private bool load_bundle_from_cache(string _bundle_path, List <BundleObject> _all_bundles)
 {
     if (bundleobj_cache_.is_in_cache(_bundle_path))
     {
         BundleObject bundle_object = bundleobj_cache_.get_bundle_object_from_cache(_bundle_path);
         if (!_all_bundles.Contains(bundle_object))
         {
             _all_bundles.Add(bundle_object);
             bundle_object.add_ref();//增加引用,防止在加载过程中被gc销毁
             //bundle_object.load_fbx_inf();//set the mesh info if this is a fbx info
         }
         return(true);
     }
     return(false);
 }
예제 #2
0
        /// <summary>
        /// 加载DefaultRes
        /// </summary>
        private IEnumerator load_first_bundle()
        {
            // 使用LoadFromFileAsync进行加载(ios包内外均可使用,android必须拷贝到包外)
            bool   is_from_package = false;
            uint   file_offset     = 0;
            string bundle_url      = get_bundle_url(FIRST_INIT_BUNDLE, ref is_from_package, ref file_offset);

            bundle_url = CommonTool.WipeFileSprit(bundle_url);

            AssetBundle bundle = null;

            if (AuditManager.Instance.Open)
            {
                var request = AssetBundle.LoadFromFileAsync(bundle_url, 0, file_offset);
                yield return(request);

                bundle = request.assetBundle;
            }
            else
            {
                var request = AssetBundle.LoadFromFileAsync(bundle_url);
                yield return(request);

                bundle = request.assetBundle;
            }

            BundleObject bundle_object = new BundleObject(FIRST_INIT_BUNDLE, bundle);

            bundle_object.add_ref();
            put_bundle_object_to_cache(FIRST_INIT_BUNDLE, bundle_object);

#if UNITY_IPHONE
            // 在ios提审/内存小于1G时,不进行Shader的预加载
            if (AuditManager.Instance.Open || SystemInfo.systemMemorySize <= 1024)
            {
                yield break;
            }
#endif

            // 加载ShaderVariantCollection
            var load_request = bundle.LoadAllAssetsAsync(typeof(UnityEngine.ShaderVariantCollection));
            yield return(load_request);

            var load_asset = load_request.asset;
            if (load_asset != null)
            {
                Debug.Log("load shadervariantvollection succ.");

                // warmup
                var shader_varient = load_asset as UnityEngine.ShaderVariantCollection;
                if (!shader_varient.isWarmedUp)
                {
                    shader_varient.WarmUp();
                }

                // Shader变体存为静态变量
                var variant_info = MainGame.GetGlobalMono().gameObject.AddComponent <ShaderVariantInfo>();
                if (variant_info != null)
                {
                    variant_info.ShaderVariantUsed = shader_varient;
                }
            }
            else
            {
                Debug.Log("load shadervariantvollection failed !!!");
            }
        }
예제 #3
0
        /// <summary>
        /// 从磁盘上加载bundle文件
        /// </summary>
        private IEnumerator load_bundle_from_disk_coroutine(string _bundle_path, List <BundleObject> _all_bundles, bool is_ui_asset)
        {
            // 获取实际的文件路径
            bool   from_install_package = false;
            uint   file_offset          = 0;
            string bundle_url           = bundleobj_cache_.get_bundle_url(_bundle_path, ref from_install_package, ref file_offset);

            if (bundle_url == null)
            {
                Debug.LogError(string.Format("[ResourceLoader](load_bundle_from_disk_coroutine)bundle url null. bundle path: {0}", _bundle_path));
                yield break;
            }

            AssetBundle bundle = null;

            if (from_install_package == false)// 在包外通过LoadFromFileAsync来加载会更快
            {
                bundle_url = CommonTool.WipeFileSprit(bundle_url);

                if (!is_ui_asset)
                {
                    if (AuditManager.Instance.Open) // 提审状态开启的时候,资源需要从bin文件读取
                    {
                        var requeset = AssetBundle.LoadFromFileAsync(bundle_url, 0, file_offset);
                        yield return(requeset);

                        bundle = requeset.assetBundle;
                    }
                    else
                    {
                        var requeset = AssetBundle.LoadFromFileAsync(bundle_url);
                        yield return(requeset);

                        bundle = requeset.assetBundle;
                    }
                }
                else
                {
                    if (AuditManager.Instance.Open) // 提审状态开启的时候,资源需要从bin文件读取
                    {
                        bundle = AssetBundle.LoadFromFile(bundle_url, 0, file_offset);
                    }
                    else
                    {
                        bundle = AssetBundle.LoadFromFile(bundle_url);
                    }
                }
            }
            else // 在包内时,因为程序修改了x.data的路径,所以必须通过www来进行加载*/
            {
#if UNITY_IPHONE
                if (AuditManager.Instance.Open) // 提审状态开启的时候,资源需要从bin文件读取
                {
                    // ios streamingasset目录下的文件也可以通过LoadFromFileAsync来读取
                    bundle_url = CommonTool.WipeFileSprit(bundle_url);
                    var requeset = AssetBundle.LoadFromFileAsync(bundle_url, 0, file_offset);
                    yield return(requeset);

                    bundle = requeset.assetBundle;
                }
                else
                {
                    // ios streamingasset目录下的文件也可以通过LoadFromFileAsync来读取
                    bundle_url = CommonTool.WipeFileSprit(bundle_url);
                    var requeset = AssetBundle.LoadFromFileAsync(bundle_url);
                    yield return(requeset);

                    bundle = requeset.assetBundle;
                }
#else
                // 通过www来加载bundle
                WWW www = new WWW(bundle_url);
                yield return(www);

                while (!www.isDone)
                {
                    Debug.LogError(string.Format("[ResourceLoader](load_bundle_from_disk_coroutine) this is harmless, bundle ids not donw after yield: {0}", _bundle_path));
                    yield return(new WaitForEndOfFrame());
                }
                // 加载完毕后获取assetbundle
                bundle = www.assetBundle;
                www.Dispose();
#endif
            }

            if (bundle == null)
            {
                string msg = string.Format("[ResourceLoader](load_bundle_from_disk_coroutine)load bundle from www failed, unity3d file is in valid, bundle path is {0} device is {1}", _bundle_path, SystemInfo.deviceModel);
                Debug.LogError(msg);
                ControlServerLogHelper.Instance.PostPlayerFollowRecord(PlayerFollowRecordSceneId.ResLoadFail, msg, false);
                // Post The File Msg To DownloadRepairer Manager
                //ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_BUNDLE_RES_LOAD_FAILED, new CEventBaseArgs(_bundle_path));
                var patch_mgr = xpatch.XPatchManager.Instance;
                if (patch_mgr.IsAutoFix)
                {
                    patch_mgr.DownloadBundle(_bundle_path);
                }

                BuglyAgent.ReportException(new IOException(), msg);

                yield break;
            }

            // 加载的bundle使用BundleObject进行包装并放入到Cache中
            BundleObject bundle_object = new BundleObject(_bundle_path, bundle);
            if (_bundle_path.EndsWith(CACHE_STR_CS))
            {
                bundle_object.add_ref();
            }
            bundleobj_cache_.put_bundle_object_to_cache(_bundle_path, bundle_object);
            _all_bundles.Add(bundle_object);
            bundle_object.add_ref();            //增加引用,防止在加载过程中被gc销毁
            //bundle_object.load_fbx_inf();//set the mesh info if this is a fbx info
        }
예제 #4
0
 public void add_depend_bundle(BundleObject _bundle_object)
 {
     _bundle_object.add_ref();
     dependence_bundles_.Add(_bundle_object);
 }