Beispiel #1
0
        void Start()
        {
            publicRoom = PlayerPrefs.GetInt("isInPublicWorld");
            GameObject Voice = GameObject.FindGameObjectWithTag("Voice");

            PunVoice = Voice.GetComponent <PhotonVoiceNetwork>();
        }
 void OnDestroy()
 {
     if (this.voice != null) // photonView.isMine does not work
     {
         PhotonVoiceNetwork.RemoveLocalVoice(this.voice);
     }
 }
Beispiel #3
0
    private static void Instegrate()
    {
#if PVOICE
        GameObject p1 = bl_GameData.Instance.Player1;
        if (p1.GetComponent <PhotonVoiceView>() == null)
        {
            p1.AddComponent <PhotonVoiceView>().UsePrimaryRecorder = true;
        }
        if (p1.GetComponent <Speaker>() == null)
        {
            p1.AddComponent <Speaker>();
        }
        p1 = bl_GameData.Instance.Player2;
        if (p1.GetComponent <PhotonVoiceView>() == null)
        {
            p1.AddComponent <PhotonVoiceView>().UsePrimaryRecorder = true;
        }
        if (p1.GetComponent <Speaker>() == null)
        {
            p1.AddComponent <Speaker>();
        }
        if (AssetDatabase.IsValidFolder("Assets/MFPS/Scenes"))
        {
            EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
            string path = "Assets/MFPS/Scenes/MainMenu.unity";
            EditorSceneManager.OpenScene(path, OpenSceneMode.Single);
            bl_Lobby lb = FindObjectOfType <bl_Lobby>();
            if (lb != null)
            {
                if (FindObjectOfType <PhotonVoiceNetwork>() == null)
                {
                    GameObject         nobj = new GameObject("PhotonVoice");
                    PhotonVoiceNetwork pvs  = nobj.AddComponent <PhotonVoiceNetwork>();
                    pvs.AutoConnectAndJoin     = true;
                    pvs.AutoLeaveAndDisconnect = true;
                    pvs.ApplyDontDestroyOnLoad = true;
                    Recorder r = nobj.AddComponent <Recorder>();
                    r.MicrophoneType    = Recorder.MicType.Unity;
                    r.TransmitEnabled   = false;
                    r.VoiceDetection    = false;
                    pvs.PrimaryRecorder = r;
                    nobj.AddComponent <bl_PhotonAudioDisabler>().isGlobal = true;
                    EditorUtility.SetDirty(nobj);
                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                }
                Debug.Log("Photon Voice Integrated, enable it on GameData.");
            }
            else
            {
                Debug.Log("Can't found Menu scene.");
            }
        }
        else
        {
            Debug.LogWarning("Can't complete the integration of the addons because MFPS folder structure has been change, please do the manual integration.");
        }
#else
        Debug.LogWarning("Enable Photon Voice addon before integrate.");
#endif
    }
Beispiel #4
0
    public void OnStateChange(LoadBalancing.ClientState state)
    {
        if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
        {
            Debug.Log("PUNVoice: Voice Client state: " + state);
        }
        switch (state)
        {
        case LoadBalancing.ClientState.JoinedLobby:
            if (PhotonNetwork.inRoom)
            {
                this.OpJoinOrCreateRoom(PhotonNetwork.room.name + "_voice_", new LoadBalancing.RoomOptions()
                {
                    IsVisible = false
                }, null);
            }
            else
            {
                Debug.LogWarning("PUNVoice: PUN client is not in room yet. Disconnecting voice client.");
                this.Disconnect();
            }
            break;

        case LoadBalancing.ClientState.Disconnected:     // triggered by PUN room join or network failure
            if (this.reconnect)
            {
                PhotonVoiceNetwork.Connect();
            }
            this.reconnect = false;
            break;
        }
    }
Beispiel #5
0
 private void Update()
 {
     if (this.punVoiceNetwork == null)
     {
         this.punVoiceNetwork = PhotonVoiceNetwork.Instance;
     }
 }
 private void OnDestroy()
 {
     if (this.voice != Voice.LocalVoice.Dummy) // photonView.isMine does not work
     {
         PhotonVoiceNetwork.RemoveLocalVoice(this.voice);
     }
 }
