Example #1
0
 //
 void Update()
 {
     if (this.m_iLoadIndex < this.m_lstPath.Count)
     {
         if (this.m_cLoadPackage == null)
         {
             this.m_cLoadPackage = LoadPackage.StartWWW(this.m_lstPath[this.m_iLoadIndex],
                                                        true, this.m_lstFTime[this.m_iLoadIndex],
                                                        finish_callback, error_callback,
                                                        this.m_lstResType[this.m_iLoadIndex]);
         }
         if (this.m_cLoadPackage.Complete)
         {
             this.m_cLoadPackage = null;
             this.m_iLoadIndex++;
         }
     }
     else
     {
         if (this.m_delFinishCallback == null)
         {
             Debug.LogError("The finish callback is null.");
         }
         else
         {
             this.m_delFinishCallback(this.m_mapRes);
         }
         GameObject.DestroyImmediate(this.gameObject);
     }
 }
        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            this.m_bStart = true;

            this.m_cLoader = LoadPackage.StartWWW(
                this.m_strFilePath, this.m_bAutoSave, this.m_lUTime, LoaderCallBack,
                ErrorCallBack, this.m_eResType, this.m_eEncryType, this.m_funDecryptFunc);
            this.m_cLoader.transform.parent = ResourceMgr.sInstance.transform;
        }
 /// <summary>
 /// 停止加载
 /// </summary>
 public void StopLoader()
 {
     if (this.m_cLoader != null)
     {
         this.m_cLoader.StopAllCoroutines();
         UnityEngine.Object.Destroy(this.m_cLoader.gameObject);
         UnityEngine.Object.Destroy(this.m_cLoader);
         this.m_cLoader = null;
     }
 }
 /// <summary>
 /// 销毁
 /// </summary>
 public void Destory(bool force)
 {
     if (this.m_cLoader != null)
     {
         this.m_cLoader.StopAllCoroutines();
         UnityEngine.Object.Destroy(this.m_cLoader.gameObject);
         UnityEngine.Object.Destroy(this.m_cLoader);
         this.m_cLoader = null;
     }
     if (this.m_cAsset != null && this.m_cAsset is AssetBundle)
     {
         ((AssetBundle)this.m_cAsset).Unload(force);
         this.m_cAsset = null;
     }
 }
        private bool m_bAutoSave;                     //auto save function.

        /// <summary>
        /// 开始WW加载
        /// </summary>
        /// <param name="path"></param>
        /// <param name="crc"></param>
        /// <param name="version"></param>
        /// <param name="callback"></param>
        /// <param name="res_type"></param>
        /// <param name="encrypt_type"></param>
        /// <param name="decryptFunc"></param>
        public static LoadPackage StartWWW(
            string path,
            bool autosave = false, long utime = 0, DOWN_FINISH_CALLBACK callback = null,
            DOWN_ERROR_CALLBACK error_call = null,
            RESOURCE_TYPE res_type         = RESOURCE_TYPE.WEB_ASSETBUNLDE,
            ENCRYPT_TYPE encrypt_type      = ENCRYPT_TYPE.NORMAL,
            DecryptBytesFunc decryptFunc   = null
            )
        {
            GameObject  obj    = new GameObject("WWWLoad");
            LoadPackage loader = obj.AddComponent <LoadPackage>();

            loader.Init(
                path, autosave, utime, callback, error_call,
                res_type, encrypt_type, decryptFunc);
            loader.StartCoroutine("Load");
            return(loader);
        }
        /// <summary>
        /// 加载器回调
        /// </summary>
        /// <param name="path"></param>
        /// <param name="www"></param>
        private void LoaderCallBack(string path, object asset)
        {
            //资源
            this.m_cAsset = asset;
            //回调
            CompleteCallBack();

            this.m_bComplete = true;

            //删除加载器
            if (this.m_cLoader != null)
            {
                GameObject.Destroy(this.m_cLoader.gameObject);
            }
            this.m_cLoader = null;

            if (this.m_bAutoClear)
            {
                ResourceMgr.UnloadResource(this.m_cPathUri.AbsolutePath);
            }
        }
 //
 void Update()
 {
     if(this.m_iLoadIndex < this.m_lstPath.Count )
     {
         if( this.m_cLoadPackage == null )
         {
             this.m_cLoadPackage = LoadPackage.StartWWW(this.m_lstPath[this.m_iLoadIndex] ,
                                                        true , this.m_lstFTime[this.m_iLoadIndex],
                                                        finish_callback , error_callback ,
                                                        this.m_lstResType[this.m_iLoadIndex]);
         }
         if( this.m_cLoadPackage.Complete )
         {
             this.m_cLoadPackage = null;
             this.m_iLoadIndex++;
         }
     }
     else
     {
         if(this.m_delFinishCallback == null ) Debug.LogError("The finish callback is null.");
         else this.m_delFinishCallback(this.m_mapRes);
         GameObject.DestroyImmediate(this.gameObject);
     }
 }
        /// <summary>
        /// 加载器回调
        /// </summary>
        /// <param name="path"></param>
        /// <param name="www"></param>
        private void LoaderCallBack(string path, object asset)
        {
            //资源
            this.m_cAsset = asset;
            //回调
            CompleteCallBack();

            this.m_bComplete = true;

            //删除加载器
            if (this.m_cLoader != null)
                GameObject.Destroy(this.m_cLoader.gameObject);
            this.m_cLoader = null;

            if(this.m_bAutoClear)
            {
                ResourceMgr.UnloadResource(this.m_cPathUri.AbsolutePath);
            }
        }
 /// <summary>
 /// 停止加载
 /// </summary>
 public void StopLoader()
 {
     if (this.m_cLoader != null)
     {
         this.m_cLoader.StopAllCoroutines();
         UnityEngine.Object.Destroy(this.m_cLoader.gameObject);
         UnityEngine.Object.Destroy(this.m_cLoader);
         this.m_cLoader = null;
     }
 }
        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            this.m_bStart = true;

            this.m_cLoader = LoadPackage.StartWWW(
                this.m_strFilePath , this.m_bAutoSave , this.m_lUTime , LoaderCallBack,
                ErrorCallBack , this.m_eResType, this.m_eEncryType, this.m_funDecryptFunc);
            this.m_cLoader.transform.parent = ResourceMgr.sInstance.transform;
        }
 /// <summary>
 /// 销毁
 /// </summary>
 public void Destory( bool force )
 {
     if (this.m_cLoader != null)
     {
         this.m_cLoader.StopAllCoroutines();
         UnityEngine.Object.Destroy(this.m_cLoader.gameObject);
         UnityEngine.Object.Destroy(this.m_cLoader);
         this.m_cLoader = null;
     }
     if (this.m_cAsset != null && this.m_cAsset is AssetBundle)
     {
         ((AssetBundle)this.m_cAsset).Unload(force);
         this.m_cAsset = null;
     }
 }