UnityEngine.Networking.NetworkManager.InitializeSingleton C# (CSharp) Method

InitializeSingleton() private method

private InitializeSingleton ( ) : void
return void
        private void InitializeSingleton()
        {
            if ((singleton == null) || (singleton != this))
            {
                LogFilter.currentLogLevel = (int) this.m_LogLevel;
                if (this.m_DontDestroyOnLoad)
                {
                    if (singleton != null)
                    {
                        if (LogFilter.logDev)
                        {
                            Debug.Log("Multiple NetworkManagers detected in the scene. Only one NetworkManager can exist at a time. The duplicate NetworkManager will not be used.");
                        }
                        UnityEngine.Object.Destroy(base.gameObject);
                        return;
                    }
                    if (LogFilter.logDev)
                    {
                        Debug.Log("NetworkManager created singleton (DontDestroyOnLoad)");
                    }
                    singleton = this;
                    if (Application.isPlaying)
                    {
                        UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
                    }
                }
                else
                {
                    if (LogFilter.logDev)
                    {
                        Debug.Log("NetworkManager created singleton (ForScene)");
                    }
                    singleton = this;
                }
                if (this.m_NetworkAddress != "")
                {
                    s_Address = this.m_NetworkAddress;
                }
                else if (s_Address != "")
                {
                    this.m_NetworkAddress = s_Address;
                }
            }
        }

Usage Example

Example #1
0
        internal static void UpdateScene()
        {
#if UNITY_EDITOR
            // In the editor, reloading scripts in play mode causes a Mono Domain Reload.
            // This gets the transport layer (C++) and HLAPI (C#) out of sync.
            // This check below detects that problem and shuts down the transport layer to bring both systems back in sync.
            if (singleton == null && s_PendingSingleton != null && s_DomainReload)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkManager detected a script reload in the editor. This has caused the network to be shut down.");
                }

                s_DomainReload = false;
                s_PendingSingleton.InitializeSingleton();

                // destroy network objects
                var uvs = FindObjectsOfType <NetworkIdentity>();
                foreach (var uv in uvs)
                {
                    GameObject.Destroy(uv.gameObject);
                }

                singleton.StopHost();

                NetworkTransport.Shutdown();
            }
#endif

            if (singleton == null)
            {
                return;
            }

            if (s_LoadingSceneAsync == null)
            {
                return;
            }

            if (!s_LoadingSceneAsync.isDone)
            {
                return;
            }

            if (LogFilter.logDebug)
            {
                Debug.Log("ClientChangeScene done readyCon:" + s_ClientReadyConnection);
            }
            singleton.FinishLoadScene();
            s_LoadingSceneAsync.allowSceneActivation = true;
            s_LoadingSceneAsync = null;
        }