// -------------------------------------------

        /*
         * CreateRoom
         */
        private void CreateRoom()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            string ipAddress  = m_container.Find("IPAddress").GetComponent <InputField>().text;
            int    portNumber = int.Parse(m_container.Find("PortAddress").GetComponent <InputField>().text);

            if (ipAddress.Length < 5)
            {
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_INFORMATION_SCREEN, ScreenInformationView.SCREEN_INFORMATION, UIScreenTypePreviousAction.KEEP_CURRENT_SCREEN, LanguageController.Instance.GetText("message.error"), LanguageController.Instance.GetText("screen.lobby.setup.server.invalid.ip"), null, "");
            }
            else
            {
                if (portNumber < 2000)
                {
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_INFORMATION_SCREEN, ScreenInformationView.SCREEN_INFORMATION, UIScreenTypePreviousAction.KEEP_CURRENT_SCREEN, LanguageController.Instance.GetText("message.error"), LanguageController.Instance.GetText("screen.lobby.setup.server.invalid.portnumber"), null, "");
                }
                else
                {
                    PlayerPrefs.SetString(PLAYERPREFS_YNT_IP, ipAddress);
                    PlayerPrefs.SetString(PLAYERPREFS_YNT_PORT, portNumber.ToString());
                    MultiplayerConfiguration.SaveIPAddressServer(ipAddress);
                    MultiplayerConfiguration.SavePortServer(portNumber);
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenRemoteModeView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
                    Destroy();
                }
            }
        }
        // -------------------------------------------

        /*
         * Constructor
         */
        public override void Initialize(params object[] _list)
        {
            base.Initialize(_list);

            m_root      = this.gameObject;
            m_container = m_root.transform.Find("Content");

#if !ALTERNATIVE_TITLE
            m_container.Find("Title").GetComponent <Text>().text = LanguageController.Instance.GetText("message.game.title");
#else
            m_container.Find("Title").GetComponent <Text>().text = LanguageController.Instance.GetText("message.game.mobile.title");
#endif

            GameObject playAsCustomer = m_container.Find("Button_Customer").gameObject;
            playAsCustomer.transform.Find("Text").GetComponent <Text>().text = LanguageController.Instance.GetText("screen.play.as.customer");
            playAsCustomer.GetComponent <Button>().onClick.AddListener(PlayAsCustomer);

            GameObject playAsDirector = m_container.Find("Button_Director").gameObject;
            playAsDirector.transform.Find("Text").GetComponent <Text>().text = LanguageController.Instance.GetText("screen.play.as.director");
            playAsDirector.GetComponent <Button>().onClick.AddListener(PlayAsDirector);

            GameObject playAsSpectator = m_container.Find("Button_Spectator").gameObject;
            if (playAsSpectator != null)
            {
                playAsSpectator.transform.Find("Text").GetComponent <Text>().text = LanguageController.Instance.GetText("screen.play.as.spectator");
                playAsSpectator.GetComponent <Button>().onClick.AddListener(PlayAsSpectator);
            }
            MultiplayerConfiguration.SaveSpectatorMode(MultiplayerConfiguration.SPECTATOR_MODE_DISABLED);

            UIEventController.Instance.UIEvent += new UIEventHandler(OnMenuEvent);
        }
        // -------------------------------------------

        /*
         * InitializeLocalData
         */
        public void InitializeLocalData(string _initialData)
        {
            if (MultiplayerConfiguration.LoadNumberOfPlayers() == 1)
            {
                InitializeWithData(_initialData);
            }
        }
        // -------------------------------------------

        /*
         * ConfirmNumberPlayers
         */
        private void ConfirmNumberPlayers()
        {
            bool loadNextScreen = true;

            if (loadNextScreen)
            {
                SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
                if (MenuScreenController.Instance.EnableAppOrganization)
                {
                    UIEventController.Instance.DispatchUIEvent(EVENT_SCREENNUMBERPLAYERS_SET_NUMBER_PLAYERS, FinalNumberOfPlayers);
                    GoBackPressed();
                }
                else
                {
                    UIEventController.Instance.DispatchUIEvent(MenuScreenController.EVENT_MENUEVENTCONTROLLER_CREATED_NEW_GAME, FinalNumberOfPlayers);
                    if (FinalNumberOfPlayers == 1)
                    {
                        MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_DISABLED);
                        MenuScreenController.Instance.ScreenGameOptions = ScreenCharacterSelectionView.SCREEN_NAME;
                    }
                    else
                    {
                        MenuScreenController.Instance.ScreenGameOptions = ScreenDirectorModeView.SCREEN_NAME;
                    }
                    MenuScreenController.Instance.LoadCustomGameScreenOrCreateGame(false, FinalNumberOfPlayers, "", null);
                }
            }
        }
        // -------------------------------------------

        /*
         * PlayInVRPressed
         */
        private void PlayInVRPressed()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            CardboardLoaderVR.Instance.SaveEnableCardboard(true);
