[Snippet] C# NetworkCallbackDelegate

Client.cs

BaseScript.TriggerServerEvent("eventName", new Action<object>((arg) =>
            {
                // Code here is executed after the server
                // arg is the data the Server returns
                // In this example we are expecting an object variable from the Server
            }));

Server.cs

RegisterEventHandler("eventName", new Action<NetworkCallbackDelegate>(OnEvent));

private void OnEvent(NetworkCallbackDelegate networkCB)
        {
            // Code here is executed when the event triggers
            // Invoking the delegate NetworkCallback executes Client's code
            // You have to pass an object variable because we have specified it in the Client
            networkCB.Invoke(5);
            // In this example we are telling the Client that the Server has returned 5.
        }

Hope this is useful to you.

8 Likes