Beispiel #7
0
 // Token: 0x06000025 RID: 37 RVA: 0x00002A18 File Offset: 0x00000C18
 private static bool FallbackSendAckThread()
 {
     if (PhotonVoiceHandler.sendThreadShouldRun && PhotonVoiceNetwork.Client != null && PhotonVoiceNetwork.Client.loadBalancingPeer != null)
     {
         ExitGames.Client.Photon.LoadBalancing.LoadBalancingPeer loadBalancingPeer = PhotonVoiceNetwork.Client.loadBalancingPeer;
         ExitGames.Client.Photon.LoadBalancing.ClientState       state             = PhotonVoiceNetwork.Client.State;
         if (PhotonVoiceHandler.timerToStopConnectionInBackground != null && PhotonVoiceNetwork.BackgroundTimeout > 0.1f && (float)PhotonVoiceHandler.timerToStopConnectionInBackground.ElapsedMilliseconds > PhotonVoiceNetwork.BackgroundTimeout * 1000f)
         {
             bool flag = true;
             if (state == ExitGames.Client.Photon.LoadBalancing.ClientState.PeerCreated || state - ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnecting <= 1 || state == ExitGames.Client.Photon.LoadBalancing.ClientState.ConnectedToNameServer)
             {
                 flag = false;
             }
             if (flag)
             {
                 PhotonVoiceNetwork.Disconnect();
             }
             PhotonVoiceHandler.timerToStopConnectionInBackground.Stop();
             PhotonVoiceHandler.timerToStopConnectionInBackground.Reset();
             return(PhotonVoiceHandler.sendThreadShouldRun);
         }
         if (loadBalancingPeer.ConnectionTime - loadBalancingPeer.LastSendOutgoingTime > 200)
         {
             loadBalancingPeer.SendAcksOnly();
         }
     }
     return(PhotonVoiceHandler.sendThreadShouldRun);
 }
    private void Awake()
    {
        punVoiceNetwork = PhotonVoiceNetwork.Instance;
        PhotonView      = GetComponent <PhotonView>();

        PlayerList = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>().PlayerList;
    }
Beispiel #9
0
 private void OnDestroy()
 {
     PhotonVoiceNetwork.UnlinkSpeakerFromRemoteVoice(this);
     if (this.source != null)
     {
         this.source.Stop();
     }
 }
Beispiel #10
0
 /// <summary>
 /// Check if a player prefab needs to be spawned.
 /// </summary>
 /// <param name="scene"></param>
 /// <param name="scenemode"></param>
 void OnLevelFinishedLoading(Scene scene, LoadSceneMode scenemode)
 {
     PhotonVoiceNetwork.Connect();
     if (PhotonNetwork.inRoom)
     {
         PhotonNetwork.Instantiate("PlayerPrefab", new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), 0);
     }
 }
Beispiel #11
0
    void Awake()
    {
#if !UNITY_EDITOR && UNITY_PS4
        this.player = new PS4AudioOut(() => new AudioStreamPlayer(GetComponent <AudioSource>(), "PUNVoice: PhotonVoiceSpeaker:", PhotonVoiceSettings.Instance.DebugInfo));
#else
        this.player = new AudioStreamPlayer(GetComponent <AudioSource>(), "PUNVoice: PhotonVoiceSpeaker:", PhotonVoiceSettings.Instance.DebugInfo);
#endif
        PhotonVoiceNetwork.LinkSpeakerToRemoteVoice(this);
    }
Beispiel #12
0
 // Token: 0x06000054 RID: 84 RVA: 0x0000331D File Offset: 0x0000151D
 public void Reconnect()
 {
     if (base.State == ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected || base.State == ExitGames.Client.Photon.LoadBalancing.ClientState.PeerCreated)
     {
         PhotonVoiceNetwork.Connect();
         return;
     }
     this.reconnect = true;
     base.Disconnect();
 }