#if ENABLE_GOOGLE_ARCORE
            if (!MenuScreenController.Instance.AskToEnableBackgroundARCore || (MultiplayerConfiguration.LoadGoogleARCore(-1) != MultiplayerConfiguration.GOOGLE_ARCORE_ENABLED))
            {
                FinalLoadGameWithAssets();
            }
            else
            {
                if (MenuScreenController.Instance.AlphaAnimationNameStack != -1)
                {
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_LAYER_GENERIC_SCREEN, -1, new List <object> {
                        ScreenController.ANIMATION_ALPHA, 0f, 1f, MenuScreenController.Instance.AlphaAnimationNameStack
                    }, ScreenEnableBackground.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, m_nameOfScreen);
                }
                else
                {
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenEnableBackground.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, m_nameOfScreen);
                }
            }
#else
            if (MenuScreenController.Instance.RequestPermissionAssetBundleDownload)
            {
                RequestDownloadAssetBundle();
            }
            else
            {
                FinalLoadGameWithAssets();
            }
#endif
        }
Exemplo n.º 6
0
        // -------------------------------------------

        /*
         * Constructor
         */
        public override void Initialize(params object[] _list)
        {
            base.Initialize(_list);

            m_root      = this.gameObject;
            m_container = m_root.transform.Find("Content");

#if !ALTERNATIVE_TITLE
            m_container.Find("Title").GetComponent <Text>().text = LanguageController.Instance.GetText("message.game.title");
#else
            m_container.Find("Title").GetComponent <Text>().text = LanguageController.Instance.GetText("message.game.mobile.title");
#endif

            GameObject playWithARCore = m_container.Find("Button_WithARCore").gameObject;
            playWithARCore.transform.Find("Text").GetComponent <Text>().text = LanguageController.Instance.GetText("screen.play.with.arcore");
            playWithARCore.GetComponent <Button>().onClick.AddListener(PlayWithARCore);

            GameObject playWithoutARCore = m_container.Find("Button_WithoutARCore").gameObject;
            playWithoutARCore.transform.Find("Text").GetComponent <Text>().text = LanguageController.Instance.GetText("screen.play.without.arcore");
            playWithoutARCore.GetComponent <Button>().onClick.AddListener(PlayWithoutARCore);

            MultiplayerConfiguration.SaveEnableBackground(true);

            UIEventController.Instance.UIEvent += new UIEventHandler(OnMenuEvent);
        }
Exemplo n.º 7
0
        // -------------------------------------------

        /*
         * PlayLocalGame
         */
        private void PlayLocalGame()
        {
#if ENABLE_PHOTON
            if (GameObject.FindObjectOfType <PhotonController>() != null)
            {
                PhotonController.Instance.Destroy();
            }
#elif ENABLE_NAKAMA
            if (GameObject.FindObjectOfType <NakamaController>() != null)
            {
                NakamaController.Instance.Destroy();
            }
#endif

            NetworkEventController.Instance.MenuController_SetLocalGame(true);
            NetworkEventController.Instance.MenuController_SetLobbyMode(false);
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
#if UNITY_WEBGL
            MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_DISABLED);
            UIEventController.Instance.DispatchUIEvent(MenuScreenController.EVENT_MENUEVENTCONTROLLER_CREATED_NEW_GAME, 1);
            CardboardLoaderVR.Instance.SaveEnableCardboard(false);
            MenuScreenController.Instance.LoadCustomGameScreenOrCreateGame(false, 1, "", null);
#else
            if (MenuScreenController.Instance.AlphaAnimationNameStack != -1)
            {
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_LAYER_GENERIC_SCREEN, -1, new List <object> {
                    ScreenController.ANIMATION_ALPHA, 0f, 1f, MenuScreenController.Instance.AlphaAnimationNameStack
                }, ScreenMenuLocalGameView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
            }
            else
            {
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenMenuLocalGameView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, m_nameOfScreen);
            }
#endif
        }
Exemplo n.º 8
0
        // -------------------------------------------

        /*
         * PlayInVRPressed
         */
        private void EnableBackgroundVR()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            MultiplayerConfiguration.SaveEnableBackground(true);

            MenuScreenController.Instance.LoadGameScene(this);
        }
