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 }
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 override string getAssetPath(string name) { string path = PStr.b().a(CLPathCfg.self.basePath).a("/") .a(CLPathCfg.upgradeRes).a("/other/things").e(); return(wrapPath(path, name)); }
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); }
// 时间格式化为:HH时mm分ss秒; public static string toStrCn(long ms) { int[] arr = getTimeArray(ms); int hour = arr[0] * 24 + arr[1]; String strHour = ""; String strMinute = ""; String strSecond = ""; if (hour > 0) { strHour = hour < 10 ? PStr.b().a("0").a(hour).e() : PStr.b().a(hour).a("").e(); strHour = PStr.b().a(strHour).a(Localization.Get("UIHour")).e(); } int minute = arr[2]; if (minute > 0) { strMinute = minute < 10 ? PStr.b().a("0").a(minute).e() : PStr.b().a(minute).a("").e(); strMinute = PStr.b().a(strMinute).a(Localization.Get("UIMinute")).e(); } int second = arr[3]; if (second >= 0) { strSecond = second < 10 ? PStr.b().a("0").a(second).e() : PStr.b().a(second).a("").e(); strSecond = PStr.b().a(strSecond).a(Localization.Get("UISecond")).e(); } return(PStr.b().a(strHour).a(strMinute).a(strSecond).e()); }
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); } }
public void jump() { int len = orgStr.Length; if (len < 2) { return; } index++; if (index >= len) { index = 0; } string left = StrEx.Left(orgStr, index); string mid = StrEx.Mid(orgStr, index, 1); string right = StrEx.Right(orgStr, len - index - 1); string str = PStr.b() .a("[sub]") .a(left) .a("[/sup]") .a("[sup]").a(mid).a("[/sup]") .a("[sub]") .a(right) .a("[/sup]") .e(); base.text = str; timeCount = Time.time + speed; }
public static PStr begin(string s) { PStr ret = new PStr(); ret.sb.Append(s); return(ret); }
public static byte[] readBytesFromStreamingAssetsPath(string filepath) { byte[] buff = null; try { #if UNITY_ANDROID && !UNITY_EDITOR sbyte[] sbuff = null; string tempPath = filepath.Replace(PStr.b().a(Application.streamingAssetsPath).a("/").e(), ""); AndroidJavaObject obj = jcAssetMgr.CallStatic <AndroidJavaObject>("getBytes", tempPath); if (obj != null && obj.GetRawObject().ToInt32() != 0) { sbuff = AndroidJNIHelper.ConvertFromJNIArray <sbyte[]>(obj.GetRawObject()); } if (obj != null) { obj.Dispose(); obj = null; } buff = Array.ConvertAll <sbyte, byte>(sbuff, a => (byte)a); #else if (File.Exists(filepath)) { buff = File.ReadAllBytes(filepath); } #endif } catch (Exception e) { Debug.LogError(e); } return(buff); }
/// 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(); }
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); } }
//-- 取得版本文件 static void getVerinfor(string fPath, string verVal) { //-- 注意是加了版本号的,可以使用cdn string url = PStr.b().a(baseUrl).a("/").a(fPath).a(".").a(verVal).e(); WWWEx.get(url, CLAssetType.bytes, (Callback)onGetVerinfor, (Callback)onGetVerinfor, fPath, true); }
public override void OnApplicationQuit() { base.OnApplicationQuit(); #if UNITY_EDITOR string atlasPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/upgradeRes4Dev/priority/atlas/atlasAllReal.prefab").e(); CLUIInit.self.emptAtlas.replacement = (UIAtlas)(AssetDatabase.LoadAssetAtPath(atlasPath, typeof(UIAtlas))); #endif }
static void onGetVerinfor(params object[] param) { byte[] content = param[0] as byte[]; object orgs = param[1]; if (content != null) { string fPath = orgs as string; progress = progress + 1; MapEx.set(localverVer, fPath, MapEx.getString(serververVer, fPath)); string fName = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(newestVerPath).a("/").a(fPath).e(); if (Path.GetFileName(fName) == "priority.ver") { //-- 优先更新需要把所有资源更新完后才记录 isNeedUpgradePriority = true; serverPriorityVer = CLVerManager.self.toMap(content); CLVerManager.self.localPriorityVer = serverPriorityVer; } else { otherResVerNew = CLVerManager.self.toMap(content); CLVerManager.self.otherResVerNew = otherResVerNew; } MapEx.set(needUpgradeVerver, fPath, true); if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, progress); } //-- if (isFinishAllGet()) then if (needUpgradeVerver.Count == progress) { if (!isNeedUpgradePriority) { //-- 说明没有优先资源需要更新,可以不做其它处理了 //--同步到本地 loadPriorityVer(); loadOtherResVer(true); } else { checkPriority(); //--处理优先资源更新 } } } else { initFailed(); } }
static void checkVervers() { progress = 0; needUpgradeVerver.Clear(); isNeedUpgradePriority = false; string ver = null; ArrayList keysList = MapEx.keys2List(serververVer); int count = keysList.Count; string basePath = CLPathCfg.self.basePath; string key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; ver = MapEx.getString(localverVer, key); //实际上这个时间localverVer是空的 if (ver == null || ver != MapEx.getString(serververVer, key)) { if (!key.Contains(PStr.b().a(basePath).a("/ui/panel").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/cell").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/other").e())) { MapEx.set(needUpgradeVerver, key, false); } } } keysList.Clear(); keysList = null; if (needUpgradeVerver.Count > 0) { if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, 0); } keysList = MapEx.keys2List(needUpgradeVerver); count = keysList.Count; key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; getVerinfor(key, MapEx.getString(serververVer, key)); } keysList.Clear(); keysList = null; } else { loadPriorityVer(); loadOtherResVer(true); } }
public static string nStrForLen(string str, int len) { try { string ret = ""; for (int i = 0; i < len - str.Length; i++) { ret = PStr.b().a(ret).a("0").e(); } return(PStr.b().a(ret).a(str).e()); } catch { return("0"); } }
public bool init() { clean(); #if !UNITY_EDITOR && !UNITY_WEBGL //取得最新的语言 Callback cb = onGetLocalize; StartCoroutine(FileEx.readNewAllBytesAsyn( PStr.b(CLPathCfg.self.localizationPath).a(Localization.language).a(".txt").e(), cb)); #endif return(initAtlas()); }
public static bool isNeedDownload(string roleName) { #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { return(false); } #endif string path = PStr.b().a(CLPathCfg.self.basePath).a("/") .a(CLPathCfg.upgradeRes).a("/other/roles").e(); path = wrapPath(path, roleName); return(CLVerManager.self.checkNeedDownload(path)); }
/// <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); }
public static string ToTimeCost(long msec) { int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(Localization.Get("DayBefore")).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } // hour += day * 24; string hstr = ((retstr.Length > 0 || hour > 0) ? PStr.b().a(hour).a(Localization.Get("HourBefore")).e() : ""); retstr = PStr.b().a(retstr).a(hstr).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } remainder = remainder % 3600000; if (remainder != 0) { minute = (int)remainder / 60000; } // retstr += ((retstr.Length > 0 || minute > 0) ? (minute + Localization.Get("MinutesBefore")) : "0" + Localization.Get("MinutesBefore")); string mstr = ((retstr.Length > 0 || minute > 0) ? PStr.b().a(minute).a(Localization.Get("MinutesBefore")).e() : ""); retstr = PStr.b().a(retstr).a(mstr).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } second = (int)remainder % 60000; second = second / 1000; // retstr += (second < 10 ? "0" + second + Localization.Get("SecondBefore") : second + Localization.Get("SecondBefore")); retstr = PStr.b().a(retstr).a(second).a(Localization.Get("SecondBefore")).e(); return(retstr); }
static public string appendSpce(string str, int totalLen) { int i = 0; if (str == null || str == "") { str = ""; } i = str.Length; PStr ps = PStr.b(str); for (; i < totalLen; i++) { ps.a(" "); } return(ps.e()); }
/// <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()); } }
/// <summary> /// 获取文件大小 /// </summary> /// <param name="file">ip服务器下的相对路径</param> /// <returns>文件大小</returns> public int GetFileSize(string file, string host, string username, string password) { StringBuilder result = new StringBuilder(); try { string uri = PStr.b().a("ftp://").a(host).a(file).e(); request = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); request.UseBinary = true; request.Credentials = new NetworkCredential(username, password); //设置用户名和密码 request.Method = WebRequestMethods.Ftp.GetFileSize; int dataLength = (int)request.GetResponse().ContentLength; return(dataLength); } catch (Exception ex) { Console.WriteLine("获取文件大小出错:" + ex.Message); return(-1); } }
public static string urlAddTimes(string url) { if (url.StartsWith("http://")) { if (url.Contains("?")) { url = PStr.b().a(url).a("&t_sign_flag___=").a(DateEx.nowMS).e(); } else { url = PStr.b().a(url).a("?t_sign_flag___=").a(DateEx.nowMS).e(); } #if CHL_NONE Debug.LogWarning(url); #endif } return(url); }
//-- 取得优先更新的资源 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 static string readTextFromStreamingAssetsPath(string filepath) { string buff = null; try { #if UNITY_ANDROID && !UNITY_EDITOR string tempPath = filepath.Replace(PStr.b().a(Application.streamingAssetsPath).a("/").e(), ""); buff = jcAssetMgr.CallStatic <string>("getString", tempPath); #else if (File.Exists(filepath)) { buff = File.ReadAllText(filepath); } #endif } catch (Exception e) { Debug.LogError(e); } return(buff); }
public static bool UploadDir(string localDir, string server, string username, string password, string remotePath, bool onlyCheckLastDir = false) { if (!Directory.Exists(localDir)) { Debug.LogError("There is no directory exist!"); return(false); } FTP ftp = new FTP(server, username, password); ftp.MakeFTPDir(remotePath, onlyCheckLastDir); string[] files = Directory.GetFiles(localDir); string file = ""; if (files != null) { FtpWebRequest request = null; for (int i = 0; i < files.Length; i++) { file = files [i]; // Debug.Log (file); ftp = new FTP(server, username, password); if (!ftp.Upload(file, remotePath)) { return(false); } } } string[] dirs = Directory.GetDirectories(localDir); if (dirs != null) { for (int i = 0; i < dirs.Length; i++) { // Debug.Log (PStr.b ().a (remotePath).a ("/").a (Path.GetFileName (dirs [i])).e ()); if (!UploadDir(dirs [i], server, username, password, PStr.b().a(remotePath).a("/").a(Path.GetFileName(dirs [i])).e(), true)) { return(false); } } } return(true); }
public static string ToTimeStr3(long msec) { // 将毫秒数换算成x天x时 int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(Localization.Get("UIDay")).e(); remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } string hstr = ((retstr.Length > 0 || hour > 0) ? PStr.b().a(hour).a(Localization.Get("UIHour")).e() : ""); return(PStr.b().a(retstr).a(hstr).e()); }
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); }