public UMsgSpawnObject(UNetworkIdentity identity) { netId = identity.netId; sceneId = identity.sceneId; assetId = identity.assetId; this.objectState = identity.ToBytes(true); }
private void ClientHandleUMsgSpawnObject(Message m) { if (isServer) { return; } UMsgSpawnObject msg = m as UMsgSpawnObject; GameObject newObject = null; if (msg.sceneId != UNetworkIdentity.InvalidNetId) { newObject = sceneInitialObjects[msg.sceneId].gameObject; newObject.SetActive(true); } else { newObject = GameObject.Instantiate(registeredPrefabs[msg.assetId]); } UNetworkIdentity iden = newObject.GetComponent <UNetworkIdentity>(); iden.FromBytes(msg.objectState, true); iden.netId = msg.netId; networkObjects.Add(iden.netId, iden); iden.CallEventOnSpawn(); }
private void ClientHandleUMsgSyncState(Message m) { if (isServer) { return; } UMsgSyncState msg = m as UMsgSyncState; UNetworkIdentity iden = networkObjects[msg.targetNetID]; iden.HandleBehaviourSyncMessage(msg); }
private void ClientHandleUMsgUnspawnObject(Message m) { if (isServer) { return; } UMsgUnspawnObject msg = m as UMsgUnspawnObject; UNetworkIdentity iden = networkObjects[msg.netId]; networkObjects.Remove(iden.netId); ForceUnspawnNetworkObject(iden); }
private void ForceUnspawnNetworkObject(UNetworkIdentity iden) { iden.CallEventOnUnspawn(); iden.netId = UNetworkIdentity.InvalidNetId; if (iden.sceneId != UNetworkIdentity.InvalidNetId) { iden.gameObject.SetActive(false); } else { DestroyImmediate(iden.gameObject); } }
public void Unspawn(GameObject networkGameObject) { if (!isServer) { return; } UNetworkIdentity iden = networkGameObject.GetComponent <UNetworkIdentity>(); networkObjects.Remove(iden.netId); serverObject.SendToAll(new UMsgUnspawnObject(iden.netId), Lidgren.Network.NetDeliveryMethod.ReliableOrdered); ForceUnspawnNetworkObject(iden); }
private void ClientHandleUMsgScriptMessage(Message m) { UMsgScriptMessage msg = m as UMsgScriptMessage; UNetworkIdentity iden = networkObjects[msg.netid]; Message newMsg = clientObject.CreateMessageObject(msg.originalMessageId); NetBuffer buffer = new NetBuffer(); buffer.Data = msg.messageData; newMsg.Read(buffer); iden.HandleScriptMessage(newMsg, msg.netComponentId); }
public void SpawnWithAuthority(GameObject networkGameObject, ulong owner) { if (!isServer) { return; } UNetworkIdentity iden = networkGameObject.GetComponent <UNetworkIdentity>(); if (iden.sceneId != UNetworkIdentity.InvalidNetId) { iden.gameObject.SetActive(true); } iden.netId = netIdCounter++; iden.ownerId = owner; networkObjects.Add(iden.netId, iden); serverObject.SendToAll(new UMsgSpawnObject(iden), Lidgren.Network.NetDeliveryMethod.ReliableOrdered); iden.CallEventOnSpawn(); }
private void LocateInitialSceneObjects() { sceneInitialObjects = new Dictionary <ulong, UNetworkIdentity>(); var tp = topRootObjects; foreach (var obj in tp) { UNetworkIdentity uv = obj.GetComponent <UNetworkIdentity>(); if (uv == null) { continue; } if (uv.sceneId != UNetworkIdentity.InvalidNetId) { sceneInitialObjects.Add(uv.sceneId, uv); } } }
private void ServerHandleUMsgScriptMessage(Message m) { UMsgScriptMessage msg = m as UMsgScriptMessage; UNetworkIdentity iden = null; networkObjects.TryGetValue(msg.netid, out iden); if (iden == null) { return; } Message newMsg = serverObject.CreateMessageObject(msg.originalMessageId); newMsg.sourceClient = msg.sourceClient; NetBuffer buffer = new NetBuffer(); buffer.Data = msg.messageData; newMsg.Read(buffer); iden.HandleScriptMessage(newMsg, msg.netComponentId); }