Exemplo n.º 9
0
        // -------------------------------------------

        /*
         * 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
        }
Exemplo n.º 10
0
        // -------------------------------------------

        /*
         * Will create a new room for lobby
         */
        public void MenuController_CreateNewLobbyRoom(string _nameLobby, int _finalNumberOfPlayers, string _extraData)
        {
            MultiplayerConfiguration.SaveNameRoomLobby(_nameLobby);
#if ENABLE_BALANCE_LOADER
            UIEventController.Instance.DispatchUIEvent(MenuScreenController.EVENT_MENUEVENTCONTROLLER_SHOW_LOADING_MESSAGE);
            CommsHTTPConfiguration.CreateNewRoom(true, _nameLobby, ClientTCPEventsController.GetPlayersString(_finalNumberOfPlayers), _extraData);
#else
            MenuController_CreateRoomForLobby(_nameLobby, _finalNumberOfPlayers, _extraData);
#endif
        }
Exemplo n.º 11
0
        // -------------------------------------------

        /*
         * Informs if the object belongs to the local player
         */
        public bool IsLocalPlayer()
        {
            if (MultiplayerConfiguration.LoadNumberOfPlayers() != 1)
            {
                return(CommunicationsController.Instance.NetworkID == NetID);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 12
0
        // -------------------------------------------

        /*
         * Will load the game scene after 1 second delay
         */
        public void MenuController_LoadGameScene(string _targetScene)
        {
            if (m_targetScene.Length == 0)
            {
                m_targetScene = _targetScene;
#if ENABLE_OCULUS || ENABLE_WORLDSENSE || ENABLE_HTCVIVE || ENABLE_PICONEO
                MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_DISABLED);
#endif
                StartCoroutine(LoadScene());
            }
        }
        // -------------------------------------------

        /*
         * Check it the actor belongs to the current player
         */
        public bool IsMine()
        {
            if (MultiplayerConfiguration.LoadNumberOfPlayers() != 1)
            {
                return(YourNetworkTools.Instance.GetUniversalNetworkID() == NetworkID.NetID);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 14
0
        // -------------------------------------------

        /*
         * Will create a new room for friends
         */
        public void MenuController_CreateNewFacebookRoom(string _friends, List <string> _friendsIDs, string _extraData)
        {
#if ENABLE_BALANCE_LOADER
            UIEventController.Instance.DispatchUIEvent(MenuScreenController.EVENT_MENUEVENTCONTROLLER_SHOW_LOADING_MESSAGE);
            MultiplayerConfiguration.SaveFriendsGame(_friends);
            MultiplayerConfiguration.SaveNumberOfPlayers(_friends.Split(',').Length);
            CommsHTTPConfiguration.CreateNewRoom(false, FacebookController.Instance.NameHuman, _friends, _extraData);
#else
            ClientTCPEventsController.Instance.CreateRoomForFriends(_friendsIDs.ToArray(), _extraData);
#endif
        }
Exemplo n.º 15
0
        // -------------------------------------------

        /*
         * SelectedLevel
         */
        private void SelectedLevel()
        {
            if (m_indexSelected == -1)
            {
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_INFORMATION_SCREEN, ScreenInformationView.SCREEN_INFORMATION, UIScreenTypePreviousAction.KEEP_CURRENT_SCREEN, LanguageController.Instance.GetText("message.warning"), LanguageController.Instance.GetText("message.you.should.select.an.item"), null, "");
            }
            else
            {
                SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
                MultiplayerConfiguration.SaveLevel6DOF(m_indexSelected);
                NextScreen();
            }
        }
Exemplo n.º 16
0
        // -------------------------------------------

        /*
         * PlayInVRPressed
         */
        private void PlayWithARCore()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            MultiplayerConfiguration.SaveGoogleARCore(MultiplayerConfiguration.GOOGLE_ARCORE_ENABLED);
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENARCORE_ENABLED_ARCORE, true);
                GoBackPressed();
            }
            else
            {
                MenuScreenController.Instance.LoadGameScene(this);
            }
        }
        // -------------------------------------------

        /*
         * PlayAsCustomer
         */
        private void PlayAsCustomer()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_DISABLED);
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENDIRECTORMODE_SELECTED_PROFILE, FunctionsScreenController.PROFILE_PLAYER.PLAYER);
                GoBackPressed();
            }
            else
            {
                NextscreenForPlayAsCustomer();
            }
        }
        // -------------------------------------------

        /*
         * Will dispatch an event that will destroy the object in all the network
         */
        void OnDestroy()
        {
#if DEBUG_MODE_DISPLAY_LOG
            Debug.LogError("[ActorNetwork] ++SEND++ SIGNAL FOR AUTODESTRUCTION");
#endif
            if (NetworkEventController.Instance != null)
            {
                NetworkEventController.Instance.NetworkEvent -= OnNetworkEvent;
            }

            if (MultiplayerConfiguration.LoadNumberOfPlayers() != 1)
            {
                NetworkEventController.Instance?.DispatchNetworkEvent(NetworkEventController.EVENT_WORLDOBJECTCONTROLLER_DESTROY_REQUEST, NetworkID.NetID.ToString(), NetworkID.UID.ToString());
            }
        }
        // -------------------------------------------

        /*
         * LoadGame
         */
        private void LoadGame(bool _setLevel)
        {
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENCHARACTERSELECTION_SELECTED_CHARACTER, m_indexSelected);
                GoBackPressed();
            }
            else
            {
#if ENABLE_SELECT_LEVEL
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenLevelSelectionView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
#elif ENABLE_GOOGLE_ARCORE
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenEnableARCore.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
#else
                MultiplayerConfiguration.SaveGoogleARCore(MultiplayerConfiguration.GOOGLE_ARCORE_DISABLED);
                MenuScreenController.Instance.LoadGameScene(this);
#endif
            }
        }
        // -------------------------------------------

        /*
         * PlayAsSpectator
         */
        private void PlayAsSpectator()
        {
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENDIRECTORMODE_SELECTED_PROFILE, FunctionsScreenController.PROFILE_PLAYER.SPECTATOR);
                GoBackPressed();
            }
            else
            {
                if (NetworkEventController.Instance.MenuController_LoadNumberOfPlayers() == MultiplayerConfiguration.VALUE_FOR_JOINING)
                {
                    MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_ENABLED);
                    MultiplayerConfiguration.SaveSpectatorMode(MultiplayerConfiguration.SPECTATOR_MODE_ENABLED);
                    CardboardLoaderVR.Instance.SaveEnableCardboard(false);
                    MultiplayerConfiguration.SaveGoogleARCore(MultiplayerConfiguration.GOOGLE_ARCORE_DISABLED);

                    MenuScreenController.Instance.LoadGameScene(this);
                }
            }
        }
        // -------------------------------------------

        /*
         * PlayAsDirector
         */
        private void PlayAsDirector()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_ENABLED);
            MultiplayerConfiguration.SaveGoogleARCore(MultiplayerConfiguration.GOOGLE_ARCORE_DISABLED);
            CardboardLoaderVR.Instance.SaveEnableCardboard(false);
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENDIRECTORMODE_SELECTED_PROFILE, FunctionsScreenController.PROFILE_PLAYER.DIRECTOR);
                GoBackPressed();
            }
            else
            {
                if (NetworkEventController.Instance.MenuController_LoadNumberOfPlayers() != MultiplayerConfiguration.VALUE_FOR_JOINING)
                {
                    MultiplayerConfiguration.SaveCharacter6DOF(0);
                    MultiplayerConfiguration.SaveLevel6DOF(0);
                }

                MenuScreenController.Instance.LoadGameScene(this);
            }
        }
