Ejemplo n.º 1
0
        public static void SendUpdate(ref UdpBitStream bitstream, ref UdpBitStream outstream)
        {
            // Send the bitstream to the UNET writer
            writer.StartMessage(masterMsgTypeId);
            writer.WriteUncountedByteArray(NSTMaster.bitstreamByteArray, bitstream.BytesUsed);
            writer.FinishMessage();

            // if this is the server - send to all.
            if (NetworkServer.active)
            {
                writer.SendPayloadArrayToAllClients(masterMsgTypeId, Channels.DefaultUnreliable);
                //NetworkServer.connections[0].FlushChannels();

                // If this is the server as client, run the ReceiveUpdate since local won't get this run.
                //if (NetworkClient.active)
                NSTMaster.ReceiveUpdate(ref bitstream, ref outstream, false, 0);
            }
            // if this is a client send to server.
            else
            {
                // TODO: find reliable way to cache this condition - Is here to eliminate some shut down warnings, and not critical
                if (cachedNetworkClient != null && cachedNetworkClient.isConnected)
                {
                    NetworkManager.singleton.client.SendWriter(writer, Channels.DefaultUnreliable);
                }
                //NetworkManager.singleton.client.connection.FlushChannels();
            }
        }
Ejemplo n.º 2
0
        public override void OnEnable()
        {
            headerName  = HeaderMasterName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();

            _target = (NSTMaster)target;

            _target.EnsureNSTMasterConforms();
            //// Remove any stray NetworkIdentities that do not belong
            //NetAdapterTools.RemovedUnusedNetworkIdentity(_target.gameObject);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  Updates over the network arrive here - AFTER the Update() runs (not tested for all platforms... thanks unet for the great docs.)
        ///  The incoming bitstream is read
        /// </summary>
        /// <param name="msg"></param>
        private static void ReceiveUpdate(NetworkMessage msg)
        {
            UdpBitStream bitstream = new UdpBitStream(msg.reader.ReadBytesNonAlloc(NSTMaster.bitstreamByteArray, msg.reader.Length), msg.reader.Length);
            UdpBitStream outstream = new UdpBitStream(NSTMaster.outstreamByteArray);

            NSTMaster.ReceiveUpdate(ref bitstream, ref outstream, NetworkServer.active, msg.conn.connectionId);

            // Write a clone message and pass it to all the clients if this is the server receiving
            if (NetworkServer.active)             // && msg.conn == nst.NI.clientAuthorityOwner)
            {
                writer.StartMessage(msg.msgType);
                writer.WriteUncountedByteArray(outstream.Data, outstream.BytesUsed);
                writer.SendPayloadArrayToAllClients(msg.msgType);
                if (NetworkServer.connections[0] != null)
                {
                    NetworkServer.connections[0].FlushChannels();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Ensures NSTSettings as well as (NSTMaster/MasterAdapter/NetworkIdentity) exist in the scene.
        /// </summary>
        /// <returns></returns>
        public static void EnsureSceneNetLibDependencies(bool immediate = true)
        {
            if (Application.isPlaying)
            {
                return;
            }

            NSTSettings.EnsureExistsInScene();

            // If a post-recompile rebuild of dependencies is pending... do it now.
            TryToAddDependenciesEverywhere();

            if (MasterNetAdapter.NetLib == NetworkLibrary.UNET)
            {
                GetNetworkManager(true);
                CopyPlayerPrefab();
            }

            NSTMaster.EnsureExistsInScene(NSTMaster.DEFAULT_GO_NAME);
            NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
        }