/** * @brief 从Xml节点中读取布尔值 * * @param node xml节点 * @param nodeName 节点名字 * @param defualtVal 默认值 * @param isMust 是否强制不能为空 * * @return */ public static bool ExtractBool(DBC_Row node, string nodeName, bool defualtVal, bool isMust) { bool result = defualtVal; if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null) { return(result); } string nodeText = node.SelectFieldByName(nodeName); if (!CrossEngineHelper.StringIsNullOrEmpty(nodeText)) { if (nodeText.Trim().ToLower() == "true" || nodeText.Trim().ToLower() == "1") { result = true; } if (nodeText.Trim().ToLower() == "false" || nodeText.Trim().ToLower() == "0") { result = false; } } return(result); }
public static Assembly GetAssembly(string assemblyPath, string assemblyName, string className) { Assembly assembly = null; if (CrossEngineHelper.StringIsNullOrEmpty(assemblyPath)) { if (CrossEngineHelper.StringIsNullOrEmpty(assemblyName)) { assembly = Assembly.GetExecutingAssembly(); } else { assembly = Assembly.Load(assemblyName); } } else { assembly = Assembly.LoadFile(string.Format("[0][1].dll", assemblyPath, assemblyName)); } if (assembly == null) { LogSystem.Debug("Warn: KernelUtil.LoadClassByName Assembly load failed!"); } return(assembly); }
/** * @brief 从Xml节点中读取数值类型,使用时,必须在函数中指明数值类型 * 如: int id = ExtractNumeric<int>(xmlNode, "Id", -1, true); * * @param node xml节点 * @param nodeName 节点名字 * @param defualtVal 默认值 * @param isMust 是否强制不能为空 * * @return */ public static T ExtractNumeric <T>(DBC_Row node, string nodeName, T defualtVal, bool isMust) { T result = defualtVal; if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null) { return(result); } string nodeText = node.SelectFieldByName(nodeName); if (!CrossEngineHelper.StringIsNullOrEmpty(nodeText)) { try { result = (T)Convert.ChangeType(nodeText, typeof(T)); } catch (System.Exception ex) { string info = string.Format("ExtractNumeric Error node:{0} nodeName:{1} ex:{2} stacktrace:{3}", node.RowIndex, nodeName, ex.Message, ex.StackTrace); LogSystem.Debug(info); CrossEngineHelper.LogCallStack(); } } return(result); }
private bool GetEscapeTargetPos(NpcInfo npc, CharacterInfo target, float dis, float anglePlus, ref Vector3 escapePos) { Vector3 targetPos = Vector3.Zero; Vector3 sourcePos = npc.GetMovementStateInfo().GetPosition3D(); float angle = Geometry.GetYAngle(target.GetMovementStateInfo().GetPosition2D(), npc.GetMovementStateInfo().GetPosition2D()); angle += CrossEngineHelper.DegreeToRadian(anglePlus); targetPos.X = sourcePos.X + dis * (float)Math.Sin(angle); targetPos.Y = sourcePos.Y; targetPos.Z = sourcePos.Z + dis * (float)Math.Cos(angle); bool isFind = AiLogicUtility.GetWalkablePosition(npc.SpatialSystem.GetCellMapView(npc.AvoidanceRadius), targetPos, sourcePos, ref escapePos); return(isFind); }
/** * @brief 从Xml节点中读取字符串数组 * * @param node xml节点 * @param nodeName 节点名字 * @param defualtVal 默认值 * @param isMust 是否强制不能为空 * * @return */ public static List <string> ExtractStringList(DBC_Row node, string nodeName, string defualtVal, bool isMust) { List <string> result = new List <string>(); if (node == null || !node.HasFields) { return(result); } string nodeText = node.SelectFieldByName(nodeName); if (!CrossEngineHelper.StringIsNullOrEmpty(nodeText)) { result = Converter.ConvertStringList(nodeText); } return(result); }
/** * @brief 从Xml节点中读取字符串 * * @param node xml节点 * @param nodeName 节点名字 * @param defualtVal 默认值 * @param isMust 是否强制不能为空 * * @return */ public static string ExtractString(DBC_Row node, string nodeName, string defualtVal, bool isMust) { string result = defualtVal; if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null) { return(result); } string nodeText = node.SelectFieldByName(nodeName); if (!CrossEngineHelper.StringIsNullOrEmpty(nodeText)) { result = nodeText; } return(result); }
public static MemoryStream ReadFileAsMemoryStream(string filePath) { try { byte[] buffer = ReadFileAsArray(filePath); if (buffer == null) { LogSystem.Debug("Err ReadFileAsMemoryStream failed:{0}\n", filePath); return(null); } return(new MemoryStream(buffer)); } catch (Exception e) { LogSystem.Debug("Exception:{0}\n", e.Message); CrossEngineHelper.LogCallStack(); return(null); } }
public static bool Exists(string filePath) { try { if (handlerFileExists != null) { return(handlerFileExists(filePath)); } else { LogSystem.Debug("ReadFileByEngine handler have not register: {0}", filePath); return(false); } } catch (Exception e) { LogSystem.Debug("Exception:{0}\n", e.Message); CrossEngineHelper.LogCallStack(); return(false); } }
public static byte[] ReadFileAsArray(string filePath) { byte[] buffer = null; try { if (handlerReadFile != null) { buffer = handlerReadFile(filePath); } else { LogSystem.Debug("ReadFileByEngine handler have not register: {0}", filePath); } } catch (Exception e) { LogSystem.Debug("Exception:{0}\n", e.Message); CrossEngineHelper.LogCallStack(); return(null); } return(buffer); }