UIAtlas _getAtlasByName(string atlasName) { try { string tmpPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a("upgradeRes"). a("/priority/atlas/").a(CLPathCfg.self.platform).a("/").a(atlasName).a(".unity3d").end(); #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { tmpPath = tmpPath.Replace("/upgradeRes/", "/upgradeRes4Publish/"); } #endif AssetBundle atlasBundel = AssetBundle.LoadFromMemory(FileEx.readNewAllBytes(tmpPath)); if (atlasBundel != null) { GameObject go = atlasBundel.mainAsset as GameObject; atlasBundel.Unload(false); atlasBundel = null; if (go != null) { UIAtlas atlas = go.GetComponent <UIAtlas>(); atlasMap[atlasName] = atlas; return(atlas); } } return(null); } catch (System.Exception e) { Debug.LogError(e + "===" + atlasName); return(null); } }
UIFont _getFontByName(string fontName) { try { string tmpPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a("upgradeRes"). a("/priority/font/").a(CLPathCfg.self.platform).a("/").a(fontName).a(".unity3d").end(); #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { tmpPath = tmpPath.Replace("/upgradeRes/", "/upgradeRes4Publish/"); } #endif AssetBundle atlasBundel = AssetBundle.LoadFromMemory(FileEx.readNewAllBytes(tmpPath)); if (atlasBundel != null) { GameObject go = atlasBundel.mainAsset as GameObject; atlasBundel.Unload(false); atlasBundel = null; if (go != null) { UIFont font = go.GetComponent <UIFont> (); fontMap [fontName] = font; if (!string.IsNullOrEmpty(font.atlasName)) { font.atlas = getAtlasByName(font.atlasName); } return(font); } } return(null); } catch (System.Exception e) { Debug.LogError(e); return(null); } }
public virtual void setLanguage(string language) { string languageFile = PStr.b( CLPathCfg.self.localizationPath, language, ".txt").e(); byte[] buff = null; #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { languageFile = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(languageFile).e(); languageFile = languageFile.Replace("/upgradeRes/", "/upgradeRes4Dev/"); buff = File.ReadAllBytes(languageFile); } else { #if UNITY_WEBGL languageFile = languageFile.Replace(".txt", ""); #endif buff = FileEx.readNewAllBytes(languageFile); } #else #if UNITY_WEBGL languageFile = languageFile.Replace(".txt", ""); #endif buff = FileEx.readNewAllBytes(languageFile); #endif Localization.Load(language, buff); }
public static Hashtable readMaterialTexRefCfg() { Hashtable ret = null; #if UNITY_EDITOR byte[] buffer = File.Exists(materialTexRefCfgPath) ? File.ReadAllBytes(materialTexRefCfgPath) : null; #else byte[] buffer = FileEx.readNewAllBytes(materialTexRefCfgPath); #endif if (buffer != null) { MemoryStream ms = new MemoryStream(); ms.Write(buffer, 0, buffer.Length); ms.Position = 0; object obj = B2InputStream.readObject(ms); if (obj != null) { ret = obj as Hashtable; } } ret = ret == null ? new Hashtable() : ret; return(ret); }
public static byte[] myLuaLoader(ref string filepath) { byte[] bytes = null; string luaPath = ""; string strs = ""; try { if (!filepath.StartsWith(CLPathCfg.self.basePath)) { //说明是通过require进来的 filepath = filepath.Replace(".", "/"); filepath = PStr.b().a(CLPathCfg.self.basePath).a("/upgradeRes/priority/lua/").a(filepath).a(".lua").e(); } #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { filepath = filepath.Replace("/upgradeRes/", "/upgradeRes4Dev/"); luaPath = PStr.b().a(Application.dataPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } if (File.Exists(luaPath)) { strs = FileEx.getTextFromCache(luaPath); bytes = System.Text.Encoding.UTF8.GetBytes(strs); filepath = luaPath; return(bytes); } } #endif #if UNITY_WEBGL bytes = MapEx.getBytes(FileBytesCacheMap, filepath); if (bytes != null) { return(bytes); } else { bytes = FileEx.readNewAllBytes(filepath); bytes = deCodeLua(bytes); FileBytesCacheMap[filepath] = bytes; return(bytes); } #else //======================================================= //1.first load from CLPathCfg.persistentDataPath; luaPath = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } if (File.Exists(luaPath)) { bytes = FileEx.getBytesFromCache(luaPath); if (bytes != null) { // bytes = System.Text.Encoding.UTF8.GetBytes(strs); bytes = deCodeLua(bytes); FileBytesCacheMap [luaPath] = bytes; filepath = luaPath; return(bytes); } } //======================================================= //2.second load from Application.streamingAssetsPath; luaPath = PStr.b().a(Application.streamingAssetsPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } bytes = FileEx.getBytesFromCache(luaPath); if (bytes != null) { // bytes = System.Text.Encoding.UTF8.GetBytes(strs); bytes = deCodeLua(bytes); FileBytesCacheMap [luaPath] = bytes; filepath = luaPath; return(bytes); } //======================================================= //3.third load from Resources.Load (); luaPath = filepath; bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } TextAsset text = Resources.Load <TextAsset>(filepath); if (text != null) { bytes = text.bytes;// System.Text.Encoding.UTF8.GetBytes(text.text); if (bytes != null) { bytes = deCodeLua(bytes); FileBytesCacheMap[luaPath] = bytes; filepath = luaPath; return(bytes); } } //========================== return(bytes); #endif } catch (System.Exception e) { Debug.LogError(luaPath + ":" + e); return(null); } }