예제 #1
0
        public void DebugPlay()
        {
            PlayerPrefs.SetInt(PrefsKeys.gameMode, (int)GameMode.TDM);
            PlayerPrefs.SetInt(PrefsKeys.networkMode, (int)NetworkMode.Offline);

            loadingWindow.SetActive(true);
            NetworkManagerCustom.StartMatch((NetworkMode)PlayerPrefs.GetInt(PrefsKeys.networkMode));
            StartCoroutine(HandleTimeout());
        }
예제 #2
0
        /// <summary>
        /// Tries to enter the game scene. Sets the loading screen active while connecting to the
        /// Matchmaker and starts the timeout coroutine at the same time.
        /// </summary>
        public void Play()
        {
            //UnityAnalyticsManager.MainSceneClosed(shopOpened, settingsOpened, musicToggle.isOn,
            //                      Encryptor.Decrypt(PlayerPrefs.GetString(PrefsKeys.activeTank)));

            loadingWindow.SetActive(true);
            NetworkManagerCustom.StartMatch((NetworkMode)PlayerPrefs.GetInt(PrefsKeys.networkMode));
            StartCoroutine(HandleTimeout());
        }
예제 #3
0
        public void Server()
        {
            PlayerPrefs.SetInt(PrefsKeys.gameMode, (int)GameMode.TDM);
            PlayerPrefs.SetInt(PrefsKeys.networkMode, (int)NetworkMode.LAN);

            loadingWindow.SetActive(true);
            NetworkManagerCustom.StartAsServer();
            StartCoroutine(HandleTimeout());
        }
예제 #4
0
        public void HostGroup(int port)
        {
            PlayerPrefs.SetInt(PrefsKeys.gameMode, (int)GameMode.TDM);
            PlayerPrefs.SetInt(PrefsKeys.networkMode, (int)NetworkMode.LAN);

            matchHost.SetActive(false);
            loadingWindow.SetActive(true);
            (NetworkManagerCustom.singleton as NetworkManagerCustom).networkPort = port;
            NetworkManagerCustom.StartAsServer();
            StartCoroutine(HandleTimeout());
        }
예제 #5
0
        public void Client()
        {
            if (CheckUserName() == false)
            {
                return;
            }

            PlayerPrefs.SetInt(PrefsKeys.gameMode, (int)GameMode.TDM);
            PlayerPrefs.SetInt(PrefsKeys.networkMode, (int)NetworkMode.LAN);

            hostClient.SetActive(false);
            serverWindow.gameObject.SetActive(true);
            NetworkManagerCustom.StartAsClient();
        }
예제 #6
0
        void Setup()
        {
            string[] scenes = System.IO.Directory.GetFiles(".", "*.unity", System.IO.SearchOption.AllDirectories);

            if (selectedPackage == Packages.UnityNetworking)
            {
                NetworkManagerCustom           netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.PropertyInfo playerPrefab = netManager.GetType().GetProperty("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"), null);
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");

                Debug.Log("Tanks Multiplayer - Setup Done!");
            }

            if (selectedPackage == Packages.Mirror)
            {
                NetworkManagerCustom        netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.FieldInfo playerPrefab = netManager.GetType().GetField("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"));
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");
            }

            if (selectedPackage == Packages.Mirror && EditorUtility.DisplayDialog("Step 2: Setup Package Contents for Mirror", "Step 2 is a manual step.\n\n" +
                                                                                  "Please open all game scenes and save them once! This is needed so that Unity correctly assigns ViewIDs to networked objects.", "I understand!"))
            {
            }

            if (selectedPackage == Packages.PhotonPUN)
            {
                #if !PUN_2_OR_NEWER
                Debug.LogError("Tanks Multiplayer - Network Setup: Could not find Photon Scripting Define. Did you import Photon yet?");
                #else
                if (EditorUtility.DisplayDialog("Step 2: Setup Package Contents for Photon", "Step 2 is a manual step.\n\n" +
                                                "Please open all game scenes, unpack the 'ObjectSpawner' prefabs and save the scene. This is needed so that Photon correctly assigns ViewIDs to networked objects.\n\n" +
                                                "For a screenshot on what to do, please see our documentation PDF.", "I understand!"))
                {
                }
                #endif
            }

            foreach (string scene in scenes)
            {
                if (scene.EndsWith("Intro.unity"))
                {
                    EditorSceneManager.OpenScene(scene);
                    break;
                }
            }
        }
