Beispiel #1
0
    /*
     * IEnumerator LoadDevice(string newDevice)
     * {
     *  if (String.Compare(XRSettings.loadedDeviceName, newDevice, true) != 0)
     *  {
     *      XRSettings.LoadDeviceByName(newDevice);
     *      yield return null;
     *      XRSettings.enabled = true;
     *  }
     * }
     *
     *
     * //http://talesfromtherift.com/googlevr-cardboard-switch-between-normal-mode-and-vr-mode-at-run-time/
     * // https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html
     * void ToggleVR()
     * {
     *
     *  if (XRSettings.loadedDeviceName == "Cardboard")
     *  {
     *    //  XRSettings.enabled = false;
     *      StartCoroutine(LoadDevice("None"));
     *  }
     *  else
     *  {
     *      XRSettings.enabled = true;
     *      Screen.orientation = ScreenOrientation.AutoRotation;
     *      StartCoroutine(LoadDevice("Cardboard"));
     *  }
     *
     *  Debug.Log("XR Settings are: " + XRSettings.enabled);
     *  Debug.Log("active: " + XRSettings.isDeviceActive);
     *  Debug.Log("supported: " + XRSettings.supportedDevices);
     * }
     */
    public void ChangeSceneToServer()
    {
        Debug.Log("Hello serverbutton");
        // Debug.Log("XR Settings are: " + XRSettings.enabled);
        notificationText.text = "Initialising Server";
        if (GameObject.FindWithTag("ClientButton") != null)
        {
            Debug.Log("Client Button found and set false.");
            GameObject.FindWithTag("ClientButton").SetActive(false);
        }
        if (networkManager == null)
        {
            networkManager = MyNetworkManager.getInstance();
            Debug.Log("Networkmanager is null.");
            notificationText.text = "Networkmanager null";
            return;
        }


        TextMeshProUGUI networkAdressText = GameObject.Find("AdressInput_Text").GetComponent <TextMeshProUGUI>();

        networkManager.InitServer();

        // bool waiting = networkManager.GetUDPChat().ConnectAsServer(notificationText.text);
        //  SceneManager.LoadScene("SampleScene");

        Debug.Log("Waiting for Client ...");
        notificationText.text = "Waiting for Client ...";
        networkManager.GetUDPChat().StartListening();


        //    Debug.Log("Address: " + networkManager.GetServerNetworkAdress());
    }
Beispiel #2
0
    public void ChangeSceneToClient()
    {
        Debug.Log("Hello clientbutton");
        notificationText.text = "Init Client ...";

        if (GameObject.FindWithTag("ServerButton") != null)
        {
            Debug.Log("Server Button found and set false.");
            GameObject.FindWithTag("ServerButton").SetActive(false);
        }
        if (networkManager == null)
        {
            Debug.Log("Networkmanager is null.");
            notificationText.text = "Networkmanager null";
        }
        TextMeshProUGUI networkAdressText = GameObject.Find("AdressInput_Text").GetComponent <TextMeshProUGUI>();

        Debug.Log("address text: " + networkAdressText.text);

        networkManager.InitClient(networkAdressText.text);


        // Debug.Log("Address: " + networkManager.GetClientNetworkAdress());

        //  Debug.Log("Is disconnect: " + disconnected);


        //    bool waiting = networkManager.GetUDPChat().ConnectAsClient(notificationText.text);
        //SceneManager.LoadScene("ClientScene");

        notificationText.text = "Client connects to server ...";
        networkManager.GetUDPChat().StartListening();



        /*   if (GameObject.FindWithTag("ServerButton") != null)
         *     GameObject.FindWithTag("ServerButton").SetActive(true);
         */
    }