private void Awake() { if (single != null) { Debug.LogWarning("Enforcing NSTSettings singleton. Multiples found."); Destroy(this); } single = this; // Tell DebugX what the logging choices were. DebugX.logInfo = logTestingInfo; DebugX.logWarnings = logWarnings; DebugX.logErrors = true; // Changes physics rate if setting calls for it if (overrideFixedTime) { Time.fixedDeltaTime = 1f / physicsTicksPerSec; } //Calculate the max objects at the current bits for NstId MaxNSTObjects = (uint)Mathf.Pow(2, bitsForNstId); packetCounterRange = (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. // Set Rewind layer to ignore all other layers SetUpRewindLayer(); }
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); }
/// <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); }
/// <summary> /// Replacement for standard Awake that instead of firing when the component first wakes up, fires after the root NetworkSyncTransform /// completes its Awake(). This ensures the NST has been initialized first. /// </summary> public virtual void OnNstPostAwake() { // If there is no network, then this NST shouldn't exist - is likely just an orphaned prefab instance in the scene and will be deleted at startup. if (MasterNetAdapter.ServerIsActive == false && MasterNetAdapter.ClientIsActive == false) { isShuttingDown = true; return; } nst = transform.root.GetComponent <NetworkSyncTransform>(); na = transform.root.GetComponent <NSTNetAdapter>(); nstSettings = nst.nstSettings; }
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); }
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(); } }
/// <summary> /// Call this at the awake of other NST components to make sure that NSTSettings exists in the scene. /// </summary> public static void EnsureSettingsExistsInScene() { if (single != null) { return; } var preexist = FindObjectOfType <NSTSettings>(); if (preexist != null) { return; } DebugX.LogWarning("<b>No NSTSettings found in scene. Adding one with default settings.</b> You probably want to edit the settings yourself."); GameObject go = new GameObject("NST Settings"); single = go.AddComponent <NSTSettings>(); }
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; }
/// <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 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); }
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"); }
private void Awake() { // Ensure an NSTSettings exists in case the developer completely missed this step somehow. NSTSettings.EnsureSettingsExistsInScene(); //fallBackBounds = new Bounds(new Vector3(0, 0, 0), new Vector3(1000, 1000, 1000f)); // Add the root meshrendered and its bounds, if one exists. MeshRenderer rootmeshrend = GetComponent <MeshRenderer>(); // Try to find the starting bounds to which we will add. Need to avoid letting the defulat values of nyBounds get used. if (rootmeshrend != null) { myBounds = rootmeshrend.bounds; } // Find all of the MeshRenderers in this map - TODO: Make colliders an option as this will likely be more accurate. MeshRenderer[] allrenderers = GetComponentsInChildren <MeshRenderer>(); // if we don't have a starting bounds from the root, get the first found child as the start. if (rootmeshrend == null && allrenderers.Length > 0) { myBounds = allrenderers[0].bounds; } for (int i = 0; i < allrenderers.Length; i++) { myBounds.Encapsulate(allrenderers[i].bounds); } // Add to this bounds set to combinedBounds. if (factorBoundsOn == FactorBoundsOn.AwakeDestroy) { FactorInBounds(true); } }
private float MaxSecondsOfBuffer() { return(((1 << NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).bitsForPacketCount) - 2) * Time.fixedDeltaTime * nst.sendEveryXTick * NSTSettings.single.TickEveryXFixed * 0.5f); }
public void OnEnable() { NSTSettings.EnsureSettingsExistsInScene(); }
// construct static BandwidthUsage() { enabled = (NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME).logDataUse); }
// Add NSTSettings to scene with default settings if it doesn't already contain one. private static void AddNSTSettingsGOFromMenu() { NSTSettings.EnsureExistsInScene(NSTSettings.DEFAULT_GO_NAME); }
// 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); } }