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); } }
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); } }
public UIFont getFontByName(string fontName) { if (fontMap.ContainsKey(fontName)) { return(fontMap[fontName]); } #if UNITY_EDITOR string tmpPath = ""; if (CLCfgBase.self.isEditMode && !Application.isPlaying) { tmpPath = PStr.begin() .a("Assets/").a(CLPathCfg.self.basePath).a("/").a("upgradeRes4Dev"). a("/priority/font/").a(fontName).a(".prefab").end(); UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(tmpPath, typeof(UnityEngine.Object)); if (obj != null) { return(((GameObject)obj).GetComponent <UIFont>()); } return(null); } else { return(_getFontByName(fontName)); } #else return(_getFontByName(fontName)); #endif }
/// iprogressCallback. 进度回调,回调有两个参数 /// ifinishCallback. 完成回调 /// isdoUpgrade. 是否做更新处理 public static void init(object iprogressCallback, object ifinishCallback, bool isdoUpgrade, string _verVerMD5) { haveUpgrade = false; verVerMD5 = _verVerMD5; baseUrl = CLVerManager.self.baseUrl; //CLVerManager.self.haveUpgrade = false; isNeedUpgradePriority = false; localverVer.Clear(); serververVer.Clear(); localPriorityVer.Clear(); serverPriorityVer.Clear(); otherResVerOld.Clear(); otherResVerNew.Clear(); platform = CLPathCfg.self.platform; CLVerManager.self.platform = platform; mVerverPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a(resVer).a("/").a(platform).a("/").a(fverVer).e(); mVerPrioriPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a(resVer).a("/").a(platform).a("/").a(versPath).a("/").a(verPriority).e(); mVerOtherPath = PStr.begin().a(CLPathCfg.self.basePath).a("/").a(resVer).a("/").a(platform).a("/").a(versPath).a("/").a(verOthers).e(); CLVerManager.self.mVerverPath = mVerverPath; CLVerManager.self.mVerPrioriPath = mVerPrioriPath; CLVerManager.self.mVerOtherPath = mVerOtherPath; progressCallback = iprogressCallback; onFinishInit = ifinishCallback; getServerVerverMap(); }
static IEnumerator loadPanel(string pName, object callback, object paras) { if (CLCfgBase.self.isEditMode) { string path = PStr.begin().a("file://").a(CLPathCfg.persistentDataPath).a("/") .a(CLPathCfg.self.panelDataPath).a(CLPathCfg.self.platform).a("/").a(pName).a(".unity3d").end(); if (CLCfgBase.self.isEditMode) { path = path.Replace("/upgradeRes/", "/upgradeRes4Publish/"); } WWW www = new WWW(path); yield return(www); if (string.IsNullOrEmpty(www.error)) { finishGetPanel(pName, www.assetBundle, callback, paras); www.Dispose(); www = null; } } else { string path = PStr.begin().a(CLPathCfg.self.panelDataPath).a(CLPathCfg.self.platform).a("/").a(pName).a(".unity3d").end(); CLVerManager.self.getNewestRes(path, CLAssetType.assetBundle, (Callback)onGetPanelAssetBundle, true, callback, pName, paras); } }
/// <summary> /// Wraps the path. 包装路径,以便支持 dir1/dir2/test.unity3d /// </summary> /// <returns>The path.</returns> /// <param name="basePath">Base path.</param> /// <param name="thingName">Thing name.</param> public static string wrapPath(string basePath, string thingName) { string tmpStr = thingName.Replace(".", "/"); string[] strs = tmpStr.Split('/'); string path = basePath; int len = strs.Length; for (int i = 0; i < len - 1; i++) { path = PStr.begin(path).a("/").a(strs [i]).end(); } path = PStr.begin(path).a("/").a(CLPathCfg.self.platform).a("/").a(strs [len - 1]).a(".unity3d").end(); return(path); }
/// <summary> /// Saves the new res.保存最新取得的资源 /// </summary> /// <param name='path'> /// Path. /// </param> /// <param name='content'> /// Content. /// </param> void saveNewRes(string path, byte[] content) { string file = PStr.begin().a(CLPathCfg.persistentDataPath).a("/").a(path).end(); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllBytes(file, content); if (otherResVerNew[path] != null) { //优先更新资源已经是最新的了,所以不用再同步 otherResVerOld[path] = otherResVerNew[path]; MemoryStream ms = new MemoryStream(); B2OutputStream.writeMap(ms, otherResVerOld); string vpath = PStr.begin().a(CLPathCfg.persistentDataPath).a("/").a(mVerOtherPath).end(); Directory.CreateDirectory(Path.GetDirectoryName(vpath)); File.WriteAllBytes(vpath, ms.ToArray()); } }
//-- 取得优先更新的资源 static void getPriorityFiles(string fPath) { string Url = ""; string verVal = MapEx.getString(serverPriorityVer, fPath); //--把版本号拼在后面 Url = PStr.begin().a(baseUrl).a("/").a(fPath).a(".").a(verVal).e(); //-- print("Url=="..Url); WWWEx.get(Url, CLAssetType.bytes, (Callback)onGetPriorityFiles, (Callback)initFailed, fPath, true); if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, progress, WWWEx.getWwwByUrl(Url)); } }
public UIAtlas getAtlasByName(string atlasName) { try { if (string.IsNullOrEmpty(atlasName)) { return(null); } if (atlasMap.ContainsKey(atlasName)) { return(atlasMap[atlasName]); } #if UNITY_EDITOR string tmpPath = ""; if (CLCfgBase.self.isEditMode && !Application.isPlaying) { tmpPath = PStr.begin() .a("Assets/").a(CLPathCfg.self.basePath).a("/").a("upgradeRes4Dev"). a("/priority/atlas/").a(atlasName).a(".prefab").end(); UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(tmpPath, typeof(UnityEngine.Object)); if (obj != null) { return(((GameObject)obj).GetComponent <UIAtlas>()); } return(null); } else { return(_getAtlasByName(atlasName)); } #else return(_getAtlasByName(atlasName)); #endif } catch (System.Exception e) { Debug.LogError(atlasName + "==" + e); return(null); } }
/// <summary> /// Gets the server verver map.取得服务器版本文件的版本信息 /// </summary> static void getServerVerverMap() { string url = ""; //if (CLCfgBase.self.hotUpgrade4EachServer) //{ // //-- 说明是每个服务器单独处理更新控制 // url = PStr.begin().a(baseUrl).a("/").a(mVerverPath).a(".").a(verVerMD5).e(); //} //else //{ // url = PStr.begin().a(baseUrl).a("/").a(mVerverPath).e(); //} url = PStr.begin().a(baseUrl).a("/").a(mVerverPath).e(); WWWEx.get( Utl.urlAddTimes(url), //加了时间戳,保证一定会取得最新的 CLAssetType.bytes, (Callback)onGetServerVerverBuff, (Callback)onGetServerVerverBuff, null, true); }
public void getNewestRes(string path, CLAssetType type, object onGetAsset, bool autoRealseAB, params object[] originals) { if (string.IsNullOrEmpty(path)) { return; } string verVal = ""; if (!MapEx.getBool(wwwMap, path)) { bool needSave = false; wwwMap[path] = true; if (localPriorityVer[path] != null) { //在优先资源里有 needSave = false; } else { //则可能在others里 object obj1 = otherResVerOld[path]; object obj2 = otherResVerNew[path]; if (obj1 == null && obj2 != null) { //本地没有,最新有 verVal = MapEx.getString(otherResVerNew, path); needSave = true; } else if (obj1 != null && obj2 != null) { if (obj1.ToString().Equals(obj2.ToString())) {//本地是最新的 needSave = false; } else { //本地不是最新的 verVal = MapEx.getString(otherResVerNew, path); needSave = true; } } else if (obj1 != null && obj2 == null) {//本地有,最新没有 needSave = false; } else { //都没有找到 needSave = false; #if UNITY_EDITOR // Debug.LogWarning ("Not found.path==" + path); #endif } } string url = ""; if (needSave) { if (!string.IsNullOrEmpty(verVal)) { url = PStr.begin().a(baseUrl).a("/").a(path).a(".").a(verVal).end(); } else { url = PStr.begin().a(baseUrl).a("/").a(path).end(); } if (isPrintDownload) { Debug.LogWarning(url); } } else { url = PStr.begin().a(CLPathCfg.persistentDataPath).a("/").a(path).end(); if (!File.Exists(url)) { url = System.IO.Path.Combine(Application.streamingAssetsPath, path); #if !UNITY_ANDROID || UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX url = PStr.begin().a("file://").a(url).end(); #endif } else { url = PStr.begin().a("file://").a(url).end(); } } doGetContent(path, url, needSave, type, onGetAsset, autoRealseAB, originals); } }