コード例 #1
0
        /// <summary>
        /// Change the axisranges for the world bounds to a new bounds.
        /// </summary>
        public static void EstablishMinBitsPerAxis(Bounds bounds, bool silent = false)
        {
            NSTSettings nstSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);

            DebugX.LogWarning(!DebugX.logWarnings ? "" :
                              ("<b>Scene is missing map bounds</b>, defaulting to a map size of Center:" + NSTMapBounds.CombinedWorldBounds.center + " Size:" + NSTMapBounds.CombinedWorldBounds.size +
                               ". Be sure to add NSTMapBounds components to your scene to define its bounds, or be sure the default bounds in NSTSettings are what you want."),
                              (!silent && Application.isPlaying && (!NSTMapBounds.isInitialized || NSTMapBounds.ActiveBoundsCount == 0) && Time.time > 1)
                              );

            DebugX.LogWarning(!DebugX.logWarnings ? "" :
                              ("<b>Scene map bounds are very small</b>. Current world bounds are " + bounds.center + " Size:" + bounds.size + ", is this intentional?" +
                               "If not check that your NSTMapBounds fully encompass your world as intended, or if using the Default bounds set in NSTSettings, that it is correct."),
                              (!silent && Application.isPlaying && (!NSTMapBounds.isInitialized || NSTMapBounds.ActiveBoundsCount > 0) && (bounds.size.x <= 1 || bounds.size.y <= 1 || bounds.size.z <= 1))
                              );

            for (int axis = 0; axis < 3; axis++)
            {
                axisRanges[axis].ChangeRange(bounds.min[axis], bounds.max[axis], (nstSettings != null) ? nstSettings.minPosResolution : 100);
            }
            DebugX.Log(
                ("Notice: Change in Map Bounds (Due to an NSTBounds being added or removed from the scene) to \n" +
                 "Center:" + bounds.center + " Size:" + bounds.size + ". Be sure this map change is happening to all networked clients or things will break badly. \n" +
                 "Position keyframes will use x:" + axisRanges[0].bits + " bits, y:" + axisRanges[1].bits + "bits, and z:" + axisRanges[2].bits +
                 " bits at the current minimum resolutons settings (in NST Settings)."), !silent && Application.isPlaying, true);
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            AddAllDependencies(true);

            NetworkSyncTransform nst = (NetworkSyncTransform)target;

            // Make sure the object is active, to prevent users from spawning inactive gameobjects (which will break things)
            if (!nst.gameObject.activeSelf)            // && AssetDatabase.Contains(target))
            {
                Debug.LogWarning("Prefabs with NetworkSyncTransform on them MUST be enabled. If you are trying to disable this so it isn't in your scene when you test it, no worries - NST destroys all scene objects with the NST component at startup.");
                nst.gameObject.SetActive(true);
            }

            NSTSettings NSTSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
            Rect        r           = EditorGUILayout.GetControlRect();

            GUI.Label(r, "Summary", "BoldLabel");
            EditorGUILayout.HelpBox(
                //"Summary:\n" +
                "Approx max seconds of buffer " + ((1 << NSTSettings.bitsForPacketCount) - 2) * Time.fixedDeltaTime * nst.sendEveryXTick * NSTSettings.TickEveryXFixed * 0.5f + " \n" +
                "sendEveryXTick = " + nst.sendEveryXTick + "\n" +
                "NSTSettings.bitsForPacketCount = " + NSTSettings.bitsForPacketCount + "\n" +
                "Time.fixedDeltaTime = " + Time.fixedDeltaTime
                ,
                MessageType.None);
        }
コード例 #3
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
        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);
        }
コード例 #4
0
ファイル: NSTNetAdapter.cs プロジェクト: vert0r/NetDemo2
        public override void OnStartClient()
        {
            // Be super sure the HLAPI didn't take a dump and set the nstID on clients if in unlimited mode.
            if (NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).bitsForNstId == 32)            // MaxNstObjects.Unlimited)
            {
                NstIdSyncvar = NI.netId.Value;
            }

            foreach (INstMasterEvents cb in iNstMasterEvents)
            {
                cb.OnNstMasterStartClient();
            }

            foreach (INstMasterOnStartClient cb in iNstMasterOnStartClient)
            {
                cb.OnNstMasterStartClient();
            }
        }
コード例 #5
0
ファイル: MasterNetAdapter.cs プロジェクト: vert0r/NetDemo2
        public void RegisterHanders()
        {
            if (IsRegistered)
            {
                return;
            }

            masterMsgTypeId = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).masterMsgTypeId;

            if (NetworkServer.active)
            {
                NetworkServer.RegisterHandler(masterMsgTypeId, ReceiveUpdate);
            }

            else if (NetworkClient.active)
            {
                NetworkManager.singleton.client.RegisterHandler(masterMsgTypeId, ReceiveUpdate);
            }

            isRegistered = true;
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: NSTMaster.cs プロジェクト: vert0r/NetDemo2
        //private void EnforceSingleton()
        //{
        //	// Base does singleton enforcement
        //	if (single != null && single != this)
        //	{
        //		Debug.LogWarning("Enforcing NSTMaster singleton. Multiples found.");
        //		Destroy(this);
        //	}
        //	single = this; ;
        //}

        //TODO add library selection logic here for selecting correct adapter
        public MasterNetAdapter EnsureHasCorrectAdapter()
        {
            NSTSettings nstSettings = NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);

            mna = GetComponent <MasterNetAdapter>();
            if (!mna)
            {
                mna = gameObject.AddComponent <MasterNetAdapter>();
            }

            if (mna && mna.NetLibrary != nstSettings.networkingLibrary)
            {
                Debug.LogWarning("Photon PUN not yet supported");
                nstSettings.networkingLibrary = NetworkLibrary.UNET;
            }



            ////if (Event.current.type == EventType.Repaint)
            //if (mna != null && mna.NetLibrary != networkingLibrary)
            //	mna.KillMe = true;


            //if (mna == null)
            //{
            //	// Hacky way to try and apply classes that may or may not exist.
            //	Type type = (networkingLibrary == NetworkLibrary.Photon) ?
            //		Type.GetType("emotitron.Network.NST.NSTMasterPhotonAdapter") :
            //		Type.GetType("emotitron.Network.NST.NSTMasterUnetAdapter");

            //	if (type != null)
            //		gameObject.AddComponent(type);

            //	mna = GetComponent<INSTMasterAdapter>();
            //}


            // Should exist now... try again.
            return(mna);
        }
コード例 #8
0
        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");
        }
コード例 #9
0
 private float MaxSecondsOfBuffer()
 {
     return(((1 << NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).bitsForPacketCount) - 2) * Time.fixedDeltaTime * nst.sendEveryXTick * NSTSettings.single.TickEveryXFixed * 0.5f);
 }
コード例 #10
0
        // constructor
        static WorldVectorCompression()
        {
            Bounds bounds = NSTMapBounds.CombinedWorldBounds;

            axisRanges = new FloatRange[3];

            for (int axis = 0; axis < 3; axis++)
            {
                axisRanges[axis] = new FloatRange(axis, bounds.min[axis], bounds.max[axis], NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).minPosResolution);
            }
        }
コード例 #11
0
 // Add NSTSettings to scene with default settings if it doesn't already contain one.
 private static void AddNSTSettingsGOFromMenu()
 {
     NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME);
 }
コード例 #12
0
ファイル: BandwidthUsage.cs プロジェクト: vert0r/NetDemo2
 // construct
 static BandwidthUsage()
 {
     enabled = (NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).logDataUse);
 }