private void FixedUpdate() { if (!ownCube || health <= 0) { return; } // if (currentCommands.HasCommand()) // { currentCommands.Rotation = ownCube.transform.rotation.eulerAngles.y; commands.Add(new Commands(currentCommands)); MoveOwnCube(currentCommands); //serialize var packet = Packet.Obtain(); Serializer.ClientSerializeInput(commands, packet.buffer); packet.buffer.Flush(); var remoteEp = serverEndpoint; if (networkLatency == 0) { channel.Send(packet, remoteEp); packet.Free(); } else { Task.Delay(networkLatency) .ContinueWith(t => channel.Send(packet, remoteEp)) .ContinueWith(t => packet.Free()); } currentCommands.Seq++; // } }
public Commands(string Menu, string Name, int Col, int Row) { menu = Menu; name = Name; idTag = new Point(Col, Row); if (Col > MaxIdTag.Col) { MaxIdTag = new Point(Col, MaxIdTag.Row); } if (Row > MaxIdTag.Row) { MaxIdTag = new Point(MaxIdTag.Col, Row); } CommandsList.Add(this); ////if ((Row == Commands.ElementConfigInt[cSensorsRowIndexKey]) && (Col != Commands.ElementConfigInt[cCommandActionsColIndexKey])) ////{ //// Array.Resize(ref Sensors, Sensors.Length + 1); //// Sensors[Sensors.Length - 1] = Name; ////} ////else if (Col == Commands.ElementConfigInt[cCommandActionsColIndexKey]) ////{ //// Array.Resize(ref CommandActions, CommandActions.Length + 1); //// CommandActions[CommandActions.Length - 1] = Name.Substring(1); ////} }
///<summary>Registers all commands defined in the class T.</summary> ///<typeparam name="T">The class where the commands are stored.</typeparam> ///<remarks>The class holding the commands cannot be static. ///Commands must have a return type of Task/ValueTask and cannot be static. ///The first parameter must be a <c>Context</c>.</remarks> public static void RegisterCommands <T>() where T : class { CommandsInstance = Activator.CreateInstance(typeof(T)); MethodInfo[] methods = typeof(T).GetMethods(); foreach (MethodInfo m in methods) { if (!m.IsDefined(typeof(CommandAttribute))) { return; } if (m.ReturnType.GetMethod(nameof(Task.GetAwaiter)) == null) { throw new InvalidSignatureException("The return type of the method must derive from Task or ValueTask to be a command.", m.Name); } if (m.IsStatic) { throw new InvalidSignatureException("A static method cannot be a command.", m.Name); } if (!typeof(Context).IsAssignableFrom(m.GetParameters()[0].ParameterType)) { throw new InvalidSignatureException("The first argument of a command must be a Context.", m.Name); } if (m.IsDefined(typeof(AliasesAttribute))) { CommandsList.Add(new Command(m.GetCustomAttribute <CommandAttribute>().Name, m, m.GetCustomAttribute <AliasesAttribute>().Aliases)); } else { CommandsList.Add(new Command(m.GetCustomAttribute <CommandAttribute>().Name, m, new List <string>())); } } }
// Update is called once per frame void Update() { bool rightPressed = Input.GetKey(TurnRightKey); bool leftPressed = Input.GetKey(TurnLeftKey); bool accPressed = Input.GetKey(AccelerateKey); bool breakPressed = Input.GetKey(BreakKey); if (rightPressed && !leftPressed) { //CommandsList.Add(new Turn(TurnDirection.Right)); CommandsList.Add(new SimplifiedCommand(CommandType.TurnRight)); } if (leftPressed && !rightPressed) { //CommandsList.Add(new Turn(TurnDirection.Left)); CommandsList.Add(new SimplifiedCommand(CommandType.TurnLeft)); } if (accPressed && !breakPressed) { //CommandsList.Add(new Accelerate()); CommandsList.Add(new SimplifiedCommand(CommandType.Accelerate)); } if (!accPressed && breakPressed) { //CommandsList.Add(new Break()); CommandsList.Add(new SimplifiedCommand(CommandType.Break)); } }
//TODO : wrzucić to do osobnej biblioteki i interfejsu!!! public void GiveCommand(Command command) { CommandsList.Add(command); }
private static void Add(Command cmm) { CommandsList.Add(cmm.Comm, cmm); }