Exemple #1
0
 public UMsgSpawnObject(UNetworkIdentity identity)
 {
     netId            = identity.netId;
     sceneId          = identity.sceneId;
     assetId          = identity.assetId;
     this.objectState = identity.ToBytes(true);
 }
Exemple #2
0
        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();
        }
Exemple #3
0
        private void ClientHandleUMsgSyncState(Message m)
        {
            if (isServer)
            {
                return;
            }

            UMsgSyncState msg = m as UMsgSyncState;

            UNetworkIdentity iden = networkObjects[msg.targetNetID];

            iden.HandleBehaviourSyncMessage(msg);
        }
Exemple #4
0
        private void ClientHandleUMsgUnspawnObject(Message m)
        {
            if (isServer)
            {
                return;
            }

            UMsgUnspawnObject msg  = m as UMsgUnspawnObject;
            UNetworkIdentity  iden = networkObjects[msg.netId];

            networkObjects.Remove(iden.netId);

            ForceUnspawnNetworkObject(iden);
        }
Exemple #5
0
        private void ForceUnspawnNetworkObject(UNetworkIdentity iden)
        {
            iden.CallEventOnUnspawn();
            iden.netId = UNetworkIdentity.InvalidNetId;

            if (iden.sceneId != UNetworkIdentity.InvalidNetId)
            {
                iden.gameObject.SetActive(false);
            }
            else
            {
                DestroyImmediate(iden.gameObject);
            }
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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();
        }
Exemple #9
0
        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);
                }
            }
        }
Exemple #10
0
        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);
        }