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> /// 获取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); } }
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); }
/// <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); } }
/// <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 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); }
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 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 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); }
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> /// 获取指定的xml节点的节点路径 /// </summary> /// <param name="element"></param> static string GetXElementNodePath(XElement element) { if (element == null) { return(null); } try { string path = element.Name.ToString(); element = element.Parent; while (null != element) { path = element.Name.ToString() + "/" + path; element = element.Parent; } return(path); } catch (Exception e) { DebugMod.LogError(e.Message); } return(null); }
/// <summary> /// 获取属性值 /// </summary> /// <param name="XElement"></param> /// <param name="attribute"></param> /// <returns></returns> public static XAttribute GetAttribute(XElement XElement, string attribute) { if (null == XElement) { return(null); } try { XAttribute attrib = XElement.Attribute(attribute); if (null == attrib) { DebugMod.LogError(new Exception(string.Format("读取属性: {0} 失败, xml节点名: {1}", attribute, GetXElementNodePath(XElement)))); return(null); } return(attrib); } catch { DebugMod.LogError(new Exception(string.Format("读取属性: {0} 失败, xml节点名: {1}", attribute, GetXElementNodePath(XElement)))); return(null); } }
void ResponseCallback(IAsyncResult ar) { HttpWebRequest req = ar.AsyncState as HttpWebRequest; if (req == null) { return; } HttpWebResponse resp = req.EndGetResponse(ar) as HttpWebResponse; if (resp.StatusCode != HttpStatusCode.OK) { resp.Close(); DebugMod.LogError("http error:" + resp.StatusCode); return; } WebReqState st = new WebReqState(m_SavePath); st.m_WebResponse = resp; Stream responseStream = resp.GetResponseStream(); st.m_OrginalStream = responseStream; responseStream.BeginRead(st.m_Buffer, 0, WebReqState.m_BufferSize, new AsyncCallback(ReadDataCallback), st); }
/// <summary> /// 加载读取csv文件 /// </summary> public bool LoadCsvFile() { if (String.IsNullOrEmpty(this.csvFilePath)) { //csv文件路径不存在 DebugMod.LogError(new Exception(string.Format("csv文件路径不存在, csv文件路径:{0}", this.csvFilePath))); return(false); } else if (!File.Exists(this.csvFilePath)) { //csv文件不存在 DebugMod.LogError(new Exception(string.Format("csv文件不存在, csv文件路径:{0}", this.csvFilePath))); return(false); } if (null == this.encoding) { this.encoding = Encoding.Default; } StreamReader sr = new StreamReader(this.csvFilePath, this.encoding); string csvInfoNameDataLine = sr.ReadLine(); if (String.IsNullOrEmpty(csvInfoNameDataLine)) //表示此文件为空 { DebugMod.LogError(new Exception(string.Format("此csv文件为空, csv文件路径:{0}", this.csvFilePath))); sr.Close(); return(false); } ParseCsvInfoName(csvInfoNameDataLine); //从csv文件中解析出信息的名称 string csvDataLine = ""; //表示一行csv文件数据 while (true) { string fileDataLine; //表示读取出的一行数据 fileDataLine = sr.ReadLine(); if (String.IsNullOrEmpty(fileDataLine)) //表示读取到了文件结尾,跳出循环 { break; } if ("" == csvDataLine) { csvDataLine = fileDataLine; } else { csvDataLine += "\r\n" + fileDataLine; } if (!IfOddQuotation(csvDataLine)) //此时csvDataLine中包含偶数个引号,表示是完整的一行csv数据,如果csvDataLine中包含奇数个引号,表示不是完整的一行csv数据,数据被回车换行符分割。 { AddNewDataLine(csvDataLine); csvDataLine = ""; } } sr.Close(); if (csvDataLine.Length > 0) //在读取玩全部csv数据后,如果csvDataLine中仍然存在数据,表示数据中出现了奇数个引号,csv文件格式错误。 { //csv文件格式错误 DebugMod.LogError(new Exception(string.Format("csv文件格式错误, csv文件路径:{0}", this.csvFilePath))); return(false); } return(true); }