Version: 2017.2
public static void RegisterHandler (short msgType, Networking.NetworkMessageDelegate handler);

Parameters

msgType Message type number.
handler Function handler which will be invoked for when this message type is received.

Description

Register a handler for a particular message type.

There are several system message types which you can add handlers for. You can also add your own message types.

using UnityEngine;
using UnityEngine.Networking;

public class MyServer : NetworkManager { void Start() { NetworkServer.Listen(7070); Debug.Log("Registering server callbacks"); NetworkServer.RegisterHandler(MsgType.Connect, OnConnected); }

void OnConnected(NetworkMessage netMsg) { Debug.Log("Client connected"); } }

The system message types are listed below:

class MsgType
{
    public const short ObjectDestroy = 1;
    public const short Rpc = 2;
    public const short ObjectSpawn = 3;
    public const short Owner = 4;
    public const short Command = 5;
    public const short LocalPlayerTransform = 6;
    public const short SyncEvent = 7;
    public const short UpdateVars = 8;
    public const short SyncList = 9;
    public const short ObjectSpawnScene = 10;
    public const short NetworkInfo = 11;
    public const short SpawnFinished = 12;
    public const short ObjectHide = 13;
    public const short CRC = 14;
    public const short LocalClientAuthority = 15;
}

Most of these messages are for internal use only. Users should not define message ids in this range.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961