public NoUndoNetworkCommand(String name, CommandScope scope, bool active, Network net, NetworkCommandType comType) : base(name, scope, active) { commandType = comType; network = net; }
public static NetworkCommandBinding From <TRequest, TResponse>(NetworkCommandType source, NetworkCommandHandler <TRequest, TResponse> handler) where TRequest : NetworkCommand where TResponse : NetworkCommand { switch (source) { // Request that are from client are handled as requests on the master. case NetworkCommandType.FromClient: return(new NetworkCommandBinding() { CommandInternalType = NetworkCommand.CommandTypeFor(typeof(TRequest)), _deserializeRequest = JsonUtility.FromJson <TRequest>, _handleRequest = async(net, clientId, command) => await handler.ProcessRequestOnMaster(net as INetworkMaster, command as TRequest, clientId), }); // Request that are from master are handled as requests on the client. case NetworkCommandType.FromMaster: return(new NetworkCommandBinding() { CommandInternalType = NetworkCommand.CommandTypeFor(typeof(TRequest)), _deserializeRequest = JsonUtility.FromJson <TRequest>, _handleRequest = async(net, clientId, command) => await handler.ProcessRequestOnClient(net as INetworkClient, command as TRequest) }); default: throw new ArgumentOutOfRangeException(nameof(source), source, null); } }
public static string GetCommand(NetworkCommandType type) { if (m_NetworkCommands.Length >= (int)type && (int)type >= 0) { return(m_NetworkCommands[(int)type]); } else { return(null); } }
public void Register <TRequest, TResponse>(NetworkCommandType source, NetworkCommandHandler <TRequest, TResponse> handler) where TResponse : NetworkCommand where TRequest : NetworkCommand { switch (source) { case NetworkCommandType.FromClient: _fromClient.Add(NetworkCommandBinding.From(source, handler)); break; case NetworkCommandType.FromMaster: _fromMaster.Add(NetworkCommandBinding.From(source, handler)); break; case NetworkCommandType.FromAny: _fromClient.Add(NetworkCommandBinding.From(NetworkCommandType.FromClient, handler)); _fromMaster.Add(NetworkCommandBinding.From(NetworkCommandType.FromMaster, handler)); break; default: throw new ArgumentOutOfRangeException(nameof(source), source, null); } }
/// <summary> /// Register a command handler to handle networking events. /// </summary> public void Register <TRequest, TResponse>(NetworkCommandType source, NetworkCommandHandler <TRequest, TResponse> handler) where TResponse : NetworkCommand where TRequest : NetworkCommand { _commands.Register(source, handler); }