/** 加载一个 */ public void loadOne(int id) { //-1不加载 if (id == -1) { clear(); //直接返回 onComplete(); return; } //相同资源,加载中跳过 if (_isLoading && _resourceID == id) { return; } clear(); _loadVersion = LoadControl.getVersion(); int index = ++_index; _isLoading = true; LoadControl.loadOne(_resourceID = id, () => { if (_index == index && LoadControl.getVersion() == _loadVersion) { onComplete(); } }, _priority); }
private void toClear(bool needCache) { _isLoading = false; if (_resourceID != -1) { ++_index; _resourceID = -1; //版本还对 if (LoadControl.getVersion() == _loadVersion) { if (needCache) { releaseCache(); } } else { _cacheResourceID = -1; _cacheObject = null; } } }
protected virtual void disposeOver() { _disposed = true; if (_loadState > 0) { if (_loadVersion == LoadControl.getVersion() && _loadResource > 0) { //unload LoadControl.unloadOne(_loadResource); } if (_loadState == 2) { if (_smodel != null) { _smodel.doDispose(); _smodel = null; GameObject.Destroy(_modelObject); _modelObject = null; } } } //归零 _loadState = 0; }
/** 加载一个 */ public void loadOne(int id) { //-1不加载 if (id == -1) { clear(); _isLoading = false; //不返回 return; } //相同资源,加载中跳过 if (_isLoading && _resourceID == id) { return; } toClear(false); _loadVersion = LoadControl.getVersion(); int index = ++_index; _isLoading = true; AssetPoolControl.loadOne(_type, _resourceID = id, () => { if (_index == index && LoadControl.getVersion() == _loadVersion) { _isLoading = false; releaseCache(); _cacheResourceID = id; _cacheObject = AssetPoolControl.getAsset(_type, id); if (_cacheObject == null) { Ctrl.throwError("获取Asset为空,可能是业务层调用了Destroy", _type, id); } else { if (_completeCall != null) { _completeCall(_cacheObject); } } } }); }
/** 清除占用 */ public void clear() { if (_resourceID != -1) { ++_index; //版本还对 if (LoadControl.getVersion() == _loadVersion) { LoadControl.unloadOne(_resourceID); } _resourceID = -1; } _isLoading = false; }
/** 加载 */ protected void load(int resource) { //未加载好 if (_smodel == null) { if (_loadState == 0) { _loadState = 1; _loadVersion = LoadControl.getVersion(); _loadResource = resource; LoadControl.loadOne(resource, onLoadComplete, LoadPriorityType.UI); } } //已加载好 else { onMakeComplete(); } }