public void insertList(object data, bool isNeedRePosition, bool isCalculatePosition) { ArrayList _list = null; if (data is LuaTable) { _list = CLUtlLua.luaTableVals2List((LuaTable)data); } else if (data is ArrayList) { _list = (ArrayList)data; } else if (data is object[]) { _list = new ArrayList(); _list.AddRange((object[])data); } times = (int)(_list.Count / RealCellCount); //------------------------------------------------ CLUILoopTableCell uiw = null; CLUILoopTableCell targetUIW = null; int newDataCount = _list.Count; Transform t = null; int _startIndex = 0; if (itemList != null && itemList.Count > 0) { _startIndex = NumEx.stringToInt(itemList [0].name); for (int i = 0; i < itemList.Count; i++) { uiw = itemList [i]; if (uiw == null) { continue; } uiw.name = NumEx.nStrForLen(newDataCount + _startIndex + i, 6); } } //------------------------------------------------ if (RealCellCount > itemList.Count) { Debug.Log("说明之前加载的数据没有占用完所有单元"); //说明之前加载的数据没有占用完所有单元 _insertList(_list, isCalculatePosition); if (isNeedRePosition) { table.Reposition(); } } //------------------------------------------------ if (list != null) { _list.AddRange(list); } list = _list; }
public void insertList(object data) { ArrayList _list = null; _list = wrapList(data); UIWidget uiw = null; int newDataCount = _list.Count; int _startIndex = 0; if (itemList != null && itemList.Count > 0) { _startIndex = NumEx.stringToInt(itemList [0].name); for (int i = 0; i < itemList.Count; i++) { uiw = itemList [i]; if (uiw == null) { continue; } uiw.name = NumEx.nStrForLen(newDataCount + _startIndex + i, 6); } } if (list != null) { _list.AddRange(list); } list = _list; refreshContentOnly(); }
/// <summary> /// Encoder the specified str and scrtkey.加密 /// </summary> /// <param name='str'>要加密的串 /// String. /// </param> /// <param name='scrtkey'>密钥secretkey /// Scrtkey. /// </param> public static string encoder(string str, string scrtkey) { if (string.IsNullOrEmpty(str)) { return(""); } string unicodestr = ""; string posstr = ""; string tmpstr = ""; string uniscrtkey = ""; string ret = ""; int i; int[] poslist = new int[str.Length]; for (i = 0; i < str.Length; i++) { unicodestr = unicodestr + (int)(str [i]); poslist [i] = unicodestr.Length; } for (i = 0; i < str.Length; i++) { tmpstr = StrEx.Mid(unicodestr, poslist [i] - 1, 1); unicodestr = tmpstr + StrEx.Left(unicodestr, poslist [i] - 1) + StrEx.Mid(unicodestr, poslist [i]); posstr = posstr + NumEx.nStrForLen(poslist [i], 4); //每4位表示一个位置 } for (i = 0; i < scrtkey.Length; i++) { uniscrtkey = uniscrtkey + (int)(scrtkey [i]); } string flag = "+"; posstr = trimIntZero(posstr); string sub = bgnusub(uniscrtkey, posstr); if (!string.IsNullOrEmpty(sub) && sub.Length > 0 && sub [0] == '-') { sub = StrEx.Mid(sub, 1); flag = "-"; } //每四位中把前面为0的用+号代表 string enSub = ""; int tmpN = 0; for (i = sub.Length - 4; i >= 0; i = i - 4) { tmpN = NumEx.stringToInt(StrEx.Mid(sub, i, 4)); enSub = (tmpN.ToString().Length < 4 ? "+" : "") + tmpN + enSub; } if (i != -4) { tmpN = NumEx.stringToInt(StrEx.Left(sub, i + 4)); enSub = (tmpN.ToString().Length < 4 ? "+" : "") + tmpN + enSub; } ret = unicodestr + flag + enSub; return(ret); }
public bool checkNeedDownload(string path) { if (string.IsNullOrEmpty(path)) { return(false); } bool ret = false; if (localPriorityVer[path] != null) { //在优先资源里有 ret = false; } else { //则可能在others里 object obj1 = otherResVerOld[path]; object obj2 = otherResVerNew[path]; if (obj1 == null && obj2 != null) { //本地没有,最新有 ret = true; } else if (obj1 != null && obj2 != null) { if (NumEx.stringToInt(obj1.ToString()) >= NumEx.stringToInt(obj2.ToString())) {//本地是最新的 ret = false; } else { //本地不是最新的 ret = true; } } else if (obj1 != null && obj2 == null) {//本地有,最新没有 ret = false; } else { //都没有找到 // NAlertTxt.add("Cannot Found the res. Path= \n"+ path, Color.red, 1); Debug.LogError("Cannot Found the res. Path= \n" + path); ret = true; } } // if (ret) { // if (!Utl.netIsActived ()) { // NAlertTxt.add (Localization.Get ("MsgNetWorkCannotReached"), Color.red, 1); // reLoadGame (); // } // } return(ret); }
/// <summary> /// Sets the action. /// </summary> /// <param name="actionValue">Action value.动作对应的value</param> /// <param name="callbackInfor">Callback infor. 是一个key:value的键值对 /// key:是0~100的整数,表示动作播放到百分之多少时执行回调, /// 而回调方法就是该key所对应的value /// </param> public void doSetActionWithCallback(int actionValue, ArrayList progressCallbackInfor) { // if (currActionValue == actionValue) { // return; // } ////////////////////////////////////////////////////////////////// progressPoints.Clear(); progressCallback.Clear(); callbackMap.Clear(); if (progressCallbackInfor != null) { int count = progressCallbackInfor.Count; for (int i = 0; i < count; i++) { if (i % 2 == 0) { progressPoints.Add(NumEx.stringToInt(progressCallbackInfor [i].ToString()) / 100.0f); } else { progressCallback.Add(progressCallbackInfor [i]); } } progressCallbackInfor.Clear(); progressCallbackInfor = null; } ////////////////////////////////////////////////////////////////// currActionValue = actionValue; currAction = (Action)(Enum.ToObject(typeof(Action), actionValue)); if (!animator.isInitialized) { return; } animator.SetInteger("Action", actionValue); if (progressPoints.Count > 0) { progressIndex = 0; isCheckProgress = true; // place the code after setAction, beacuse in setAction function ,set isCheckProgress = false; } else { isCheckProgress = false; } }
public static byte[] post2(string host, int port, string path, byte[] buf, int timeout) { TcpClient client = new TcpClient(); client.SendTimeout = timeout; client.ReceiveTimeout = timeout; client.Connect(host, port); // create request post data //const string POST_HEAD = "POST /{0} HTTP/1.1\r\nHost: {1}:{2}\r\nContent-Type: text/html;\r\nContent-Length: {3:G} \r\n\r\n"; string str = string.Format(POST_HEAD, path, host, port, buf.Length); byte[] headBytes = System.Text.Encoding.Default.GetBytes(str); // send request data NetworkStream ns = client.GetStream(); ns.Write(headBytes, 0, headBytes.Length); ns.Write(buf, 0, buf.Length); ns.Flush(); // read http header int length = 0; for (int n = 0; n < 100; n++) { string line = readLine(ns); bool isLen = line.StartsWith("Content-Length"); if (isLen) { string sub = line.Substring(line.IndexOf(":") + 1); length = NumEx.stringToInt(sub); } if (line == null || line.Length <= 1) { break; } } // read response body byte[] r2 = new byte[length]; ns.Read(r2, 0, length); ns.Close(); client.Close(); return(r2); }
public static void onGetSprite(params object[] paras) { UISprite sprite = (UISprite)(paras [0]); if (sprite == null || sprite.atlas == null) { return; } string sprName = paras [1].ToString(); sprite.spriteName = sprName; UISpriteData sd = sprite.atlas.getSpriteBorrowMode(sprite.spriteName); if (sd == null) { return; } int maxSize = NumEx.stringToInt(paras [2].ToString()); if (maxSize > 0) { if (sd == null) { return; } float x = (float)(sd.width); float y = (float)(sd.height); float size = x > y ? x : y; float rate = 1; if (size > maxSize) { rate = maxSize / size; } // sprite.MakePixelPerfect(); sprite.SetDimensions((int)(sd.width * rate), (int)(sd.height * rate)); } else { sprite.SetDimensions(sd.width, sd.height); } }
public static int[] ipv4(string ipv4) { int[] r2 = new int[4]; if (ipv4 == null || ipv4.Length < 7 || ipv4.Length > 17) { return(r2); } // 127.0.0.1 int p1 = ipv4.IndexOf('.'); if (p1 < 1) { return(r2); } int p2 = ipv4.IndexOf('.', p1 + 1); if (p2 < 1) { return(r2); } int p3 = ipv4.IndexOf('.', p2 + 1); if (p3 < 1) { return(r2); } string s1 = Mid(ipv4, 0, p1); string s2 = Mid(ipv4, p1 + 1, p2); string s3 = Mid(ipv4, p2 + 1, p3); string s4 = Mid(ipv4, p3 + 1, ipv4.Length); r2 [0] = NumEx.stringToInt(s1); r2 [1] = NumEx.stringToInt(s2); r2 [2] = NumEx.stringToInt(s3); r2 [3] = NumEx.stringToInt(s4); return(r2); }
/// <summary> /// Bignumberadditive the specified nu1 and nu2. /// 大数相加,以4位长的数字分段计算两个参数是不代符号的 /// </summary> /// <param name='nu1'> /// Nu1. /// </param> /// <param name='nu2'> /// Nu2. /// </param> static string bignumberadditive(string nu1, string nu2) { string result = ""; string a = ""; string b = ""; int sizea = 0; int sizeb = 0; string tmpstr; int i = 0; a = nu1; b = nu2; if (a.Length < b.Length) { tmpstr = a; a = b; b = tmpstr; } if (a.Length % 4 == 0) { sizea = a.Length / 4; } else { sizea = a.Length / 4 + 1; } if (b.Length % 4 == 0) { sizeb = b.Length / 4; } else { sizeb = b.Length / 4 + 1; } string[] lista = new string[sizea]; string[] tmpresult = new string[sizea]; string[] listb = new string[sizeb]; for (i = 0; i < sizea; i++) { if (a.Length > 4) { lista[i] = StrEx.Right(a, 4); a = StrEx.Left(a, a.Length - 4); } else { lista[i] = StrEx.Right(a, a.Length); a = StrEx.Left(a, a.Length); } } for (i = 0; i < sizeb; i++) { if (b.Length > 4) { listb[i] = StrEx.Right(b, 4); b = StrEx.Left(b, b.Length - 4); } else { listb[i] = StrEx.Right(b, b.Length); b = StrEx.Left(b, b.Length); } } for (i = 0; i < sizea; i++) { if (i < sizeb) { tmpresult[i] = (NumEx.stringToInt(lista[i]) + NumEx.stringToInt(listb[i])).ToString(); } else { tmpresult[i] = lista[i]; } if (i != 0) { if ((tmpresult[i - 1]).Length == 5) { tmpresult[i] = (NumEx.stringToInt(tmpresult[i]) + 1).ToString(); } } if (i != sizea - 1) { int tmpN = 0; if (tmpresult[i].Length >= 4) { tmpN = NumEx.stringToInt(StrEx.Right(tmpresult[i], 4)); } else { tmpN = NumEx.stringToInt(tmpresult[i]); } result = NumEx.nStrForLen(tmpN, 4) + result; } else { result = tmpresult[i] + result; } } return(result); }
/// <summary> /// Bignumbersubduct the specified nu1 and nu2. /// 大数相减,以4位长的数字分段计算 /// 两个参数是不代符号的 /// </summary> /// <param name='nu1'> /// Nu1. /// </param> /// <param name='nu2'> /// Nu2. /// </param> static string bignumbersubduct(string nu1, string nu2) { string result = ""; string a; string b; string tmpstr; int sizea = 0; int sizeb = 0; int i = 0; string flag = ""; a = nu1; b = nu2; if (a.Length < b.Length) { tmpstr = a; a = b; b = tmpstr; flag = "-"; } else if (a.Length == b.Length) { if (a.CompareTo(b) == -1) { tmpstr = a; a = b; b = tmpstr; flag = "-"; } } if (a.Length % 4 == 0) { sizea = a.Length / 4; } else { sizea = a.Length / 4 + 1; } if (b.Length % 4 == 0) { sizeb = b.Length / 4; } else { sizeb = b.Length / 4 + 1; } string[] lista = new string[sizea]; string[] tmpresult = new string[sizea]; string[] listb = new string[sizeb]; for (i = 0; i < sizea; i++) { if (a.Length > 4) { lista[i] = StrEx.Right(a, 4); a = StrEx.Left(a, a.Length - 4); } else { lista[i] = StrEx.Right(a, a.Length); a = StrEx.Left(a, a.Length); } } for (i = 0; i < sizeb; i++) { if (b.Length > 4) { listb[i] = StrEx.Right(b, 4); b = StrEx.Left(b, b.Length - 4); } else { listb[i] = StrEx.Right(b, b.Length); b = StrEx.Left(b, b.Length); } } for (i = 0; i < sizea; i++) { if (i < sizeb) { if (i != sizea - 1) { tmpresult[i] = (NumEx.stringToInt("1" + lista[i]) - NumEx.stringToInt(listb[i])).ToString(); } else { tmpresult[i] = (NumEx.stringToInt(lista[i]) - NumEx.stringToInt(listb[i])).ToString(); } } else { if (i != sizea - 1) { tmpresult[i] = "1" + lista[i]; } else { tmpresult[i] = lista[i]; } } if (i != 0) { if (tmpresult[i - 1].Length < 5) { tmpresult[i] = (NumEx.stringToInt(tmpresult[i]) - 1).ToString(); } } if (i != sizea - 1) { int tempN = 0; if (tmpresult[i].Length >= 4) { tempN = NumEx.stringToInt(StrEx.Right(tmpresult[i], 4)); } else { tempN = NumEx.stringToInt(tmpresult[i]); } result = NumEx.nStrForLen(tempN, 4) + result; } else { result = tmpresult[i] + result; } } result = flag + result; return(result); }
// void LateUpdate () void Update() { if (itemList.Count < 3) { return; } sourceIndex = -1; targetIndex = -1; // sign = 0; head = itemList [0]; tail = itemList [itemList.Count - 1]; checkHead = itemList [1]; checkTail = itemList [itemList.Count - 2]; firstVislable = checkHead.widget.isVisible; lastVisiable = checkTail.widget.isVisible; // if first and last both visiable or invisiable then return if (firstVislable == lastVisiable) { return; } if (firstVislable && int.Parse(head.name) > 0) { isCanCallOnEndList = true; times--; // move last to first one sourceIndex = itemList.Count - 1; targetIndex = 0; forward = false; } else if (lastVisiable && int.Parse(tail.name) < list.Count - 1) { isCanCallOnEndList = true; times++; // move first to last one sourceIndex = 0; targetIndex = itemList.Count - 1; forward = true; } else if (lastVisiable && int.Parse(tail.name) == list.Count - 1) { //说明已经到最后了 if (isCanCallOnEndList) { isCanCallOnEndList = false; #if UNITY_EDITOR Debug.Log("说明已经到最后了"); #endif Utl.doCallback(this.onEndListCallback); } } else { isCanCallOnEndList = true; } if (sourceIndex > -1) { movedWidget = itemList [sourceIndex]; if (forward) { // movedWidget.name = string.Format ("{0:D5}",); movedWidget.name = NumEx.nStrForLen(NumEx.stringToInt(tail.name) + 1, 6); // movedWidget.name = NumEx.nStrForLen( ((times - 1) / RealCellCount + 1) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6); } else { movedWidget.name = NumEx.nStrForLen(NumEx.stringToInt(head.name) - 1, 6); // movedWidget.name = string.Format ("{0:D5}", ((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount); // movedWidget.name = NumEx.nStrForLen(((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6); } int index = int.Parse(movedWidget.name); Utl.doCallback(this.initCellCallback, movedWidget.GetComponent <CLCellBase> (), this.list [index]); // ***after init call, then set the position*** if (movedWidget.isSetWidgetSize) { _boxCollidr = movedWidget.GetComponent <BoxCollider> (); if (_boxCollidr != null) { _boxCollidr.size = Vector2.zero; } movedWidget.widget.SetDimensions(0, 0); } NGUITools.updateAll(movedWidget.transform); if (movedWidget.isSetWidgetSize) { _bound = NGUIMath.CalculateRelativeWidgetBounds(movedWidget.transform, false); movedWidget.widget.SetDimensions((int)(_bound.size.x), (int)(_bound.size.y)); } targetWidget = itemList [targetIndex]; if (forward) { setPosition(movedWidget, targetWidget, table.direction); } else { UITable.Direction dir = table.direction; if (table.direction == UITable.Direction.Up) { dir = UITable.Direction.Down; } else { dir = UITable.Direction.Up; } setPosition(movedWidget, targetWidget, dir); } // change item index itemList.RemoveAt(sourceIndex); itemList.Insert(targetIndex, movedWidget); } }
/// <summary> /// Decoder the specified encodestr and scrtkey.解密 /// </summary> /// <param name='encodestr'>要解密的串 /// Encodestr. /// </param> /// <param name='scrtkey'>密钥secretkey /// Scrtkey. /// </param> public static string decoder(string encodestr, string scrtkey) { if (string.IsNullOrEmpty(encodestr) || string.IsNullOrEmpty(scrtkey)) { return(""); } string result = ""; string unicodestr = ""; string posstr = ""; string tmpstr = ""; string uniscrtkey = ""; int sizepos = 0; int i = 0; char splitChar = '-'; int splitPos = encodestr.IndexOf('-'); if (splitPos < 0) { splitChar = '+'; splitPos = encodestr.IndexOf('+'); } if (splitPos < 0) { return(""); } unicodestr = StrEx.Left(encodestr, splitPos); posstr = StrEx.Right(encodestr, encodestr.Length - splitPos - 1); string[] ss = posstr.Split('+'); posstr = ""; for (i = 0; i < ss.Length; i++) { int j = 0; tmpstr = ""; for (j = ss [i].Length - 4; j >= 0; j = j - 4) { tmpstr = StrEx.Mid(ss [i], j, 4) + tmpstr; } if (j != -4) { int tmpN = NumEx.stringToInt(StrEx.Mid(ss [i], 0, j + 4)); tmpstr = NumEx.nStrForLen(tmpN, 4) + tmpstr; } posstr += tmpstr; } //去掉面前的0 posstr = trimIntZero(posstr); if (splitChar == '-') { posstr = "-" + posstr; } for (i = 0; i < scrtkey.Length; i++) { uniscrtkey = uniscrtkey + (int)(scrtkey [i]); } posstr = bgnusub(uniscrtkey, posstr); if (posstr.Length % 4 == 0) { sizepos = posstr.Length / 4; } else { sizepos = posstr.Length / 4 + 1; } int[] poslist = new int[sizepos]; for (i = 0; i < sizepos; i++) { int tmpN = 0; if (posstr.Length >= 4) { tmpN = NumEx.stringToInt(StrEx.Right(posstr, 4)); } else { tmpN = NumEx.stringToInt(posstr); } if (tmpN == 0) { break; } poslist [i] = tmpN; if (posstr.Length > 4) { posstr = StrEx.Left(posstr, posstr.Length - 4); } } sizepos = i; for (i = 0; i < sizepos; i++) { unicodestr = StrEx.Left(unicodestr, poslist [i]) + StrEx.Mid(unicodestr, 0, 1) + StrEx.Mid(unicodestr, poslist [i]); unicodestr = StrEx.Mid(unicodestr, 1); } for (i = 0; i < sizepos; i++) { if (i != sizepos - 1) { result = (char)(NumEx.stringToInt(StrEx.Mid(unicodestr, poslist [i + 1], poslist [i] - poslist [i + 1]))) + result; } else { result = (char)(NumEx.stringToInt(StrEx.Mid(unicodestr, 0, poslist [i]))) + result; } } return(result); }