コード例 #1
0
        protected internal UniTask <T> SendServerRpcWithReturn <T>(Type invokeClass, string cmdName, NetworkWriter writer, int channelId, bool requireAuthority = true)
        {
            ValidateServerRpc(invokeClass, cmdName, requireAuthority);

            (UniTask <T> task, int id) = ClientObjectManager.CreateReplyTask <T>();

            // construct the message
            var message = new ServerRpcMessage
            {
                netId          = NetId,
                componentIndex = ComponentIndex,
                replyId        = id,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, cmdName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            Client.Send(message, channelId);

            return(task);
        }
コード例 #2
0
        protected internal void SendTargetRpcInternal(INetworkPlayer player, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
        {
            // this was in Weaver before
            if (Server == null || !Server.Active)
            {
                throw new InvalidOperationException($"RPC Function {rpcName} called when server is not active.");
            }

            // connection parameter is optional. assign if null.
            if (player == null)
            {
                player = ConnectionToClient;
            }

            // This cannot use Server.active, as that is not specific to this object.
            if (!IsServer)
            {
                if (logger.WarnEnabled())
                {
                    logger.LogWarning("ClientRpc " + rpcName + " called on un-spawned object: " + name);
                }
                return;
            }

            // construct the message
            var message = new RpcMessage
            {
                netId          = NetId,
                componentIndex = ComponentIndex,
                // type+func so Inventory.RpcUse != Equipment.RpcUse
                functionHash = RemoteCallHelper.GetMethodHash(invokeClass, rpcName),
                // segment to avoid reader allocations
                payload = writer.ToArraySegment()
            };

            player.Send(message, channelId);
        }