// ------------------------------------------- /* * Converts the normal GameObjects in Network GameObjects */ void Start() { System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; NetworkEventController.Instance.NetworkEvent += new NetworkEventHandler(OnNetworkEvent); int isLocalGame = PlayerPrefs.GetInt(COOCKIE_IS_LOCAL_GAME, -1); if (isLocalGame == -1) { IsLocalGame = true; } else { IsLocalGame = false; } if (IsLocalGame) { if (MultiplayerConfiguration.LoadNumberOfPlayers() != 1) { // INSTANTIATE LOCAL NETWORK PREFAB MANAGERS for (int j = 0; j < LocalNetworkPrefabManagers.Length; j++) { Utilities.AddChild(transform, LocalNetworkPrefabManagers[j]); } // NETWORK VARIABLES MANAGER Utilities.AddChild(transform, NetworkVariablesManager); // ASSIGN THE GAME OBJECTS TO THE CONTROLLER WorldObjectController worldObjectController = GameObject.FindObjectOfType <WorldObjectController>(); if (worldObjectController != null) { int totalNumberLocalObjects = 0; for (int i = 0; i < GameObjects.Length; i++) { if (GameObjects[i].GetComponent <NetworkWorldObjectData>() != null) { totalNumberLocalObjects++; } } int counterAppWorldObjects = 0; worldObjectController.AppWorldObjects = new GameObject[totalNumberLocalObjects]; for (int i = 0; i < GameObjects.Length; i++) { GameObject prefabToNetwork = GameObjects[i]; if (prefabToNetwork.GetComponent <NetworkWorldObjectData>() != null) { prefabToNetwork.GetComponent <NetworkWorldObjectData>().enabled = true; #if ENABLE_MIRROR GameObject.FindObjectOfType <MirrorDiscoveryController>().spawnPrefabs.Add(prefabToNetwork); #endif if (prefabToNetwork.GetComponent <NetworkID>() != null) { prefabToNetwork.GetComponent <NetworkID>().enabled = false; } if (prefabToNetwork.GetComponent <ActorNetwork>() == null) { prefabToNetwork.AddComponent <ActorNetwork>(); } worldObjectController.AppWorldObjects[counterAppWorldObjects] = prefabToNetwork; counterAppWorldObjects++; } } } } else { NetworkEventController.Instance.DelayLocalEvent(NetworkEventController.EVENT_SYSTEM_INITIALITZATION_LOCAL_COMPLETED, 0.2f, 1); } } else { #if !ENABLE_PHOTON && !ENABLE_NAKAMA // CONNECT TO THE SERVER ClientTCPEventsController.Instance.Initialitzation(MultiplayerConfiguration.LoadIPAddressServer(), MultiplayerConfiguration.LoadPortServer(), MultiplayerConfiguration.LoadRoomNumberInServer(0), MultiplayerConfiguration.LoadMachineIDServer(0), MultiplayerConfiguration.LoadBufferSizeReceive(), MultiplayerConfiguration.LoadTimeoutReceive(), MultiplayerConfiguration.LoadBufferSizeSend(), MultiplayerConfiguration.LoadTimeoutSend()); // NETWORK VARIABLES MANAGER Utilities.AddChild(transform, NetworkVariablesManager); #elif !ENABLE_PHOTON && ENABLE_NAKAMA NakamaController.Instance.Initialitzation(); #endif // ADD NETWORK IDENTIFICATION TO THE GAME OBJECTS for (int i = 0; i < GameObjects.Length; i++) { GameObject prefabToNetwork = GameObjects[i]; if (prefabToNetwork.GetComponent <NetworkID>() == null) { prefabToNetwork.AddComponent <NetworkID>(); } else { prefabToNetwork.GetComponent <NetworkID>().enabled = true; } #if !DISABLE_UNET_COMMS if (prefabToNetwork.GetComponent <NetworkWorldObjectData>() != null) { prefabToNetwork.GetComponent <NetworkWorldObjectData>().enabled = false; } #endif if (prefabToNetwork.GetComponent <ActorNetwork>() == null) { prefabToNetwork.AddComponent <ActorNetwork>(); } } } m_hasBeenInitialized = true; NetworkEventController.Instance.DispatchLocalEvent(EVENT_YOURNETWORKTOOLS_CONTROLLER_STARTED); }
// ------------------------------------------- /* * Will create the socket connection */ public void MenuController_InitialitzationSocket(int _numberRoom, int _idMachineHost) { #if ENABLE_PHOTON PhotonController.Instance.Login(); #elif ENABLE_NAKAMA NakamaController.Instance.Initialitzation(); #else ClientTCPEventsController.Instance.Initialitzation(MultiplayerConfiguration.LoadIPAddressServer(), MultiplayerConfiguration.LoadPortServer(), MultiplayerConfiguration.LoadRoomNumberInServer(_numberRoom), MultiplayerConfiguration.LoadMachineIDServer(_idMachineHost), MultiplayerConfiguration.LoadBufferSizeReceive(), MultiplayerConfiguration.LoadTimeoutReceive(), MultiplayerConfiguration.LoadBufferSizeSend(), MultiplayerConfiguration.LoadTimeoutSend()); #endif }