예제 #7
0
        public void ClientGroup(int port)
        {
            PlayerPrefs.SetInt(PrefsKeys.gameMode, (int)GameMode.TDM);
            PlayerPrefs.SetInt(PrefsKeys.networkMode, (int)NetworkMode.LAN);

            matchClient.SetActive(false);
            NetworkManagerCustom.StartAsClient(false);
            string address = "::ffff:127.0.0.1";

            if (PlayerPrefs.HasKey(PrefsKeys.serverAddress))
            {
                address = "::ffff:" + PlayerPrefs.GetString(PrefsKeys.serverAddress);
            }
            Connect(address, port);
        }
예제 #8
0
        /// <summary>
        /// Stops receiving further network updates which leads to loading the starting scene.
        /// </summary>
        public void Quit()
        {
            int count = 2;

            for (float i = 0; i > count; i += Time.deltaTime)
            {
            }

            OnReUiValue.Invoke();
            PhotonNetwork.Disconnect();
            SceneManager.LoadScene(NetworkManagerCustom.GetInstance().offlineSceneIndex);

            PlayerPrefs.SetFloat(PrefsKeys.cameradistance, camera.distance);
            PlayerPrefs.SetFloat(PrefsKeys.cameraheight, camera.height);
            PlayerPrefs.SetString(PrefsKeys.playMusic, musicToggle.isOn.ToString());
        }
예제 #9
0
        //initialize network view
        void Awake()
        {
            if (instance == null)
            {
                instance = this;
                DontDestroyOnLoad(gameObject);
            }
            else if (instance != this)
            {
                Destroy(gameObject);
                return;
            }

            //adding a view to this gameobject with a unique viewID
            //this is to avoid having the same ID in a scene
            PhotonView view = gameObject.AddComponent <PhotonView>();

            view.ViewID = 999;
        }
예제 #10
0
 /// <summary>
 /// Stops receiving further network updates which leads to loading the starting scene.
 /// </summary>
 public void Quit()
 {
     SceneManager.LoadScene(NetworkManagerCustom.GetInstance().offlineSceneIndex);
 }
예제 #11
0
        void Setup()
        {
            string[] scenes = System.IO.Directory.GetFiles(".", "*.unity", System.IO.SearchOption.AllDirectories);

            if (selectedPackage == Packages.UnityNetworking)
            {
                NetworkManagerCustom           netManager   = (NetworkManagerCustom)AssetDatabase.LoadAssetAtPath("Assets/TanksMultiplayer/Prefabs/Network.prefab", typeof(NetworkManagerCustom));
                System.Reflection.PropertyInfo playerPrefab = netManager.GetType().GetProperty("playerPrefab");
                playerPrefab.SetValue(netManager, Resources.Load("TankFree"), null);
                AssetDatabase.ImportAsset("Assets/TanksMultiplayer/Scripts/GameManager.cs");
            }

            if (selectedPackage == Packages.PhotonPUN)
            {
                #if !PUN_2_OR_NEWER
                Debug.LogError("Tanks Multiplayer - Network Setup: Could not find PhotonViewHandler. Did you import Photon yet?");
                #else
                EditorWindow photonWin = Photon.Pun.PhotonViewHandler.GetWindowWithRect(typeof(Photon.Pun.PhotonViewHandler), new Rect(0, 0, 0, 0));
                System.Reflection.MethodInfo hierarchyMethod = photonWin.GetType().GetMethod("HierarchyChange", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.DeclaredOnly);

                //automatic assignment of PhotonView IDs in non-loaded scenes
                foreach (string scene in scenes)
                {
                    if (scene.EndsWith("Game.unity"))
                    {
                        EditorSceneManager.OpenScene(scene);

                        //we have to disconnect all prefab connections first, because otherwise they can't be manipulated
                        //in the PhotonViewHandler.HierarchyChange method - seems like a Unity bug
                        ObjectSpawner[] objects = FindObjectsOfType(typeof(ObjectSpawner)) as ObjectSpawner[];
                        if (objects == null || objects.Length == 0)
                        {
                            continue;
                        }

                        for (int i = 0; i < objects.Length; i++)
                        {
                            if (PrefabUtility.IsPartOfPrefabInstance(objects[i]))
                            {
                                PrefabUtility.UnpackPrefabInstance(objects[i].gameObject, PrefabUnpackMode.Completely, InteractionMode.AutomatedAction);
                            }
                        }

                        hierarchyMethod.Invoke(photonWin, null);
                        EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), EditorSceneManager.GetActiveScene().path);
                    }
                }

                photonWin.Close();
                #endif
            }

            foreach (string scene in scenes)
            {
                if (scene.EndsWith("Intro.unity"))
                {
                    EditorSceneManager.OpenScene(scene);
                    break;
                }
            }

            Debug.Log("Tanks Multiplayer - Setup Done!");
        }