public ActionBase CreateAction(object actionType) { ActionBase action = null; try { string name = string.Format(ActionFormat(), actionType); var type = (Type)lookupType[name]; lock (lookupType) { if (type == null) { if (null != ActionAssembly) { type = ActionAssembly.GetType(name); if (null != type) { lookupType[name] = type; } } } } if (type != null) { //action.ActionId = name; //action = Activator.CreateInstance(type) as ActionBase; //action = FastActivator.Create(type) as ActionBase; } } catch (Exception ex) { DebugMod.LogError("action create error:" + ex); } return(action); }
/// <summary> /// 获得csvmod加载的文件内容,并按照“前后名id”,放到NameContainer的各自的List中(0->只做前名,1->只做后名,2->前后名都可以做) /// NameContainer< <0, <前名...> > , <1, <后名...> , <2 ,<前/后...> > > /// </summary> private void InitNameDictionary() { if (0 == (tempList = csvmod.GetAllData()).Count)//若是没加载Name.csv文件,先加载. { if (!csvmod.LoadCsvStr()) { DebugMod.Log("Load NameFile Failed!"); } else { for (int index = 0; index < tempList.Count; index++) { int nameId = int.Parse(tempList[index]["前后代号"]); //前后代号:各种名字的id string name = tempList[index]["备用名字"]; // 代号对应的名字 if (NameContainer.ContainsKey(nameId)) { NameContainer[nameId].Add(name); } else { NameContainer.Add(nameId, new List <string>()); } } } } }
public static void ThreadProc(object param) { try { DebugMod.Log("Logic Thread Start."); GameMain frame = param as GameMain; long prevTick = DateTime.Now.Ticks; if (null != param) { while (!m_AppExit) { long nowTick = DateTime.Now.Ticks; long elapseTick = nowTick - prevTick; if (elapseTick > 333333) //33ms { prevTick = nowTick; frame.OnThreadUpdate(); } } } DebugMod.Log("Logic Thread Exit."); } catch (Exception ex) { DebugMod.LogException(ex); } }
/// <summary> /// 将日期时间字符串转为整数表示 /// </summary> /// <param name="str"></param> /// <returns></returns> public static long ConvertToTicks(string str, long defVal) { if ("*" == str) { return(defVal); } str = str.Replace('$', ':'); try { DateTime dt; if (!DateTime.TryParse(str, out dt)) { return(0L); } return(dt.Ticks / 10000); } catch (Exception e) { DebugMod.LogException(e); } return(0L); }
public static List <int> GetXElementAttributeIntList(XElement xElement, string attributeName, string newroot = null) { List <int> result = new List <int>(); if (xElement != null) { IEnumerable <XElement> xmlItems = null; if (null == newroot) { xmlItems = xElement.Elements(); } else { xmlItems = xElement.DescendantsAndSelf(newroot); } if (xmlItems != null) { foreach (var xmlItem in xmlItems) { result.Add(GetXElementAttributeInt(xmlItem, attributeName)); } } } else { DebugMod.LogError(new Exception(string.Format("GetXElement异常, 读取: {0} 失败, xml节点名: {1}", newroot, GetXElementNodePath(xElement)))); } return(result); }
public void DownloadFile() { DebugMod.Log("asyDownload:" + m_Url); HttpWebRequest httpRequest = WebRequest.Create(m_Url) as HttpWebRequest; httpRequest.BeginGetResponse(new AsyncCallback(ResponseCallback), httpRequest); }
/// <summary> /// 获取XElement文件树节点段XElement的列表 /// </summary> /// <param name="XElement">XElement文件载体</param> /// <param name="newroot">要查找的独立节点</param> /// <returns>XElement列表</returns> public static List <XElement> GetXElementList(XElement xElement, string newroot = null) { List <XElement> xmlItemList = new List <XElement>(); if (xElement != null) { IEnumerable <XElement> xmlItems = null; if (null == newroot) { xmlItems = xElement.Elements(); } else { xmlItems = xElement.DescendantsAndSelf(newroot); } if (xmlItems != null) { foreach (var xmlItem in xmlItems) { xmlItemList.Insert(xmlItemList.Count, xmlItem); } } } else { DebugMod.LogError(new Exception(string.Format("GetXElement异常, 读取: {0} 失败, xml节点名: {1}", newroot, GetXElementNodePath(xElement)))); } return(xmlItemList); }
/// <summary> /// 安全获取xml整型数值 /// </summary> /// <param name="XElement"></param> /// <param name="attributeName"></param> /// <returns></returns> public static float GetXElementAttributeFloat(XElement XElement, string attributeName) { XAttribute attrib = GetAttribute(XElement, attributeName); if (null == attrib) { return(-1.0f); } string str = (string)attrib; if (null == str || str == "") { return(-1.0f); } float nReturn = 0.0f; if (float.TryParse(str, out nReturn)) { return(nReturn); } else { DebugMod.LogError(string.Format("读取属性: {0} 失败, xml节点名: {1}", attributeName, GetXElementNodePath(XElement))); return(-1.0f); } }
private void DequueLogicAction() { try { LogicAction action = null; do { action = null; lock (m_QueueLogicAction) { if (0 < m_QueueLogicAction.Count) { action = m_QueueLogicAction.Dequeue();//移除并返回栈顶数据 } } if (null != action) { action.ProcessAction(); } } while (action != null); } catch (Exception ex) { DebugMod.LogException(ex); } }
/// <summary> /// 获取XElement文件树节点段XElement /// </summary> /// <param name="xml">XElement文件载体</param> /// <param name="mainnode">要查找的主节点</param> /// <param name="attribute1">主节点条件属性名1</param> /// <param name="value1">主节点条件属性值1</param> /// <param name="attribute2">主节点条件属性名2</param> /// <param name="value2">主节点条件属性值2</param> /// <returns>以该主节点为根的XElement</returns> public static XElement GetXElement(XElement XElement, string newroot, string attribute1, string value1, string attribute2, string value2) { if (XElement != null) { IEnumerable <XElement> xmlItems = XElement.DescendantsAndSelf(newroot); foreach (var xmlItem in xmlItems) { XAttribute attrib1 = xmlItem.Attribute(attribute1); XAttribute attrib2 = xmlItem.Attribute(attribute2); if (null != attrib1 && attrib1.Value == value1) { if (null != attrib2 && attrib2.Value == value2) { return(xmlItem); } } } return(null); } else { DebugMod.LogError(new Exception(string.Format("GetXElement异常, 读取: {0}/{1}={2}/{3}={4} 失败, xml节点名: {5}", newroot, attribute1, value1, attribute2, value2, GetXElementNodePath(XElement)))); return(null); } }
public static void LogException(Exception e, string extMsg, bool showMsgBox) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("应用程序出现了异常:\r\n{0}\r\n", e.Message); stringBuilder.AppendFormat("\r\n 额外信息: {0}", extMsg); if (null != e) { if (e.InnerException != null) { stringBuilder.AppendFormat("\r\n {0}", e.InnerException.Message); } stringBuilder.AppendFormat("\r\n {0}", e.StackTrace); } //记录异常日志文件 //LogManager.WriteException(stringBuilder.ToString()); if (showMsgBox) { //弹出异常日志窗口 System.Console.WriteLine(stringBuilder.ToString()); } } catch (Exception ex) { DebugMod.LogException(ex); } }
public static GameObject FindChild(Transform transform, string childname, bool lowercompare = true) { if (null == transform) { DebugMod.LogError("transform is null in FindChild"); return(null); } int totalChildCount = transform.childCount; for (int i = 0; i < totalChildCount; i++) { string name = transform.GetChild(i).gameObject.name; if ((lowercompare ? name.ToLowerInvariant() : name) == childname.ToLowerInvariant()) { return(transform.GetChild(i).gameObject); } } for (int i = 0; i < totalChildCount; i++) { GameObject go = FindChild(transform.GetChild(i), childname); if (null != go) { return(go); } } return(null); }
/// <summary> /// 获取XElement文件树节点段XElement /// </summary> /// <param name="xml">XElement文件载体</param> /// <param name="mainnode">要查找的主节点</param> /// <param name="attribute">主节点条件属性名</param> /// <param name="value">主节点条件属性值</param> /// <returns>以该主节点为根的XElement</returns> public static XElement GetXElement(XElement XElement, string newroot, string attribute, string value) { if (XElement != null) { IEnumerable <XElement> xmlItems = XElement.DescendantsAndSelf(newroot); if (xmlItems != null) { foreach (var xmlItem in xmlItems) { XAttribute attrib = null; if (xmlItem != null) { attrib = xmlItem.Attribute(attribute); } if (null != attrib && attrib.Value == value) { return(xmlItem); } } } return(null); } else { DebugMod.LogError(new Exception(string.Format("GetXElement异常, 读取: {0}/{1}={2} 失败, xml节点名: {3}", newroot, attribute, value, GetXElementNodePath(XElement)))); return(null); } }
/// <summary> /// 输入明文和密钥,输出密文 /// </summary> /// <param name="plainText"></param> /// <param name="key"></param> /// <returns></returns> public static string Encrypt(string plainText, string passwd, string saltValue) { if (string.IsNullOrEmpty(plainText)) { return(null); } byte[] bytesData = null; try { bytesData = new UTF8Encoding().GetBytes(plainText); } catch (Exception e) { DebugMod.LogException(e); return(null); } byte[] bytesResult = null; try { bytesResult = AesHelper.AesEncryptBytes(bytesData, passwd, saltValue); } catch (Exception e) { DebugMod.LogException(e); return(null); } return(ByteHelper.Bytes2HexString(bytesResult)); }
public static T Clone <T>(Object sample) where T : Object { if (sample == null) { DebugMod.LogError("sample is null in:" + MethodBase.GetCurrentMethod().Name); return(null); } return(GameObject.Instantiate(sample) as T); }
public static void AddChild(Object parent, Object child, bool usechildoriginaltransform = false) { if (child == null) { DebugMod.LogError("child is null in:" + MethodBase.GetCurrentMethod().Name); return; } Transform prt = null; Transform cld = null; if (parent != null) { if (parent is GameObject) { prt = ((GameObject)parent).transform; } else if (parent is Transform) { prt = (Transform)parent; } else { DebugMod.LogError("parent type is unknown in:" + MethodBase.GetCurrentMethod().Name); } } if (child is GameObject) { cld = ((GameObject)child).transform; } else if (child is Transform) { cld = (Transform)child; } else { DebugMod.LogError("child type is unknown in:" + MethodBase.GetCurrentMethod().Name); } if (prt == null || cld == null) { return; } Vector3 localpos = cld.localPosition; Quaternion localrot = cld.localRotation; Vector3 localscl = cld.localScale; cld.parent = prt; cld.localPosition = usechildoriginaltransform ? localpos : Vector3.zero; cld.localRotation = usechildoriginaltransform ? localrot : Quaternion.identity; cld.localScale = usechildoriginaltransform ? localscl : Vector3.one; }
/// <summary> /// 加载读取csv字符串 /// </summary> public bool LoadCsvStr() { if (String.IsNullOrEmpty(this.csvStr)) { //csv文件路径不存在 DebugMod.LogError(new Exception(string.Format("csv信息为空"))); return(false); } string[] csvInfoArray = csvStr.Split(new string[] { "\r\n" }, StringSplitOptions.None); string csvInfoNameDataLine = csvInfoArray[0]; ParseCsvInfoName(csvInfoNameDataLine); //从csv文件中解析出信息的名称 string csvDataLine = ""; //表示一行csv文件数据 for (int i = 1; i < csvInfoArray.Length; ++i) { string fileDataLine; //表示读取出的一行数据 fileDataLine = csvInfoArray[i]; if (String.IsNullOrEmpty(fileDataLine)) //表示读取到了文件结尾,跳出循环 { break; } if ("" == csvDataLine) { csvDataLine = fileDataLine; } else { csvDataLine += "\r\n" + fileDataLine; } if (!IfOddQuotation(csvDataLine)) //此时csvDataLine中包含偶数个引号,表示是完整的一行csv数据,如果csvDataLine中包含奇数个引号,表示不是完整的一行csv数据,数据被回车换行符分割。 { AddNewDataLine(csvDataLine); csvDataLine = ""; } } if (csvDataLine.Length > 0) //在读取玩全部csv数据后,如果csvDataLine中仍然存在数据,表示数据中出现了奇数个引号,csv文件格式错误。 { //csv文件格式错误 DebugMod.LogError(new Exception(string.Format("csv文件格式错误"))); return(false); } return(true); }
public void OnThreadUpdate() { try { DequueLogicAction(); m_FrmworkThreader.Update(); } catch (Exception ex) { DebugMod.LogException(ex); } }
public static T GetComponent <T>(GameObject go) where T : Component { if (go == null) { DebugMod.LogError("gameobject is null"); } T t = go.GetComponent <T>(); if (t == null) { t = go.AddComponent <T>(); } return(t); }
public int PutData(byte[] byteData, int offset, int len) { if (len <= 0 || len > _maxLen) { //PRINT("CCircularBuffer::PutData len is <=0\n"); return(0); } while (IsOverFlowCondition(len)) { BufferResize(); } m_nValidCount += len; try { if (IsIndexOverFlow(len)) { int FirstCopyLen = m_iBufSize - m_iTailPos; int SecondCopyLen = len - FirstCopyLen; Tools.Assert.Check(FirstCopyLen > 0); Array.Copy(byteData, offset, m_Buffer, m_iTailPos, FirstCopyLen); if (SecondCopyLen > 0) { Array.Copy(byteData, offset + FirstCopyLen, m_Buffer, 0, SecondCopyLen); m_iTailPos = SecondCopyLen; } else { m_iTailPos = 0; } } else { Array.Copy(byteData, offset, m_Buffer, m_iTailPos, len); m_iTailPos += len; } } catch (Exception e) { DebugMod.LogException(e, "CircleBuffer.PutData", false); } return(len); }
public void Init() { try { //创建逻辑线程 DebugMod.Log("GameMain Init"); OutLog.Instance.InitLog(); //Thread t = new Thread(new ParameterizedThreadStart(ThreadProc)); //t.Start(this); //Thread.Sleep(0); LogicActionFactory.Instance.ActionAssembly = System.Reflection.Assembly.GetCallingAssembly(); BattleManager.Instance.Init(); } catch (Exception ex) { DebugMod.LogException(ex); } }
public static T Load <T>(string path) where T : Object { if (!Instance.mCacheDic.ContainsKey(path)) { T res = Resources.Load <T>(path); if (res == null) { DebugMod.LogError("can't find res from " + path); return(null); } Instance.mCacheDic[path] = new ResCache() { resCache = (Object)res }; } return(Instance.mCacheDic[path].resCache as T); }
/// <summary> /// 格式化堆栈信息 /// </summary> /// <param name="msg"></param> /// <returns></returns> public static void LogFormatStack(System.Diagnostics.StackTrace stackTrace, string extMsg) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("应用程序出现了对象锁定超时错误:\r\n"); stringBuilder.AppendFormat("\r\n 额外信息: {0}", extMsg); stringBuilder.AppendFormat("\r\n {0}", stackTrace.ToString()); //记录异常日志文件 //LogManager.WriteException(stringBuilder.ToString()); } catch (Exception e) { DebugMod.LogException(e); } }
/// <summary> /// 判断如果不是 "*", 则转为指定的值, 否则默认值 /// </summary> /// <param name="str"></param> /// <returns></returns> public static Int32 ConvertToInt32(string str, Int32 defVal) { try { if ("*" != str) { return(Convert.ToInt32(str)); } return(defVal); } catch (Exception e) { DebugMod.LogException(e); } return(defVal); }
/// <summary> /// 将日期时间字符串转为整数表示 /// </summary> /// <param name="str"></param> /// <returns></returns> public static long ConvertToTicks(string str) { try { DateTime dt; if (!DateTime.TryParse(str, out dt)) { return(0L); } return(dt.Ticks / 10000); } catch (Exception e) { DebugMod.LogException(e); } return(0L); }
public void Init() { GlobalObject = gameObject; try { //创建逻辑线程 DebugMod.Log("GameMain Init"); LuaScriptMgr.Instance.Init(); LuaScriptMgr.Instance.InitStart(); //Thread t = new Thread(new ParameterizedThreadStart(ThreadProc)); //t.Start(this); //Thread.Sleep(0); NetActionFactory.Instance.ActionAssembly = System.Reflection.Assembly.GetCallingAssembly(); } catch (Exception ex) { DebugMod.LogException(ex); } }
void ReadDataCallback(IAsyncResult ar) { WebReqState rs = ar.AsyncState as WebReqState; int read = rs.m_OrginalStream.EndRead(ar); if (read > 0) { rs.m_FileStream.Write(rs.m_Buffer, 0, read); rs.m_FileStream.Flush(); rs.m_OrginalStream.BeginRead(rs.m_Buffer, 0, WebReqState.m_BufferSize, new AsyncCallback(ReadDataCallback), rs); } else { rs.m_FileStream.Close(); rs.m_OrginalStream.Close(); rs.m_WebResponse.Close(); DebugMod.Log("http download url finish" + m_Url); } }
public static void Trigger <T>(T e) where T : EventArgs { Delegate del; if (Instance.mEventDic.TryGetValue(typeof(T), out del)) { EventDelegate <T> callback = del as EventDelegate <T>; try { if (callback != null) { callback(e); } } catch { DebugMod.LogError("Event Trigger error on:" + typeof(T).ToString()); } } }
/// <summary> /// 去掉数据块的首尾引号,一对双引号变为单个单引号 /// </summary> /// <param name="fileCellData"></param> /// <returns></returns> private string GetHandleData(string fileCellData) { if ("" == fileCellData) { return(""); } if (IfOddQuotationStart(fileCellData)) { if (IfOddQuotationEnd(fileCellData)) { return(fileCellData.Substring(1, fileCellData.Length - 2).Replace("\"\"", "\"")); //去掉数据块的首尾引号,一对双引号变为单个单引号 } else { DebugMod.LogError(new Exception(string.Format("csv数据引号无法匹配, 无法匹配数据:{0}", fileCellData))); } } return(fileCellData); }
/// <summary> /// 输入密文和密钥,输出明文 /// </summary> /// <param name="plainText"></param> /// <param name="key"></param> /// <returns></returns> public static string Decrypt(string encryptText, string passwd, string saltValue) { if (string.IsNullOrEmpty(encryptText)) { return(null); } byte[] bytesData = ByteHelper.HexString2Bytes(encryptText); if (null == bytesData) { return(null); } byte[] bytesResult = null; try { bytesResult = AesHelper.AesDecryptBytes(bytesData, passwd, saltValue); } catch (Exception e) { DebugMod.LogException(e); return(null); } string strResult = null; try { strResult = new UTF8Encoding().GetString(bytesResult, 0, bytesResult.Length); } //解析错误 catch (Exception e) { DebugMod.LogException(e); return(null); } return(strResult); }