IEnumerator Restart() { if (LAN) { LANParty.End(); } else { if (Network.peerType == NetworkPeerType.Server) { MasterServer.UnregisterHost(); } } yield return(new WaitForSeconds(1.0f)); if (Network.peerType != NetworkPeerType.Disconnected) { Debug.Log("Disconnecting..."); Network.Disconnect(); LANParty.log += "\nDisconnected"; } Resources.UnloadUnusedAssets(); SceneManager.LoadScene(SceneManager.GetActiveScene().name); }
// Use this for initialization IEnumerator Start() { if (Application.isWebPlayer) { yield return(Application.RequestUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone)); } Screen.sleepTimeout = SleepTimeout.NeverSleep; VideoChat.SetVideoQuality(videoQuality); VideoChat.SetAudioQuality(audioQuality); VideoChat.SetCompression(compression); VideoChat.SetEchoCancellation(echoCancellation); //Initialize to set base parameters such as the actual WebCamTexture height and width VideoChat.Init(0, framerate); //Add was created in case we need to defer the assignment of a remoteView until after it has been Network instantiated //In this example we are not doing network instantiation but if we were, this would come in handy VideoChat.cameraView = cameraMaterial; VideoChat.Add(remoteView, null, null); if (LAN) { LANParty.Init("MidnightVideoChat", 1); } else { MasterServer.ClearHostList(); MasterServer.RequestHostList("MidnightVideoChat"); hostData = MasterServer.PollHostList(); } //Make some adjustments to the default video chat quad object for this demo, this assumes a Main Camera at the origin if (!remoteView) { VideoChat.vcObject.transform.localScale *= 1.5f; VideoChat.vcObject.transform.position = new Vector3(0, -1.4f, 5); } audioView = gameObject.AddComponent <NetworkView>(); audioView.stateSynchronization = NetworkStateSynchronization.Off; audioView.group = VideoChat.audioGroup; videoView = gameObject.AddComponent <NetworkView>(); videoView.stateSynchronization = NetworkStateSynchronization.Off; videoView.group = VideoChat.videoGroup; }
public void JoinVideoChat() { Debug.Log("Joining video chat server..."); if (LAN) { LANParty.peerType = "client"; LANParty.Broadcast(LANParty.ipRequestString + LANParty.gameName); } else { if (hostData.Length == 0) { hostData = MasterServer.PollHostList(); } } StartCoroutine("DelayedConnection"); }
void OnApplicationQuit() { LANParty.End(); }
void OnGUI() { if (!VideoChat.tempImage && !VideoChat.videoPrimed || !UI) { return; } VideoChat.framerate = framerate; if (!Network.isClient && !Network.isServer) { bool oldTestMode = testMode; testMode = GUI.Toggle(new Rect(0, 20, Screen.width / 3, 40), testMode, "Test Mode"); if (testMode == false && oldTestMode == true) { VideoChat.ClearAudioOut(); } if (testMode) { GUI.Label(new Rect(0, 40, Screen.width, 20), "Mic sensitivity " + audioThreshold); audioThreshold = GUI.HorizontalSlider(new Rect(0, 60, Screen.width, 20), audioThreshold, 0.0f, 1.0f); echoCancel = GUI.Toggle(new Rect(0, 80, Screen.width / 3, 40), echoCancel, "Echo Cancellation"); echoCancellation = (echoCancel == true) ? EchoCancellation.on : EchoCancellation.off; VideoChat.echoCancellation = echoCancellation; } VideoChat.testMode = testMode; if (!testMode) { if (GUI.Button(new Rect(0, 140, Screen.width, 40), "Start")) { if (LAN) { LANParty.peerType = "server"; if (oneToManyBroadcast) { LANParty.possibleConnections = numberReceivers; } else { LANParty.possibleConnections = 1; } LANParty.log += "\n" + Network.InitializeServer(LANParty.possibleConnections, 2301, false); } else { if (oneToManyBroadcast) { Network.InitializeServer(numberReceivers, 2301, true); } else { Network.InitializeServer(1, 2301, true); } MasterServer.RegisterHost("MidnightVideoChat", "Test"); } } if (GUI.Button(new Rect(0, 180, Screen.width, 40), "Join")) { if (LAN) { LANParty.peerType = "client"; LANParty.Broadcast(LANParty.ipRequestString + LANParty.gameName); } else { if (hostData.Length == 0) { hostData = MasterServer.PollHostList(); } } StartCoroutine("DelayedConnection"); } } } else { if (GUI.Button(new Rect(0, 20, Screen.width, 40), "Disconnect")) { StartCoroutine(Restart()); } GUI.Label(new Rect(0, 40, Screen.width, 20), "Friend's mic sensitivity " + audioThreshold); currentAudioThreshold = GUI.HorizontalSlider(new Rect(0, 60, Screen.width, 20), currentAudioThreshold, 0.0f, 1.0f); if (!testMode) { if (currentAudioThreshold != audioThreshold && setAudioThresholdTimer + 0.1f < Time.time) { audioView.RPC("SetAudioThreshold", RPCMode.Others, currentAudioThreshold); audioThreshold = currentAudioThreshold; setAudioThresholdTimer = Time.time; } } if (GUI.Button(new Rect(0, 100, Screen.width, 40), "Change Camera " + VideoChat.deviceIndex)) { VideoChat.deviceIndex++; } echoCancel = GUI.Toggle(new Rect(0, 80, Screen.width / 3, 20), echoCancel, "Echo Cancellation"); echoCancellation = (echoCancel == true) ? EchoCancellation.on : EchoCancellation.off; VideoChat.echoCancellation = echoCancellation; } return; }