/// <summary> /// Initializes the NetworkManager by: /// Spawning all the components needed. /// Listening to events. /// </summary> public static void Initialize() { Main.Log("Initializing NetworkManager"); isHost = false; isClient = false; if (!UGameObject.Exists("NetworkManager")) { networkManager = Object.Instantiate(new GameObject(), Vector3.zero, Quaternion.identity); networkManager.name = "NetworkManager"; server = networkManager.AddComponent <XmlUnityServer>(); client = networkManager.AddComponent <UnityClient>(); client.Disconnected += OnClientDisconnected; Object.DontDestroyOnLoad(networkManager); server.configuration = new TextAsset(File.ReadAllText("./Mods/DVMultiplayer/Resources/config.xml")); } if (UI == null) { UI = new NetworkingUI(); UI.Setup(); } }
/// <summary> /// Deinitializing by destroying this gameobject. /// </summary> public static void Deinitialize() { Main.Log("Deinitializing NetworkManager"); if (UGameObject.Exists("NetworkManager")) { GameObject.Destroy(GameObject.Find("NetworkManager")); } }