void Start() { // назначение ключу свою "команду" через методы в InputControll скрипте //run //inputCtrl.SetCommandForButton(_fire, new FireCommand()); inputCtrl.SetCommandForButton(_fire, GameObject.FindObjectOfType <FireCommand>() as FireCommand); inputCtrl.SetCommandForButton(_jump, new JumpCommand()); inputCtrl.SetCommandForButton(_sound, new SoundCommand()); inputCtrl.SetCommandForButton(_ball, new BallCommand()); //run switch inputCtrl.SetCommandForButton(_light, new SwitchLightsCommand(new Light())); inputCtrl.SetCommandForButton(_button, new SwitchButtonCommand(new Button())); //macrocommand //creating macrocommand var ballCommand = new BallCommand(); var soundCommand = new SoundCommand(); //merging var macroCommand = new MacroCommand(new List <ICommand> { ballCommand, soundCommand }); //run macrocommand inputCtrl.SetCommandForButton(_macro, macroCommand); // hold inputCtrl.SetCommandForButton(_hold, GameObject.FindObjectOfType <Hold>() as Hold); }
/// <summary> /// Valid packet processing. /// </summary> /// <param name="packet">Packet for validation.</param> public void HandlePacket(Packet packet) { if (packet == null) { throw new Exception("packet can`t be null"); } // The choice of actions depending on the type of command. switch (packet.commandCharacter) { case "T": { TextCommand textCommand = new TextCommand(packet.parameters); ColourPrinter.Print("\nACK", ConsoleColor.Green); textCommand.Action(); break; }; case "S": { List <int> paramList = new List <int>(); // Convert the parameters to a list of integers. foreach (string str in commandValidator.GetParamsList(packet.parameters)) { if (int.TryParse(str.Trim(), out int result)) { paramList.Add(result); } else { throw new Exception("Parameter can`t be parsed."); } } // In this type of command, two required parameters are required - frequency and duration. if (paramList.Count != 2) { throw new Exception("Parameter list have wrong number of items."); } // The zero parameter is frequency. The first is duration. SoundCommand soundCommand = new SoundCommand(paramList[0], paramList[1]); ColourPrinter.Print("\nACK", ConsoleColor.Green); soundCommand.Action(); break; }; default: { throw new Exception("Undefined packet command character."); }; } }
protected void ParsePlayCommand(STFReader f, string lowertoken) { switch (lowertoken) { case "playoneshot": case "startloop": case "releaselooprelease": case "startlooprelease": case "releaseloopreleasewithjump": case "disabletrigger": case "enabletrigger": case "setstreamvolume": ++playcommandcount; if (playcommandcount > 1) { STFException.TraceWarning(f, "Replaced play command"); } break; default: break; } switch (lowertoken) { case "playoneshot": SoundCommand = new PlayOneShot(f); break; case "startloop": SoundCommand = new StartLoop(f); break; case "releaselooprelease": SoundCommand = new ReleaseLoopRelease(f); break; case "startlooprelease": SoundCommand = new StartLoopRelease(f); break; case "releaseloopreleasewithjump": SoundCommand = new ReleaseLoopReleaseWithJump(f); break; case "disabletrigger": SoundCommand = new DisableTrigger(f); break; case "enabletrigger": SoundCommand = new EnableTrigger(f); break; case "setstreamvolume": SoundCommand = new SetStreamVolume(f); break; case "(": f.SkipRestOfBlock(); break; } }
/// <summary> /// Decide which command will be executed /// </summary> /// <param name="packet"></param> public static void Handler(string packet) { bool isValidPacket = Validator.ValidatePacket(packet); if (isValidPacket) { switch (packet[1]) { case 'T': TextCommand text = new TextCommand(); text.Execute(packet); break; case 'S': SoundCommand sound = new SoundCommand(); sound.Execute(packet); break; } } else { Console.WriteLine("\n" + Helper.badRequest + "\n"); } }