1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class BundleRequestAsync : BundleRequest
- {
- private AssetBundleCreateRequest _request;
- public override float progress
- {
- get
- {
- if (isDone)
- return 1;
- if (LoadState == AssetLoadState.Init)
- return 0;
- if (_request == null)
- return 1;
- return _request.progress;
- }
- }
- internal override bool Update()
- {
- if (!base.Update())
- return false;
- if(LoadState == AssetLoadState.LoadAsset)
- {
- if (_request.isDone)
- {
- assetBundle = _request.assetBundle;
- if (assetBundle == null)
- error = string.Format("unable to load assetBundle:{0}", name);
- LoadState = AssetLoadState.Loaded;
- return false;
- }
- }
- return true;
- }
- internal override void Load()
- {
- if(_request == null)
- {
- _request = AssetBundle.LoadFromFileAsync(name);
- if(_request == null)
- {
- error = name + "LoadFromFile failed.";
- return;
- }
- }
- LoadState = AssetLoadState.LoadAsset;
- }
- internal override void Unload()
- {
- _request = null;
- LoadState = AssetLoadState.Unload;
- base.Unload();
- }
- internal override void LoadImmediate()
- {
- Load();
- assetBundle = _request.assetBundle;
- if (assetBundle != null)
- {
- Debug.LogWarning("LoadImmediate:" + assetBundle.name);
- LoadState = AssetLoadState.Loaded;
- }
- }
- }
|