Exemple #1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            serializedObject.Update();

            NSTMaster.EnsureExistsInScene("NST Master").EnsureHasCorrectAdapter();

            var nstsettings = (NSTSettings)target;

            nstsettings.MaxNSTObjects = (uint)System.Math.Pow(2, nstsettings.bitsForNstId);
            nstsettings.frameCount    = (int)System.Math.Pow(2, nstsettings.bitsForPacketCount);

            float adjustedFixedTime = Time.fixedDeltaTime;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(new GUIContent("Summary:"), "BoldLabel");

            string str =
                "Physics Rate: " + adjustedFixedTime.ToString("0.000") + "ms (" + (1 / adjustedFixedTime).ToString("0.0") + " ticks/sec)\n\n" +

                "You can change the physics rate by changing the Edit/Project Settings/Time/Fixed Step value. \n\n" +

                NSTMapBoundsEditor.WorldBoundsSummary()
            ;

            EditorGUILayout.HelpBox(str, MessageType.None);

            serializedObject.ApplyModifiedProperties();
        }
Exemple #2
0
        public override void OnEnable()
        {
            nstMaster = (NSTMaster)target;
            mna       = nstMaster.EnsureHasCorrectAdapter();

            headerName  = HeaderMasterName;
            headerColor = HeaderSettingsColor;
            base.OnEnable();
        }
Exemple #3
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);
        }
Exemple #4
0
        private void Update()
        {
            for (int i = 0; i < NetworkSyncTransform.allNsts.Count; i++)
            {
                NetworkSyncTransform.allNsts[i].MasterCommandToInterpolate();
            }

            if (updateDue)
            {
                NSTMaster.PollAllForUpdates();
            }

            updateDue = false;
        }
Exemple #5
0
        public override void OnInspectorGUI()
        {
            nstMaster   = (NSTMaster)target;
            mna         = nstMaster.EnsureHasCorrectAdapter();
            nstSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);

            base.OnInspectorGUI();

            if (mna == null)
            {
                EditorGUILayout.HelpBox(
                    "No network library adapter found for '" +
                    Enum.GetName(typeof(NetworkLibrary), nstSettings.networkingLibrary) + "'", MessageType.Error);
            }

            EditorGUILayout.HelpBox("The NST Master is a required engine singleton. It collects and dispatches all NST Updates, and receives incoming updates from the network.", MessageType.None);
        }
Exemple #6
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);

            BandwidthUsage.ReportMasterBits(ref bitstream, BandwidthLogType.MasterIn);

            // 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(bitstream.Data, msg.reader.Length);
                writer.WriteUncountedByteArray(outstream.Data, outstream.BytesUsed);
                writer.SendPayloadArrayToAllClients(msg.msgType);
            }
        }
Exemple #7
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);
        }
        private void AddAllDependencies(bool silence = false)
        {
            headerName  = HeaderNSTName;
            headerColor = HeaderNSTColor;
            base.OnEnable();

            nst = (NetworkSyncTransform)target;

            // Add this NST to the prefab spawn list (and as player prefab if none exists yet) as an idiot prevention
            if (!Application.isPlaying)
            {
                MasterNetAdapter.AddAsRegisteredPrefab(nst.gameObject, silence);
            }


            // If user tried to put NST where it shouldn't be... remove it and all of the required components it added.
            if (nst.transform.parent != null)
            {
                Debug.LogError("NetworkSyncTransform must be on the root of an prefab object.");
                nst.nstElementsEngine = nst.transform.GetComponent <NSTElementsEngine>();

                NSTNetAdapter.RemoveAdapter(nst);

                DestroyImmediate(nst);

                if (nst.nstElementsEngine != null)
                {
                    DestroyImmediate(nst.nstElementsEngine);
                }

                return;
            }

            nst.na = NSTNetAdapter.EnsureNstAdapterExists(nst.gameObject);

            nst.nstSettings       = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
            nst.nstElementsEngine = NSTElementsEngine.EnsureExistsOnRoot(nst.transform, false);
            NSTMaster.EnsureExistsInScene("NST Master");
        }
Exemple #9
0
        protected override void Awake()
        {
            // Base does singleton enforcement
            base.Awake();

            NSTMaster.EnsureExistsInScene("NST Master");
            // TODO Add items like this to an idiot check test bool so they can be disabled.
            DestroyAllNSTsInScene();

            // Tell DebugX what the logging choices were.
            DebugX.logInfo     = logTestingInfo;
            DebugX.logWarnings = logWarnings;
            DebugX.logErrors   = true;

            //Calculate the max objects at the current bits for NstId
            MaxNSTObjects = (uint)Mathf.Pow(2, bitsForNstId);

            frameCount =
                (bitsForPacketCount == 4) ? 16 :
                (bitsForPacketCount == 5) ? 32 :
                (bitsForPacketCount == 6) ? 64 :
                0;                 // zero will break things, but it should never happen so breaking it would be good.
        }
Exemple #10
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
            {
                NetworkManager.singleton.client.SendWriter(writer, Channels.DefaultUnreliable);
                //NetworkManager.singleton.client.connection.FlushChannels();
            }
        }