Beispiel #13
0
    internal UnityVoiceClient(PhotonVoiceNetwork network)
    {
        this.OnRemoteVoiceInfoAction   = OnRemoteVoiceInfo;
        this.OnRemoteVoiceRemoveAction = OnRemoteVoiceRemove;
        this.OnAudioFrameAction        = OnAudioFrame;

        this.OnStateChangeAction        = OnStateChange;
        this.OnOpResponseAction         = OnOpResponse;
        this.loadBalancingPeer.DebugOut = DebugLevel.INFO;
    }
    // give user a chance to change MicrophoneDevice in Awake()
    void Start()
    {
        if (photonView.isMine)
        {
            var pvs = PhotonVoiceSettings.Instance;

            Application.RequestUserAuthorization(UserAuthorization.Microphone);
            // put required sample rate into audio source and encoder - both adjust it if needed
            Voice.IBufferReader <float> audioStream;
            int channels           = 0;
            int sourceSamplingRate = 0;
            if (AudioClip == null)
            {
                if (Microphone.devices.Length < 1)
                {
                    // Error already logged in PhotonVoiceNetwork.Awake()
                    return;
                }

                var micDev = this.MicrophoneDevice != null ? this.MicrophoneDevice : PhotonVoiceNetwork.MicrophoneDevice;
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's microphone device to {0}", micDev);
                }
                var mic = new MicWrapper(micDev, (int)pvs.SamplingRate);
                sourceSamplingRate = mic.SourceSamplingRate;
                channels           = mic.Channels;
                audioStream        = mic;
            }
            else
            {
                audioStream        = new AudioClipWrapper(AudioClip);
                sourceSamplingRate = AudioClip.frequency;
                channels           = AudioClip.channels;
                if (this.LoopAudioClip)
                {
                    ((AudioClipWrapper)audioStream).Loop = true;
                }
            }

            Voice.VoiceInfo voiceInfo = Voice.VoiceInfo.CreateAudioOpus(pvs.SamplingRate, sourceSamplingRate, channels, pvs.FrameDuration, pvs.Bitrate, photonView.viewID);
            this.voice                   = PhotonVoiceNetwork.CreateLocalVoice(voiceInfo, audioStream);
            this.VoiceDetector.On        = PhotonVoiceSettings.Instance.VoiceDetection;
            this.VoiceDetector.Threshold = PhotonVoiceSettings.Instance.VoiceDetectionThreshold;
            if (this.voice != Voice.LocalVoiceAudio.Dummy)
            {
                this.voice.Transmit = PhotonVoiceSettings.Instance.AutoTransmit;
            }
            else if (PhotonVoiceSettings.Instance.AutoTransmit)
            {
                Debug.LogWarning("PUNVoice: Cannot Transmit.");
            }
            gameObject.SendMessage("VoiceCreated", new VoiceCreatedParams(this.voiceAudio, voiceInfo), SendMessageOptions.DontRequireReceiver);
        }
    }
Beispiel #15
0
 private void VoiceSwitchOnClick()
 {
     if (PhotonVoiceNetwork.ClientState == ExitGames.Client.Photon.LoadBalancing.ClientState.Joined)
     {
         PhotonVoiceNetwork.Disconnect();
     }
     else if (PhotonVoiceNetwork.ClientState == ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected)
     {
         PhotonVoiceNetwork.Connect();
     }
 }
Beispiel #16
0
 /// <summary>
 /// Trigger reconnect to the (possible other) room.
 /// </summary>
 /// /// <remarks>
 /// When connecting manually, call this to switch Voice client to new voice room if PUN room changed.
 /// </remarks>
 public void Reconnect()
 {
     if (this.State == LoadBalancing.ClientState.Disconnected || this.State == LoadBalancing.ClientState.PeerCreated)
     {
         PhotonVoiceNetwork.Connect();
     }
     else
     {
         this.reconnect = true;
         this.Disconnect();
     }
 }
 private void VoiceSwitchOnClick()
 {
     if (PhotonVoiceNetwork.ClientState == Client.Photon.LoadBalancing.ClientState.Joined)
     {
         PhotonVoiceNetwork.Disconnect();
     }
     else if (PhotonVoiceNetwork.ClientState == Client.Photon.LoadBalancing.ClientState.Uninitialized ||
              PhotonVoiceNetwork.ClientState == Client.Photon.LoadBalancing.ClientState.Disconnected)
     {
         PhotonVoiceNetwork.Connect();
     }
 }
