public T LoadAsset <T>(string _module, string _res) where T : UnityEngine.Object { T _t = null; _module = _module.ToLower(); _res = _res.ToLower(); #if UNITY_EDITOR if (!string.IsNullOrEmpty(_module)) { _t = EditorLoad <T>(_module, _res); } #endif if (_t == null) { AssetModuleConfig _amc = GetAssetModuleConfigByModule(_module, _res); if (_amc == null) { return(null); } _t = LoadAssetBundle <T>(_amc.GetBundleName(_res), _amc.GetResourceName(_res)); } if (_t == null) { Utility.LogError("模块", _module, "中的资源", _res, "加载失败!"); } return(_t); }
public void UnloadAsset(string _module, string _res) { AssetModuleConfig _amc = GetAssetModuleConfigByModule(_module, _res); if (_amc == null) { return; } UnloadAssetBundle(_amc.GetBundleName(_res)); }
public byte[] EditorLoadTextFile(string _module, string _res) { if (editorRely == null) { CreateEditorRely(); } _module = _module.ToLower(); _res = _res.ToLower(); AssetModuleConfig _amc = GetAssetModuleConfigByModule(_module, _res); string _path = editorRely[_module][_res]; _path = Path.GetDirectoryName(_path); _path += "/"; string _fname = _amc.GetResourceName(_res); string _ext = Path.GetExtension(_fname); if (_ext.EndsWith("bytes")) { string _nefname = Path.GetFileNameWithoutExtension(_fname); while (true) { if (File.Exists(_path + _nefname + ".lua")) { _path = _path + _nefname + ".lua"; break; } if (File.Exists(_path + _nefname + ".pb")) { _path = _path + _nefname + ".pb"; break; } break; } } return(File.ReadAllBytes(_path)); }
/// <summary> /// 构建资源关系 /// </summary> private static void RecordResourceRelationship(string _module, string _bundle, string[] _file) { _module = _module.ToLower(); _bundle = _bundle.ToLower(); if (currentBundleModuleName == null) { currentBundleModuleName = new AssetModuleConfig(_module, _bundle); resBundleModuleName.Add(currentBundleModuleName); } else { if (currentBundleModuleName.mN != _module || currentBundleModuleName.bN != _bundle) { currentBundleModuleName = new AssetModuleConfig(_module, _bundle); resBundleModuleName.Add(currentBundleModuleName); } } for (int i = 0; i < _file.Length; i++) { string _oneFile = _file[i].ToLower(); string _fileExt = Path.GetExtension(_oneFile); if (_fileExt.EndsWith("meta")) { continue; } string _fileName = Path.GetFileNameWithoutExtension(_oneFile); //assetbundle不识别lua后缀,修改为txt后缀 _fileExt = _fileExt.Replace(".lua", ".bytes"); _fileExt = _fileExt.Replace(".pb", ".bytes"); if (!currentBundleModuleName.Add(_fileName, _fileExt)) { Utility.LogError("模块", _module, "下发现重名资源:", _fileName, " 路径:", _file[i]); } } }
private static void Clear() { buildmap.Clear(); resBundleModuleName.Clear(); currentBundleModuleName = null; }