private void __OnUnregistered(NetworkMessage message) { HostMessage temp = message == null ? null : message.ReadMessage <HostMessage>(); Node target; if (temp == null || temp.index < 0 || __nodes == null || !__nodes.TryGetValue(temp.index, out target)) { Debug.LogError("Unregister Fail."); return; } if (onUnregistered != null) { onUnregistered(target); } if (target is Node) { if (target._onDestroy != null) { target._onDestroy(); } } if (target != null) { Destroy(target.gameObject); } __nodes.Remove(temp.index); }
private void __OnRpc(NetworkMessage message) { NetworkConnection connection = message == null ? null : message.conn; #if DEBUG if (connection == null) { throw new InvalidOperationException(); } #endif HostMessage temp = message.ReadMessage <HostMessage>(); Node target; if (__nodes == null || temp == null || !__nodes.TryGetValue(temp.index, out target) || (target == null && !(target is UnityEngine.Object)) || temp.bytes == null || temp.bytes.Length < 2) { Debug.LogError("Rpc Fail."); return; } NetworkReader reader = new NetworkReader(temp.bytes); target.InvokeHandler(reader.ReadInt16(), connection.connectionId, reader); }
private void __OnRegistered(NetworkMessage message) { HostMessage temp = message == null ? null : message.ReadMessage <HostMessage>(); if (temp == null || temp.index < 0) { Debug.LogError("Register Fail."); return; } if (__nodes == null) { __nodes = new System.Collections.Generic.Dictionary <int, Node>(); } Node instance; if (__nodes.TryGetValue(temp.index, out instance) && instance != null) { if (!instance._isLocalPlayer) { NetworkReader reader = new NetworkReader(temp.bytes); instance._type = reader.ReadInt16(); instance._isLocalPlayer = reader.ReadBoolean(); } } else { NetworkReader reader = new NetworkReader(temp.bytes); short type = reader.ReadInt16(); instance = prefabs == null || type < 0 || type >= prefabs.Length ? null : prefabs[type]; instance = instance == null ? null : Instantiate(instance); #if DEBUG if (instance == null) { throw new InvalidOperationException(); } #endif instance._isLocalPlayer = reader.ReadBoolean(); instance._type = type; instance._index = temp.index; instance._host = this; __nodes[temp.index] = instance; if (instance._onCreate != null) { instance._onCreate(); } if (onRegistered != null) { onRegistered(instance); } } }
private HostMessage __GetMessage(short index, int count, byte[] bytes) { if (__message == null) { __message = new HostMessage(index, count, bytes); } else { __message.index = index; __message.count = count; __message.bytes = bytes; } return(__message); }