Beispiel #18
0
        // Photon
        void InitializePhoton()
        {
            string gameVersion = UnityEngine.Application.productName + " (" + UnityEngine.Application.version + ")";

            Debug.Log("Connecting to server as: \"" + gameVersion + "\"");

#pragma warning disable 0219
            PhotonVoiceNetwork photonVoiceNetwork = PhotonVoiceNetwork.instance; // Workaround for Photon Voice bug: http://forum.photonengine.com/discussion/7496/photon-voice-debugging
#pragma warning restore 0219
            PhotonNetwork.sendRate            = 40;
            PhotonNetwork.sendRateOnSerialize = 20;
            PhotonNetwork.ConnectUsingSettings(gameVersion);
        }
    // give user a chance to change MicrophoneDevice in Awake()
    void Start()
    {
        if (Microphone.devices.Length < 1)
        {
            return;
        }
        if (photonView.isMine)
        {
            var pvs = PhotonVoiceSettings.Instance;

            Application.RequestUserAuthorization(UserAuthorization.Microphone);
            // put required sample rate into audio source and encoder - both adjust it if needed
            Voice.IAudioStream audioStream;
            int channels = 0;
            if (AudioClip == null)
            {
                var micDev = this.MicrophoneDevice != null ? this.MicrophoneDevice : PhotonVoiceNetwork.MicrophoneDevice;
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.LogFormat("PUNVoice: Setting recorder's microphone device to {0}", micDev);
                }
                var mic = new MicWrapper(micDev, (int)pvs.SamplingRate);
                channels    = mic.Channels;
                audioStream = mic;
            }
            else
            {
                audioStream = new AudioClipWrapper(AudioClip);
                channels    = AudioClip.channels;
                if (this.LoopAudioClip)
                {
                    ((AudioClipWrapper)audioStream).Loop = true;
                }
            }

            Voice.VoiceInfo voiceInfo = new Voice.VoiceInfo((int)pvs.SamplingRate, channels, (int)pvs.FrameDuration, pvs.Bitrate, photonView.viewID);
            this.voice = PhotonVoiceNetwork.CreateLocalVoice(audioStream, voiceInfo);

            this.VoiceDetector.On        = PhotonVoiceSettings.Instance.VoiceDetection;
            this.VoiceDetector.Threshold = PhotonVoiceSettings.Instance.VoiceDetectionThreshold;

            if (this.voice != Voice.LocalVoice.Dummy)
            {
                this.voice.Transmit = PhotonVoiceSettings.Instance.AutoTransmit;
            }
            else if (PhotonVoiceSettings.Instance.AutoTransmit)
            {
                Debug.LogWarning("PUNVoice: Cannot Transmit.");
            }
        }
    }
Beispiel #20
0
        private void OnJoinedRoom()
        {
            Debug.Log(string.Format("[NetworkManager] You joined {0} \n your are the player {1}", PhotonNetwork.room.name, PhotonNetwork.player.ID));

            OnNetworkJoinedRoom.Invoke();

            int viewId = PhotonNetwork.AllocateViewID();

            PhotonNetwork.RaiseEvent(InstantiateVrAvatarEventCode, viewId, true, new RaiseEventOptions()
            {
                CachingOption = EventCaching.AddToRoomCache, Receivers = ReceiverGroup.All
            });

            PhotonVoiceNetwork.Connect();
        }
Beispiel #21
0
    /// <summary>
    /// A function that repeats every second to check games status.
    /// </summary>
    void refreshrep()
    {
        if (PhotonNetwork.connectedAndReady)
        {
            PhotonVoiceNetwork.Connect();
            if (steammangercheck.issteamversion == true && SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagAll) > 0)
            {
                getfriendslist();
            }
            if (PhotonNetwork.playerName != null)
            {
                namedisplaytext.text = "Player Name: " + PhotonNetwork.playerName;
            }
            if (steammangercheck.issteamversion == false)
            {
                steamconnectiontext.text = "Oculus Connected";
            }
            else
            {
                steamconnectiontext.text = "SteamConnection: " + SteamAPI.IsSteamRunning().ToString();
            }
            refresh();
        }
        else if (PhotonNetwork.connectionStateDetailed != ClientState.JoinedLobby)
        {
            counter++;
            if (counter == 3)
            {
                PhotonNetwork.ConnectUsingSettings("1.0");
                counter = 0;
            }
        }
        statustext.text = "status: " + PhotonNetwork.connectionStateDetailed;
        MainMenuValueHolder manvalueholder  = GameObject.Find("MainMenuHolder").GetComponent <MainMenuValueHolder>();
        MainMenuValueHolder manvalueholder2 = GameObject.Find("MainMenuHolder").GetComponent <MainMenuValueHolder>();

        if ((manvalueholder.testarea == true || manvalueholder.tutorial == true || manvalueholder.campaign == true))
        {
            Loading.SetActive(true);
        }
        if ((manvalueholder.testarea == true || manvalueholder.tutorial == true || manvalueholder.campaign == true) && joinedyet == false)
        {
            joinedyet = true;
            onevone();
            Debug.Log("1v1");
        }
    }
