Exemplo n.º 1
0
    /// <summary>
    /// Plays a clip and returns the active audio source (for later reference). Returns null if no sources available in the pool.
    /// </summary>
    public PooledAudioSource Play(AudioClip clip, AudioPoolType group, string mixerGroup, float volume, float pitch, bool loop, float delay, Action onReturnedToPool)
    {
        PooledAudioSource source = _getFromPool(group);

        if (source == null)
        {
            return(null);
        }

        source.Init(clip, mixerGroup, volume, pitch, loop, onReturnedToPool);
        source.Play(delay);
        return(source);
    }
    /// <summary>
    /// Handle
    /// </summary>
    /// <param name="eventcode"></param>
    /// <param name="content"></param>
    /// <param name="senderid"></param>
    private void _onEvent(byte eventcode, object content, int senderid)
    {
        if (eventcode == (byte)Constants.EVENT_ID.CAN_BROKE)
        {
            // If we are the master client, do this stuff
            if (PhotonNetwork.player.IsMasterClient)
            {
                DebugString("Recieved a network call that the can has broken ON MASTER CLIENT. Sender ID" + senderid.ToString());

                object[] selected = content as object[];
                string   name     = selected[0] as string;

                // Do not allow any other player to say that they broke!
                if (!_isGameOver)
                {
                    GameOverlay.Instance.SetMasterGameOver(name);
                    _isGameOver = true;
                    // Start the countdown for auto restarting
                    StartCoroutine(_countdownRoutine(RestartCountdownLength, false, _restartGame));
                }
                _winnersList.Add(name);
                // TODO: Update the list of winners on the server


                // Play the one shot when someone wins
                if (_musicSource != null)
                {
                    // pause normal music loop
                    _musicSource.Pause();

                    // play the oneshot - once done, resume normal music loop
                    AudioManager.Instance.Play(ServerMusic, AudioPoolType.Music, Constants.Mixer.Mixers.Master.Music.Name, false, () => { _musicSource.Play(); });
                }
                else
                {
                    DebugString("Tried to play winning one shot - but " + _musicSource.ToString() + " was null for some reason.");
                }
                // TODO: Update the list of winners on the server UI
            }
            else
            {
                DebugString("Recieved a network call that the can has broken on normal client.");
                GameOverlay.Instance.SetText("You popped your can!");
                GameOverlay.Instance.FadeIn(0.6f);
            }
        }
    }