Exemplo n.º 22
0
        // -------------------------------------------

        /*
         * Start looking for a server to work as a client
         */
        private void Start()
        {
            Debug.Log("NetworkDiscoveryUNET::START!!!!");

            if (MultiplayerConfiguration.LoadNumberOfPlayers() == 1)
            {
                broadcastData       = Utilities.RandomCodeGeneration(UnityEngine.Random.Range(0, 10).ToString());
                broadcastKey        = UnityEngine.Random.Range(2000, 6000);
                broadcastPort       = UnityEngine.Random.Range(20000, 90000);
                broadcastSubVersion = UnityEngine.Random.Range(1, 9);

                NetworkEventController.Instance.DelayLocalEvent(NetworkEventController.EVENT_COMMUNICATIONSCONTROLLER_REGISTER_ALL_NETWORK_PREFABS, 0.2f);
                BasicSystemEventController.Instance.DelayBasicSystemEvent(CommunicationsController.EVENT_COMMSCONTROLLER_SET_UP_IS_SERVER, 0.3f);
                return;
            }


            // Initializes NetworkDiscovery.
            Initialize();

            if (!CheckComponents())
            {
                Debug.Log("Invalid configuration detected. Network Discovery disabled.");
                Destroy(this);
                return;
            }

            broadcastInterval = BroadcastInterval;

            // Start listening for broadcasts.
            StartAsClient();

            float InvokeWaitTime = 3 * BroadcastInterval + Random.value * 3 * BroadcastInterval;

            Invoke("MaybeInitAsServer", InvokeWaitTime * 0.001f);

            NetworkEventController.Instance.NetworkEvent += new NetworkEventHandler(OnBasicEvent);
        }
        // -------------------------------------------

        /*
         * OnLocalPartyGame
         */
        private void OnLocalPartyGame()
        {
            if (MenuScreenController.Instance.EnableAppOrganization)
            {
                UIEventController.Instance.DispatchUIEvent(EVENT_SCREENMAIN_LOCAL_OR_REMOTE_PARTY, true);
                GoBackPressed();
            }
            else
            {
                NetworkEventController.Instance.MenuController_SetLocalGame(true);
                SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);

#if UNITY_STANDALONE
                CardboardLoaderVR.Instance.SaveEnableCardboard(false);
                MultiplayerConfiguration.SaveDirectorMode(MultiplayerConfiguration.DIRECTOR_MODE_DISABLED);
                MultiplayerConfiguration.SaveGoogleARCore(MultiplayerConfiguration.GOOGLE_ARCORE_DISABLED);
                MenuScreenController.Instance.ScreenGameOptions = ScreenCharacterSelectionView.SCREEN_NAME;
                MenuScreenController.Instance.CreateRoomInServer(1, MultiplayerConfiguration.LoadExtraData());
#else
                UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenMenuLocalGameView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
#endif
            }
        }
        // -------------------------------------------

        /*
         * Returns the network identificator independently if it's a local or a remote game
         */
        public int GetUniversalNetworkID()
        {
            if (IsLocalGame)
            {
                if (MultiplayerConfiguration.LoadNumberOfPlayers() != 1)
                {
                    return(CommunicationsController.Instance.NetworkID);
                }
                else
                {
                    return(1);
                }
            }
            else
            {
#if ENABLE_PHOTON
                return(PhotonController.Instance.UniqueNetworkID);
#elif ENABLE_NAKAMA
                return(NakamaController.Instance.UniqueNetworkID);
#else
                return(ClientTCPEventsController.Instance.UniqueNetworkID);
#endif
            }
        }