Beispiel #22
0
    internal static PhotonVoiceNetwork getInstance()
    {
        lock (instanceLock)
        {
            if (destroyed)
            {
                return(null);
            }
            if (_instance == null)
            {
                _singleton      = new GameObject();
                _instance       = _singleton.AddComponent <PhotonVoiceNetwork>();
                _singleton.name = "PhotonVoiceNetworkSingleton";

                DontDestroyOnLoad(_singleton);
            }
            return(_instance);
        }
    }
    // give user a chance to change MicrophoneDevice in Awake()
    void Start()
    {
        if (photonView.isMine)
        {
            var pvs = PhotonVoiceSettings.Instance;

            if (!this.microphoneDeviceSet)
            {
                this.MicrophoneDevice = PhotonVoiceNetwork.MicrophoneDevice;
            }

            Application.RequestUserAuthorization(UserAuthorization.Microphone);
            // put required sample rate into audio source and encoder - both adjust it if needed
            Voice.IAudioStream audioStream;
            int channels = 0;
            if (AudioClip == null)
            {
                if (PhotonVoiceSettings.Instance.DebugInfo)
                {
                    Debug.Log("PUNVoice: Setting recorder's microphone device to " + this.MicrophoneDevice);
                }
                var mic = new MicWrapper(this.MicrophoneDevice, (int)pvs.SamplingRate);
                this.microphoneDeviceUsed = true;
                channels    = mic.Channels;
                audioStream = mic;
            }
            else
            {
                audioStream = new AudioClipWrapper(AudioClip);
                channels    = AudioClip.channels;
                if (this.LoopAudioClip)
                {
                    ((AudioClipWrapper)audioStream).Loop = true;
                }
            }

            Voice.VoiceInfo voiceInfo = new Voice.VoiceInfo((int)pvs.SamplingRate, channels, (int)pvs.Delay, pvs.Bitrate, photonView.viewID);
            this.voice = PhotonVoiceNetwork.CreateLocalVoice(audioStream, voiceInfo);

            this.VoiceDetector.On        = PhotonVoiceSettings.Instance.VoiceDetection;
            this.VoiceDetector.Threshold = PhotonVoiceSettings.Instance.VoiceDetectionThreshold;
        }
    }
Beispiel #24
0
    public void OnStateChange(LoadBalancing.ClientState state)
    {
        if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
        {
            Debug.LogFormat("PUNVoice: Voice Client state: {0}", state);
        }
        switch (state)
        {
        case LoadBalancing.ClientState.ConnectedToMasterserver:
            if (PhotonNetwork.inRoom)
            {
                this.OpJoinOrCreateRoom(string.Format("{0}_voice_", PhotonNetwork.room.Name),
                                        new LoadBalancing.RoomOptions()
                {
                    IsVisible = false
                }, null);
            }
            else
            {
                Debug.LogWarning("PUNVoice: PUN client is not in room yet. Disconnecting voice client.");
                this.Disconnect();
            }
            break;

        case LoadBalancing.ClientState.Disconnected:     // triggered by PUN room join or network failure
            // PhotonNetwork.SetMasterClient(PhotonNetwork.playerList[0]);
            // Debug.Log("Changed");
            if (this.reconnect)
            {
                PhotonVoiceNetwork.Connect();
            }
            this.reconnect = false;
            break;
        }

        if (this.OnStateChangeAction != null)
        {
            this.OnStateChangeAction(state);
        }
    }
