public static NetworkManager GetNetworkManagerSingleton() { if (NetworkManager.singleton == null) { List <NetworkManager> found = FindObjects.FindObjectsOfTypeAllInScene <NetworkManager>(); if (found.Count > 0) { NetworkManager.singleton = found[0]; } else { DebugX.LogWarning(!DebugX.logWarnings ? "" : ("No NetworkManager in scene. Adding one now.")); GameObject nmGo = GameObject.Find("Network Manager"); if (nmGo == null) { nmGo = new GameObject("Network Manager"); } NetworkManager.singleton = nmGo.AddComponent <NetworkManager>(); } } // Add a HUD if that is also missing if (NetworkManager.singleton.gameObject.GetComponent <NetworkManagerHUD>() == null) { NetworkManager.singleton.gameObject.AddComponent <NetworkManagerHUD>(); } return(NetworkManager.singleton); }
private void Start() { // Destroy any NSTs the developer may have left in the scene. List <NetworkSyncTransform> nsts = FindObjects.FindObjectsOfTypeAllInScene <NetworkSyncTransform>(true); for (int i = 0; i < nsts.Count; i++) { Destroy(nsts[i].gameObject); } // Not ideal code to prevent hitching issues with vsync being off - ensures a reasonable framerate is being enforced if (QualitySettings.vSyncCount == 0) { if (Application.targetFrameRate <= 0) { Application.targetFrameRate = 60; } else { Application.targetFrameRate = Application.targetFrameRate; } DebugX.LogWarning(!DebugX.logWarnings ? "" : ("VSync appears to be disabled, which can cause some problems with Networking. \nEnforcing the current framerate of " + Application.targetFrameRate + " to prevent hitching. Enable VSync or set 'Application.targetFrameRate' as desired if this is not the framerate you would like.")); } }
private void Start() { // Destroy any NSTs the developer may have left in the scene. List <NetworkSyncTransform> nsts = FindObjects.FindObjectsOfTypeAllInScene <NetworkSyncTransform>(true); for (int i = 0; i < nsts.Count; i++) { Destroy(nsts[i].gameObject); } }
public static NetworkManager GetNetworkManager(bool createMissing = false) { if (MasterNetAdapter.NetLib != NetworkLibrary.UNET) { return(null); } if (NetworkManager.singleton == null) { List <NetworkManager> found = FindObjects.FindObjectsOfTypeAllInScene <NetworkManager>(); if (found.Count > 0) { NetworkManager.singleton = found[0]; } else if (createMissing) { DebugX.LogWarning(!DebugX.logWarnings ? null : ("No NetworkManager in scene. Adding one now.")); GameObject nmGo = GameObject.Find("Network Manager"); if (nmGo == null) { nmGo = new GameObject("Network Manager"); } NetworkManager.singleton = nmGo.AddComponent <NetworkManager>(); // If we are creating a missing NM, also create a HUD in case user wants that. NetworkManagerHUD hud = nmGo.GetComponent <NetworkManagerHUD>(); if (!hud) { nmGo.AddComponent <NetworkManagerHUD>(); } // Copy the playerprefab over from pun if it exists. } } return(NetworkManager.singleton); }
public static NetworkManager GetNetworkManager(bool createMissing = false) { if (MasterNetAdapter.NetLib != NetworkLibrary.UNET) { return(null); } if (NetworkManager.singleton == null) { #if MIRROR List <NetworkManager> mirrorNM = FindObjects.FindObjectsOfTypeAllInScene <Mirror.NetworkManager>(); if (mirrorNM.Count > 0) { return(mirrorNM[0]); } #endif List <NetworkManager> found = FindObjects.FindObjectsOfTypeAllInScene <NetworkManager>(); if (found.Count > 0) { NetworkManager.singleton = found[0]; } else if (createMissing) { Debug.Log("<b>Adding Network Manager</b>"); XDebug.LogWarning(!XDebug.logWarnings ? null : ("No NetworkManager in scene. Adding one now.")); GameObject nmGo = GameObject.Find("Network Manager"); if (nmGo == null) { nmGo = new GameObject("Network Manager"); } NetworkManager.singleton = nmGo.AddComponent <NetworkManager>(); // If we are creating a missing NM, also create a HUD in case user wants that. NetworkManagerHUD hud = nmGo.GetComponent <NetworkManagerHUD>(); if (!hud) { nmGo.AddComponent <NetworkManagerHUD>(); } // Copy the playerprefab over from pun if it exists. //#if MIRROR // var unetHUD = nmGo.GetComponent<UnityEngine.Networking.NetworkManagerHUD>(); // if (unetHUD) // Object.DestroyImmediate(unetHUD); // var unetNM = nmGo.GetComponent<UnityEngine.Networking.NetworkManager>(); // if (unetNM) // Object.DestroyImmediate(unetNM); //#endif } } return(NetworkManager.singleton); }