docs.unity.cn
    Show / Hide Table of Contents

    Struct RpcExecutor

    Struct that can be used to simplify writing systems and jobs that deserialize and execute received rpc commands.

    Inherited Members
    ValueType.Equals(Object)
    ValueType.GetHashCode()
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetType()
    Namespace: Unity.NetCode
    Syntax
    public struct RpcExecutor

    Methods

    ExecuteCreateRequestComponent<TActionSerializer, TActionRequest>(ref RpcExecutor.Parameters)

    Helper method that can be used to implement the execute method for the IRpcCommandSerializer<T> interface. By calling the ExecuteCreateRequestComponent, a new entity (with a TActionRequest and a ReceiveRpcCommandRequest component) is created. It is the users responsibility to write a system that consumes the created rpcs entities. For example:

    public struct MyRpcConsumeSystem : ISystem
    {
       private Query rcpQuery;
       public void OnCreate(ref SystemState state)
       {
           var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<MyRpc, ReceiveRpcCommandRequestComponent>();
           rcpQuery = state.GetEntityQuery(builder);
       }
       public void OnUpdate(ref SystemState state)
       {
            foreach(var rpc in SystemAPI.Query<MyRpc>().WithAll<ReceiveRpcCommandRequestComponent>())
            {
                //do something with the rpc
            }
            //Consumes all of them
            state.EntityManager.DestroyEntity(rpcQuery);
       }
    }
    Declaration
    public static Entity ExecuteCreateRequestComponent<TActionSerializer, TActionRequest>(ref RpcExecutor.Parameters parameters)
        where TActionSerializer : struct, IRpcCommandSerializer<TActionRequest> where TActionRequest : struct, IComponentData
    Parameters
    Type Name Description
    RpcExecutor.Parameters parameters

    Container for EntityCommandBuffer, JobIndex, as well as connection entity.

    Returns
    Type Description
    Entity

    Created entity for RPC request. Name of the Entity is set as 'NetCodeRPC'.

    Type Parameters
    Name Description
    TActionSerializer

    Struct of type IRpcCommandSerializer<T>.

    TActionRequest

    Unmanaged type of IComponentData.

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Thursday, August 10, 2023