Beispiel #25
0
 // Token: 0x0600005E RID: 94 RVA: 0x00003824 File Offset: 0x00001A24
 public void OnStateChange(ExitGames.Client.Photon.LoadBalancing.ClientState state)
 {
     if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
     {
         Debug.LogFormat("PUNVoice: Voice Client state: {0}", new object[]
         {
             state
         });
     }
     if (state != ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected)
     {
         if (state == ExitGames.Client.Photon.LoadBalancing.ClientState.ConnectedToMasterserver)
         {
             if (PhotonNetwork.inRoom)
             {
                 base.OpJoinOrCreateRoom(string.Format("{0}_voice_", PhotonNetwork.room.Name), new ExitGames.Client.Photon.LoadBalancing.RoomOptions
                 {
                     IsVisible = false
                 }, null, null);
             }
             else
             {
                 Debug.LogWarning("PUNVoice: PUN client is not in room yet. Disconnecting voice client.");
                 base.Disconnect();
             }
         }
     }
     else
     {
         if (this.reconnect)
         {
             PhotonVoiceNetwork.Connect();
         }
         this.reconnect = false;
     }
     if (this.OnStateChangeAction != null)
     {
         this.OnStateChangeAction(state);
     }
 }
        public void OnUpdate()
        {
            if (currentLevelId == 1)
            {
                try
                {
                    if (StartGameScript.playingOnline)
                    {
                        PlayerBody me = PlayerBody.localPlayer;
                        if (voiceToggleButton == null)
                        {
                            createVoiceButton();
                        }

                        if (me != null)
                        {
                            voiceToggleButton.Update(me);
                        }

                        if (voiceToggleButton.buttonPressed)
                        {
                            if (voiceToggleButton.isButtonOn)
                            {
                                PhotonVoiceNetwork.Disconnect();
                            }
                            else
                            {
                                PhotonVoiceNetwork.Connect();
                            }

                            me.DisplayMessageInFrontOfPlayer("Voice  is  " + (voiceToggleButton.isButtonOn ? "off" : "on"));
                        }
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
Beispiel #27
0
    /// <summary>A thread which runs independent from the Update() calls. Keeps connections online while loading or in background. See PhotonVoiceNetwork.BackgroundTimeout.</summary>
    private static bool FallbackSendAckThread()
    {
        if (sendThreadShouldRun && PhotonVoiceNetwork.Client != null && PhotonVoiceNetwork.Client.loadBalancingPeer != null)
        {
            ExitGames.Client.Photon.LoadBalancing.LoadBalancingPeer voicePeer   = PhotonVoiceNetwork.Client.loadBalancingPeer;
            ExitGames.Client.Photon.LoadBalancing.ClientState       clientState = PhotonVoiceNetwork.Client.State;
            // check if the client should disconnect after some seconds in background
            if (timerToStopConnectionInBackground != null && PhotonVoiceNetwork.BackgroundTimeout > 0.1f)
            {
                if (timerToStopConnectionInBackground.ElapsedMilliseconds > PhotonVoiceNetwork.BackgroundTimeout * 1000)
                {
                    bool connected = true;
                    switch (clientState)
                    {
                    case ExitGames.Client.Photon.LoadBalancing.ClientState.PeerCreated:
                    case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected:
                    case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnecting:
                    case ExitGames.Client.Photon.LoadBalancing.ClientState.ConnectedToNameServer:
                        connected = false;
                        break;
                    }
                    if (connected)
                    {
                        PhotonVoiceNetwork.Disconnect();
                    }
                    timerToStopConnectionInBackground.Stop();
                    timerToStopConnectionInBackground.Reset();
                    return(sendThreadShouldRun);
                }
            }

            if (voicePeer.ConnectionTime - voicePeer.LastSendOutgoingTime > 200)
            {
                voicePeer.SendAcksOnly();
            }
        }

        return(sendThreadShouldRun);
    }
Beispiel #28
0
    private void InitialVoiceSetUp()
    {
        var pvs = PhotonVoiceSettings.Instance;

        Application.RequestUserAuthorization(UserAuthorization.Microphone);
        // put required sample rate into audio source and encoder - both adjust it if needed
        Voice.IAudioStream audioStream;
        int channels = 0;

        if (AudioClip == null)
        {
            var micDev = microphoneDevice ?? PhotonVoiceNetwork.MicrophoneDevice ?? (Microphone.devices.Any() ? Microphone.devices.First() : null);
            microphoneDevice = micDev;
            if (PhotonVoiceSettings.Instance.DebugInfo)
            {
                Debug.LogFormat("PUNVoice: Setting recorder's microphone device to {0}", micDev);
            }
            var mic = new MicWrapper(micDev, (int)pvs.SamplingRate);
            channels    = mic.Channels;
            audioStream = mic;
        }
        else
        {
            audioStream = new AudioClipWrapper(AudioClip);
            channels    = AudioClip.channels;
            if (LoopAudioClip)
            {
                ((AudioClipWrapper)audioStream).Loop = true;
            }
        }

        Voice.VoiceInfo voiceInfo = new Voice.VoiceInfo((int)pvs.SamplingRate, channels, (int)pvs.Delay, pvs.Bitrate, photonView.viewID);
        voice                   = PhotonVoiceNetwork.CreateLocalVoice(audioStream, voiceInfo);
        VoiceDetector.On        = PhotonVoiceSettings.Instance.VoiceDetection;
        VoiceDetector.Threshold = PhotonVoiceSettings.Instance.VoiceDetectionThreshold;
        MicrophoneDevice        = microphoneDevice;
    }
Beispiel #29
0
 private void Awake()
 {
     this.punVoiceNetwork = PhotonVoiceNetwork.Instance;
 }
 private void Awake()
 {
     voiceConnection = GetComponent <PhotonVoiceNetwork>();
 }