Exemplo n.º 25
0
        // -------------------------------------------

        /*
         * We save the IP address we should connect
         */
        public void MenuController_SaveIPAddressServer(string _value)
        {
            MultiplayerConfiguration.SaveIPAddressServer(_value);
        }
Exemplo n.º 26
0
        // -------------------------------------------

        /*
         * Will save the ID of the machine which is hosting the room
         */
        public void MenuController_SaveMachineIDServer(int _value)
        {
            MultiplayerConfiguration.SaveMachineIDServer(_value);
        }
        // -------------------------------------------

        /*
         * CreateGamePressed
         */
        public void CreateGamePressed()
        {
            SoundsController.Instance.PlaySingleSound(SoundsConfiguration.SOUND_SELECTION_FX);
            if (MenuScreenController.Instance.ForceFixedPlayers != -1)
            {
                MenuScreenController.Instance.CreateRoomInServer(MenuScreenController.Instance.ForceFixedPlayers, MultiplayerConfiguration.LoadExtraData());
            }
            else
            {
                if (MenuScreenController.Instance.AlphaAnimationNameStack != -1)
                {
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_LAYER_GENERIC_SCREEN, -1, new List <object> {
                        ScreenController.ANIMATION_ALPHA, 0f, 1f, MenuScreenController.Instance.AlphaAnimationNameStack
                    }, ScreenMenuNumberPlayersView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
                }
                else
                {
                    UIEventController.Instance.DispatchUIEvent(UIEventController.EVENT_SCREENMANAGER_OPEN_GENERIC_SCREEN, ScreenMenuNumberPlayersView.SCREEN_NAME, UIScreenTypePreviousAction.DESTROY_ALL_SCREENS, false, null);
                }
            }
        }
        // -------------------------------------------

        /*
         * 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);
        }
        // -------------------------------------------

        /*
         * UnPack a communication received and dispatch it to the system
         */
        public void UnPackEventAndDispatch(string _package)
        {
#if DEBUG_MODE_DISPLAY_LOG
            Debug.LogError("****UnPackEventAndDispatch::_package=" + _package);
#endif

            // PROCESS ALL THE OTHER EVENTS
            string[] parameters = _package.Split(TOKEN_SEPARATOR_EVENTS);
            string   nameEvent  = parameters[0];

            // PROCESS PACKAGE
            if (m_uniqueNetworkID != -1)
            {
                if (parameters.Length > 3)
                {
                    int uniqueNetworkID = int.Parse(parameters[1]);
                    if (uniqueNetworkID == m_uniqueNetworkID)
                    {
                        // Debug.LogError("ClientTCPEventsController::EVENT[" + nameEvent + "] IGNORED BECAUSE IT CAME FROM THIS ORIGIN");
                        return;
                    }

                    int      originNetworkID = int.Parse(parameters[2]);
                    int      targetNetworkID = int.Parse(parameters[3]);
                    string[] list            = new string[parameters.Length - 4];
                    for (int i = 4; i < parameters.Length; i++)
                    {
                        list[i - 4] = parameters[i];
                    }

                    NetworkEventController.Instance.DispatchCustomNetworkEvent(nameEvent, true, originNetworkID, targetNetworkID, list);
                }
            }
            else
            {
                // RETRIEVE THE UNIQUE NETWORK IDENTIFICATOR
                if (nameEvent == EVENT_CLIENT_TCP_ESTABLISH_NETWORK_ID)
                {
                    m_room      = int.Parse(parameters[4]);
                    m_uidPlayer = parameters[5];
#if DEBUG_MODE_DISPLAY_LOG
                    Debug.LogError("EVENT_CLIENT_TCP_ESTABLISH_NETWORK_ID::HAS BEEN ASSIGNED AVAILABLE ROOM[" + m_room + "]++++++++++");
#endif

                    m_events.Add(Pack(EVENT_CLIENT_TCP_PLAYER_UID, -1, -1, (MultiplayerConfiguration.LoadIsRoomLobby() ? m_uidPlayer : FacebookController.Instance.Id)));

                    if (GameObject.FindObjectOfType <YourNetworkTools>() == null)
                    {
                        UIEventController.Instance.DispatchUIEvent(EVENT_CLIENT_TCP_ESTABLISH_NETWORK_ID, m_room);
                    }
                    else
                    {
                        NetworkEventController.Instance.DelayLocalEvent(EVENT_CLIENT_TCP_ESTABLISH_NETWORK_ID, 1f, m_room);
                    }
                }
                else
                {
                    if (nameEvent == EVENT_CLIENT_TCP_LIST_OF_GAME_ROOMS)
                    {
                        string[] roomsInvited = parameters[4].Split(TOKEN_SEPARATOR_PARTY);
                        m_roomsInvited.Clear();
                        m_roomsLobby.Clear();
                        for (int i = 0; i < roomsInvited.Length; i++)
                        {
                            string[] dataParty = roomsInvited[i].Split(TOKEN_SEPARATOR_PLAYERS_IDS);
                            if (dataParty.Length > 1)
                            {
                                if (int.Parse(dataParty[0]) == 0)
                                {
                                    m_roomsInvited.Add(new ItemMultiTextEntry(dataParty));
                                }
                                else
                                {
                                    m_roomsLobby.Add(new ItemMultiTextEntry(dataParty));
                                }
                            }
                        }
                        UIEventController.Instance.DispatchUIEvent(EVENT_CLIENT_TCP_LIST_OF_GAME_ROOMS);
                    }
                    else
                    {
                        if (nameEvent == EVENT_CLIENT_TCP_CONNECTED_ROOM)
                        {
                            m_uniqueNetworkID = int.Parse(parameters[4]);
                            m_idNetworkServer = int.Parse(parameters[5]);
                            int totalNumberPlayers = int.Parse(parameters[6]);
                            NetworkEventController.Instance.DispatchLocalEvent(NetworkEventController.EVENT_SYSTEM_INITIALITZATION_LOCAL_COMPLETED, m_uniqueNetworkID);
                            BasicSystemEventController.Instance.DispatchBasicSystemEvent(CommunicationsController.EVENT_COMMSCONTROLLER_SET_UP_IS_SERVER);
                            UIEventController.Instance.DispatchUIEvent(EVENT_CLIENT_TCP_CONNECTED_ROOM, totalNumberPlayers);
#if DEBUG_MODE_DISPLAY_LOG
                            Debug.LogError("EVENT_CLIENT_TCP_CONNECTED_ROOM::ASSIGNED LOCAL CLIENT NUMBER[" + m_uniqueNetworkID + "] IN THE ROOM[" + m_room + "] WHERE THE SERVER IS[" + m_idNetworkServer + "]++++++++++");
#endif
                        }
                    }
                }
            }
        }
        // -------------------------------------------

        /*
         * Manager of global events
         */
        private void OnNetworkEvent(string _nameEvent, bool _isLocalEvent, int _networkOriginID, int _networkTargetID, params object[] _list)
        {
            if (_nameEvent == EVENT_YOURNETWORKTOOLS_INITIALITZATION_DATA)
            {
                string         targetNetworkID    = (string)_list[0];
                string         initialDataNetwork = (string)_list[1];
                ActorNetwork[] networkActors      = GameObject.FindObjectsOfType <ActorNetwork>();
                // Debug.LogError("+++++++++++++EVENT_YOURNETWORKTOOLS_INITIALITZATION_DATA::TARGET[" + targetNetworkID + "]::data[" + initialDataNetwork + "]::TOTAL NETWORK ACTORS["+ networkActors.Length + "]");
                for (int i = 0; i < networkActors.Length; i++)
                {
                    IGameNetworkActor networkActor = networkActors[i].GetComponentInParent <IGameNetworkActor>();
                    if (networkActor != null)
                    {
                        if (networkActor.NetworkID.CheckID(targetNetworkID))
                        {
                            networkActor.Initialize(initialDataNetwork);
                        }
                    }
                }
            }
            if (_nameEvent == ClientTCPEventsController.EVENT_CLIENT_TCP_ESTABLISH_NETWORK_ID)
            {
#if ENABLE_BALANCE_LOADER
                int totalPlayersConfigurated = MultiplayerConfiguration.LoadNumberOfPlayers();
                if (totalPlayersConfigurated != MultiplayerConfiguration.VALUE_FOR_JOINING)
                {
                    string friends = MultiplayerConfiguration.LoadFriendsGame();
                    if (friends.Length > 0)
                    {
                        string[] friendIDs   = friends.Split(',');
                        int      idRoomLobby = MultiplayerConfiguration.LoadRoomNumberInServer(-1);
                        ClientTCPEventsController.Instance.CreateRoomForFriends(idRoomLobby, friendIDs, "");
                    }
                    else
                    {
                        string nameRoomLobby = MultiplayerConfiguration.LoadNameRoomLobby();
                        if (nameRoomLobby.Length > 0)
                        {
                            int idRoomLobby = MultiplayerConfiguration.LoadRoomNumberInServer(-1);
                            ClientTCPEventsController.Instance.CreateRoomForLobby(idRoomLobby, nameRoomLobby, totalPlayersConfigurated, "");
                        }
                        else
                        {
                            throw new Exception("THERE IS NO NAME OF LOBBY TO CREATE A TCP CONNECTION");
                        }
                    }
                }
                else
                {
                    int idRoomLobby = MultiplayerConfiguration.LoadRoomNumberInServer(-1);
                    if (idRoomLobby != -1)
                    {
                        if (MultiplayerConfiguration.LoadIsRoomLobby())
                        {
                            ClientTCPEventsController.Instance.JoinRoomOfLobby(idRoomLobby, "null", "");
                        }
                        else
                        {
                            ClientTCPEventsController.Instance.JoinRoomForFriends(idRoomLobby, "null", "");
                        }
                    }
                    else
                    {
                        throw new Exception("NO GOOD");
                    }
                }
#endif
            }
            if (_nameEvent == ClientTCPEventsController.EVENT_CLIENT_TCP_CONNECTED_ROOM)
            {
                // Debug.LogError("EVENT_CLIENT_TCP_CONNECTED_ROOM::UniversalUniqueID[" + GetUniversalNetworkID() + "]");
            }
            if (_nameEvent == NetworkEventController.EVENT_SYSTEM_INITIALITZATION_REMOTE_COMPLETED)
            {
                if (IsServer)
                {
                    // Debug.LogError("++++++++++++++++++++SENDING INFORMATION ABOUT ALL EXISTING NETWORK OBJECTS+++++++++++++++++++++++++++++");
                    CheckInitializationObjects();
                }
            }
            if (_nameEvent == NetworkEventController.EVENT_WORLDOBJECTCONTROLLER_LOCAL_CREATION_CONFIRMATION)
            {
                if (IsServer)
                {
                    string keyNetworkGO = (string)_list[0];
                    CheckInitializationObjects(keyNetworkGO);
                }
            }
            if (_nameEvent == NetworkEventController.EVENT_WORLDOBJECTCONTROLLER_INITIAL_DATA)
            {
                if (IsServer)
                {
                    if (!m_initialData.ContainsKey((string)_list[0]))
                    {
                        string keyNetworkGO  = (string)_list[0];
                        string dataNetworkGO = (string)_list[1];
                        m_initialData.Add(keyNetworkGO, dataNetworkGO);
                        // Debug.LogError("*************************************DATA ADDED TO LIST(" + keyNetworkGO + ")("+ dataNetworkGO + ")::TOTAL INITIAL DATA["+ m_initialData.Count + "]::TOTAL TCP PLAYERS["+m_tcpNetworkObjects.Count+"]");
                        CheckInitializationObjects(keyNetworkGO);
                    }
                }
            }
            if (_nameEvent == EVENT_YOURNETWORKTOOLS_NETID_NEW)
            {
                if (IsServer)
                {
                    // Debug.LogError("*************************************NEW TCP NETWORK OBJECT REGISTERED(" + m_tcpNetworkObjects.Count + "]");
                    CheckInitializationObjects();
                }
            }
            if (_nameEvent == NetworkEventController.EVENT_WORLDOBJECTCONTROLLER_DESTROY_REQUEST)
            {
                DestroyNetworkObject(int.Parse((string)_list[0]), int.Parse((string)_list[1]));
            }
            if (_nameEvent == NetworkEventController.EVENT_COMMUNICATIONSCONTROLLER_CREATION_CONFIRMATION_NETWORK_OBJECT)
            {
#if !DISABLE_UNET_COMMS
                m_unetNetworkObjects.Add(new NetworkWorldObject((GameObject)_list[0]));
#endif
            }
            if (_nameEvent == NetworkEventController.EVENT_PLAYERCONNECTIONDATA_USER_DISCONNECTED)
            {
                Debug.Log("----------------------DISCONNECTED PLAYER[" + (int)_list[0] + "]");
            }
#if ENABLE_PHOTON
            if (_nameEvent == EVENT_YOURNETWORKTOOLS_CREATED_GAMEOBJECT)
            {
                GameObject newGO = (GameObject)_list[0];
                if (!m_tcpNetworkObjects.Contains(newGO))
                {
                    m_tcpNetworkObjects.Add(newGO);
                    NetworkEventController.Instance.DispatchLocalEvent(EVENT_YOURNETWORKTOOLS_NETID_NEW);
                }
            }
#endif
            if (_nameEvent == ClientTCPEventsController.EVENT_CLIENT_TCP_TRANSFORM_DATA)
            {
                int        NetID             = (int)_list[0];
                int        UID               = (int)_list[1];
                int        prefabIndex       = (int)_list[2];
                Vector3    position          = (Vector3)_list[3];
                Vector3    forward           = (Vector3)_list[4];
                Vector3    scale             = (Vector3)_list[5];
                object     networkObject     = GetNetworkObjectByID(NetID, UID);
                GameObject networkGameObject = null;
                if (networkObject == null)
                {
                    m_networkIDReceived = NetID;
                    networkGameObject   = Utilities.AddChild(this.gameObject.transform, GetPrefabByName(GameObjects[prefabIndex].name));
                    networkGameObject.GetComponent <NetworkID>().IndexPrefab = GetPrefabIndexOfName(GameObjects[prefabIndex].name);
                    networkGameObject.GetComponent <NetworkID>().NetID       = NetID;
                    networkGameObject.GetComponent <NetworkID>().UID         = UID;
                    m_tcpNetworkObjects.Add(networkGameObject);
                    networkGameObject.transform.position   = position;
                    networkGameObject.transform.forward    = forward;
                    networkGameObject.transform.localScale = scale;
                    NetworkEventController.Instance.DispatchLocalEvent(EVENT_YOURNETWORKTOOLS_NETID_NEW);
                }
                else
                {
                    networkGameObject = (GameObject)networkObject;
                    InterpolatorController.Instance.Interpolate(networkGameObject, position, TimeToUpdateTransforms * 1.01f);
                    InterpolatorController.Instance.InterpolateForward(networkGameObject, forward, TimeToUpdateTransforms * 1.01f);
                    networkGameObject.transform.localScale = scale;
                }
            }
            if (_nameEvent == EVENT_YOURNETWORKTOOLS_DESTROYED_GAMEOBJECT)
            {
                int NetID = (int)_list[1];
                int UID   = (int)_list[2];

                if (IsLocalGame)
                {
#if !DISABLE_UNET_COMMS
                    for (int i = 0; i < m_unetNetworkObjects.Count; i++)
                    {
                        bool removeObject = false;
                        if (m_unetNetworkObjects[i] == null)
                        {
                            removeObject = true;
                        }
                        else
                        {
                            if (m_unetNetworkObjects[i].GetNetworkObjectData() == null)
                            {
                                removeObject = true;
                            }
                        }
                        if (removeObject)
                        {
                            m_unetNetworkObjects.RemoveAt(i);
                        }
                        else
                        {
                            if ((m_unetNetworkObjects[i].GetNetworkObjectData().NetID == NetID) &&
                                (m_unetNetworkObjects[i].GetNetworkObjectData().UID == UID))
                            {
                                m_unetNetworkObjects[i].Destroy();
                                m_unetNetworkObjects.RemoveAt(i);
                                return;
                            }
                        }
                    }
#endif
                }
                else
                {
                    for (int i = 0; i < m_tcpNetworkObjects.Count; i++)
                    {
                        bool removeObject = false;
                        if (m_tcpNetworkObjects[i] == null)
                        {
                            removeObject = true;
                        }
                        if (removeObject)
                        {
                            m_tcpNetworkObjects.RemoveAt(i);
                        }
                        else
                        {
                            if ((m_tcpNetworkObjects[i].GetComponent <NetworkID>().NetID == NetID) &&
                                (m_tcpNetworkObjects[i].GetComponent <NetworkID>().UID == UID))
                            {
                                m_tcpNetworkObjects.RemoveAt(i);
                                return;
                            }
                        }
                    }
                }
            }
        }