static int GetInfoByName(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); XMLLoader <XMLDataCity> obj = LuaScriptMgr.GetNetObject <XMLLoader <XMLDataCity> >(L, 1); string arg0 = LuaScriptMgr.GetLuaString(L, 2); XMLDataCity o = obj.GetInfoByName(arg0); LuaScriptMgr.PushObject(L, o); return(1); }
static int GetInfoById(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 2); XMLLoader <XMLDataCity> obj = LuaScriptMgr.GetNetObject <XMLLoader <XMLDataCity> >(L, 1); int arg0 = (int)LuaScriptMgr.GetNumber(L, 2); XMLDataCity o = obj.GetInfoById(arg0); LuaScriptMgr.PushObject(L, o); return(1); }
static int get_Flag(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaDLL.luaL_error(L, "unknown member name Flag"); } XMLDataCity obj = (XMLDataCity)o; LuaScriptMgr.Push(L, obj.Flag); return(1); }
static int set_Wise(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaDLL.luaL_error(L, "unknown member name Wise"); } XMLDataCity obj = (XMLDataCity)o; obj.Wise = LuaScriptMgr.GetNetObject <String[]>(L, 3); return(0); }
static int set_Money(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaDLL.luaL_error(L, "unknown member name Money"); } XMLDataCity obj = (XMLDataCity)o; obj.Money = (int)LuaScriptMgr.GetNumber(L, 3); return(0); }
static int set_Name(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaDLL.luaL_error(L, "unknown member name Name"); } XMLDataCity obj = (XMLDataCity)o; obj.Name = LuaScriptMgr.GetString(L, 3); return(0); }
static int get_Wise(IntPtr L) { object o = LuaScriptMgr.GetLuaObject(L, 1); if (o == null) { LuaDLL.luaL_error(L, "unknown member name Wise"); } XMLDataCity obj = (XMLDataCity)o; LuaScriptMgr.PushArray(L, obj.Wise); return(1); }
public CityInfo(int id) { ID = id; XMLDataCity data = XMLManager.City.GetInfoById(ID); Name = data.Name; Level = data.Level; KingID = DataManager.FindKingID(data.Times[GamePublic.Instance.CurrentTimes]); Flag = data.Flag; GeneralMax = data.GeneralMax; Population = data.Population; Money = data.Money; Reservist = 0; ReservistMax = data.ReservistMax; Defense = data.Defense; m_generals = new List <int>(); m_prisons = new List <int>(); m_objects = new List <int>(); }
public static int FindCityID(string name) { if (string.IsNullOrEmpty(name)) { return(0); } string cityName = Utility.GeneralName(name); IEnumerator enumerator = XMLManager.City.Data.Values.GetEnumerator(); while (enumerator.MoveNext()) { XMLDataCity data = (XMLDataCity)enumerator.Current; if (Utility.GeneralName(data.Name) == cityName) { return(data.ID); } } Debugging.LogError("Function:FindCityID; name = " + name); return(-1); }
static void Execute() { if (Selection.activeTransform == null) { return; } if (Selection.activeTransform.childCount == 0) { return; } if (Selection.activeTransform.name != "CityPoints") { return; } Transform root = Selection.activeTransform; Transform[] points = new Transform[root.childCount]; for (int i = 0; i < root.childCount; i++) { points[i] = root.GetChild(i); } XMLLoader <XMLDataPathInfo> pathInfo = new XMLLoader <XMLDataPathInfo>(XMLConfigPath.PathInfo); XMLLoader <XMLDataCity> cityInfo = new XMLLoader <XMLDataCity>(XMLConfigPath.City); XmlDocument xmlDoc = new XmlDocument(); XmlDeclaration xmldecl; xmldecl = xmlDoc.CreateXmlDeclaration("1.0", null, null); xmldecl.Encoding = "UTF-8"; xmlDoc.AppendChild(xmldecl); XmlElement rootElement = xmlDoc.CreateElement("root"); xmlDoc.AppendChild(rootElement); int cityNum = points.Length; int[] cityPoints = new int[cityNum]; int[] cityID = new int[cityNum]; int step = GeneratePathInfo.m_step; int[] xStep = new int[] { 0, 0, step, step, step, 0, -step, -step, -step }; int[] yStep = new int[] { 0, step, step, 0, -step, -step, -step, 0, step }; for (int i = 0; i < points.Length; i++) { if (points[i].name == "") { continue; } if (!cityInfo.Data.ContainsKey(System.Convert.ToInt32(points[i].name))) { continue; } Vector3 position = points[i].transform.position; position.x = ((int)position.x / step) * step; position.y = ((int)position.y / step) * step; string p = ""; int index = 0; bool isFind = false; for (int n = 0; n < 9; n++) { p = ((int)(position.x + xStep[n])).ToString() + "," + ((int)(position.y + yStep[n])).ToString(); IEnumerator enumerator = pathInfo.Data.Keys.GetEnumerator(); while (enumerator.MoveNext()) { XMLDataPathInfo current = pathInfo.GetInfoById((int)enumerator.Current); if (current.Position == p) { isFind = true; index = (int)enumerator.Current; int id = System.Convert.ToInt32(points[i].name); cityID[i] = id; cityPoints[i] = index; break; } } if (isFind) { break; } } if (!isFind) { string errorMessage = "城市点 " + points[i].name + " 不在寻路点上!" + p; Debug.LogError(errorMessage); EditorUtility.DisplayDialog("失败", errorMessage, "确定"); return; } } //输出城市间的路线 int ID = 1; for (int i = 0; i < cityNum - 1; i++) { for (int j = i + 1; j < cityNum; j++) { List <int> path = PathFinding.GetPath(cityPoints[i], cityPoints[j], pathInfo.Data); XMLDataCity currentInfo = cityInfo.GetInfoById(cityID[i]); XMLDataCity nextInfo = cityInfo.GetInfoById(cityID[j]); if (path == null) { string errorMessage = "城市 " + currentInfo.Name + " 到城市 " + nextInfo.Name + " 的路不通!"; Debug.LogError(errorMessage); EditorUtility.DisplayDialog("失败", errorMessage, "确定"); return; } // 去掉不是相邻的城市的点 bool flag = false; for (int n = 0; n < path.Count; n++) { for (int k = 0; k < cityNum; k++) { if (k == i || k == j) { continue; } Vector3 p1 = Utility.GetPoint(pathInfo.GetInfoById(cityPoints[k]).Position); Vector3 p2 = Utility.GetPoint(pathInfo.GetInfoById(path[n]).Position); if (Vector3.Distance(p1, p2) < 4 * step) { flag = true; } } } if (flag) { continue; } int[] intArr = path.ToArray(); string[] strArr = intArr.Select(v => v.ToString()).ToArray(); string pathstr = string.Join(",", strArr); XmlElement node = xmlDoc.CreateElement("RECORD"); node.SetAttribute("ID", ID.ToString()); node.SetAttribute("FromCity", cityID[i].ToString()); node.SetAttribute("ToCity", cityID[j].ToString()); node.SetAttribute("FromPoint", cityPoints[i].ToString()); node.SetAttribute("ToPoint", cityPoints[j].ToString()); node.SetAttribute("Path", pathstr); rootElement.AppendChild(node); ID++; EditorUtility.DisplayProgressBar("Processing", currentInfo.Name, 1.0f * i / cityNum); } } xmlDoc.Save(m_configPath); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("成功", "城市位置信息生成完成!", "确定"); }