public void SetSelector(PickInfo pickInfo) { ClearCommands(); GameRoomManager.Instance.CommandManager.CurrentExecuter = pickInfo; //从“command_set”表格中读取对应于该单位的指令菜单集 CsvStreamReader CommandSet = CsvDataManager.Instance.GetTable("command_set"); if (CommandSet == null) { return; } string strCmdSet = ""; string toggleRootName = ""; if (pickInfo.CurrentCity != null) { if (pickInfo.CurrentCity.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId) // 只有是自己的城市,才会出现[命令菜单] { strCmdSet = CommandSet.GetValue(2001, "CommandSet"); } toggleRootName = "城市"; } else if (pickInfo.CurrentActor != null) { var av = pickInfo.CurrentActor; if (av.OwnerId == GameRoomManager.Instance.CurrentPlayer.TokenId) // 只有是自己的部队,才会出现[命令菜单] { strCmdSet = CommandSet.GetValue(av.ActorInfoId, "CommandSet"); } CsvStreamReader csv = CsvDataManager.Instance.GetTable("actor_info"); toggleRootName = csv.GetValue(av.ActorInfoId, "Name"); } else if (pickInfo.CurrentCell != null) { HexResource res = pickInfo.CurrentCell.Res; if (res.GetAmount(res.ResType) > 0) { string[] resNames = { "木材", "粮食", "铁矿" }; toggleRootName = $"{resNames[(int) res.ResType]}:{res.GetLevel(res.ResType)}"; } else if (pickInfo.CurrentCell.IsUnderwater) { toggleRootName = "水"; } else {// Sand-0; Grass-1; Mud-2; Stone-3; Snow-4 string[] terrainNames = { "沙漠", "草原", "沃土", "山区", "雪地" }; toggleRootName = terrainNames[(int)pickInfo.CurrentCell.TerrainTypeIndex]; } } int countCmd = LoadCommandMenu(strCmdSet); //gameObject.SetActive(countCmd > 0); _toggleText.text = toggleRootName; gameObject.SetActive(true); }
public void LoadCommands() { // create and attach child object GameObject obj = new GameObject("Commands"); obj.transform.parent = transform; obj.transform.localPosition = Vector3.zero; Commands = new Dictionary <CommandID, CommandInfo>(); // create all the commands CommandInfo ci = null; CsvStreamReader csv = CsvDataManager.Instance.GetTable("command_id"); CommandID cmdId = CommandID.BuildCity; string cmdName = cmdName = csv.GetValue((int)cmdId, "Name"); int actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } int order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdBuildCity>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.AbandonCity; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdAbandonCity>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.AbandonBuilding; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdAbandonBuilding>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateFarmer; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateFarmer>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateSettler; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateSettler>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateSoldier1; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateSoldier1>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateSoldier2; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateSoldier2>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateSoldier3; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateSoldier3>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.CreateSoldier4; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCreateSoldier4>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Lumberjack; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdLumberjack>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Harvest; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdHarvest>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Mining; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdMining>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.BuildRoad; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdBuildRoad>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.BuildBridge; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdBuildBridge>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.DismissTroop; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdDismissTroop>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.March; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdMarch>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Attack; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdAttack>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Guard; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdGuard>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.RapidMarch; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdRapidMarch>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Charge; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdCharge>(), }; Commands.Add(cmdId, ci); cmdId = CommandID.Halt; cmdName = csv.GetValue((int)cmdId, "Name"); actionPointCost = csv.GetValueInt((int)cmdId, "ActionPointCost"); if (actionPointCost > 0) { cmdName += $"({actionPointCost})"; } order = csv.GetValueInt((int)cmdId, "Order"); ci = new CommandInfo() { CmdId = cmdId, Name = cmdName, Order = order, ActionPointCost = actionPointCost, Func = obj.AddComponent <CmdHalt>(), }; Commands.Add(cmdId, ci); }