コード例 #1
0
 /// <summary>
 /// Sends the gameobject state over the network.
 /// </summary>
 private void sendGameObjectState()
 {
     if (networkAuthority == NetworkAuthority.CLIENT && isClient)
     {
         sendMessage(MessageFactory.createSetActiveMessage(this, true), true);
     }
     else if (networkAuthority == NetworkAuthority.SERVER && isServer)
     {
         sendMessage(MessageFactory.createSetActiveMessage(this, false), true);
     }
 }
コード例 #2
0
        private static void processSetActiveMessage(byte[] msg, bool clientMessage)
        {
            short netID = ObjectSerializer.deserializeShort(ref msg);

            if (NetworkEntityManager.Instance.findComponent(netID, out NetworkIdentity netIdentity))
            {
                netIdentity.gameObject.SetActive(ObjectSerializer.deserializeByte(ref msg) == 1);

                //Message was sent from a client, now being processed on the server
                if (clientMessage && ServerBehaviour.Instance)
                {
                    short  clientID     = ObjectSerializer.deserializeShort(ref msg);   //Client who sent the message
                    byte[] setActiveMsg = MessageFactory.createSetActiveMessage(netIdentity);
                    ServerBehaviour.Instance.sendMessage(setActiveMsg, clientID, true); //Forward to all clients but the sender
                }
            }
        }