예제 #1
0
        public void PlayAudio(AudioCue cue, AudioPlayType type, int priority)   //played from generic sources on cam
        {
            var item = CreateNewVoiceItemFromCue(cue, type, priority);

            item.source = GetAudioSourceForTrack(cue.GetTrack());       //equivalent for source-supplied sounds is to find mixer group and assign source to it

            AttemptAddSoundToList(item);
            ReviewSoundList();
        }
예제 #2
0
        //public void StopSoundtrack()
        //{
        //    soundtrackSource.Stop();
        //}
        #endregion

        #region NEW play audio generic method with different overloads
        public void PlayAudio(AudioCue cue, AudioPlayType type, int priority, AudioSource source)   //played from the supplied source
        {
            var item = CreateNewVoiceItemFromCue(cue, type, priority);

            item.source = source;

            AttemptAddSoundToList(item);
            ReviewSoundList();
        }
예제 #3
0
        public static AudioPlay Create(AudioPlayType playType)
        {
            switch (playType)
            {
            case AudioPlayType.DirectSound: return(new DirectSoundPlay());

            default:
                throw new NotImplementedException();
            }
        }
예제 #4
0
 private bool IsLooping(AudioPlayType type)
 {
     if (type == AudioPlayType.PlayLooped)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #5
0
    /// <summary>
    /// 채널을 초기화합니다.
    /// </summary>
    /// <param name="eChannelType">채널 타입</param>
    /// <param name="nMaxChannel">최대 동시 재생 사운드 오브젝트 수</param>
    public void Init(E_AUDIO_CHANNEL_TYPE eChannelType, int nMaxChannel, Transform trTransform, float fSpatialBlend)
    {
        m_AudioActiveObjectList   = new List <AudioObject>();
        m_AudioDeactiveObjectList = new List <AudioObject>();
        m_AudioObjectList         = new CustomDictionary <string, AudioObject>();

        m_eChannelType    = eChannelType;
        m_nMaxAudioObject = nMaxChannel;
        m_trTransform     = trTransform;
        m_fSpatialBlend   = fSpatialBlend;

        m_AudioActiveObjectList.Clear();
        m_AudioDeactiveObjectList.Clear();

        FillAudioObject(nMaxChannel);
        m_fVolume     = 1.0f;
        m_fFadeVolume = 1.0f;
        m_bMute       = false;
        m_bActive     = true;

        switch (m_eChannelType)
        {
        case E_AUDIO_CHANNEL_TYPE.BGM_Map:
            m_PlayType = new AudioPlayType_Bgm_Map(this);
            m_LoadType = new AudioLoadType_Bgm(m_PlayType);
            break;

        case E_AUDIO_CHANNEL_TYPE.BGM_SPECIAL:
            m_PlayType = new AudioPlayType_Bgm_Special(this);
            m_LoadType = new AudioLoadType_Bgm(m_PlayType);
            break;

        case E_AUDIO_CHANNEL_TYPE.CV_2D:
        case E_AUDIO_CHANNEL_TYPE.CV_3D:
            m_PlayType = new AudioPlayType_Effect(this);
            m_LoadType = new AudioLoadType_CV(m_PlayType);
            break;

        case E_AUDIO_CHANNEL_TYPE.SE:
        case E_AUDIO_CHANNEL_TYPE.UISE:
            m_PlayType = new AudioPlayType_Effect(this);
            m_LoadType = new AudioLoadType_Effect(m_PlayType);
            break;
        }
    }
예제 #6
0
        private VoiceItem CreateNewVoiceItemFromCue(AudioCue cue, AudioPlayType type, int priority)
        {
            priority = Mathf.Clamp(priority, highestPriority, lowestPriority);

            var newClip = cue.SelectClip();

            VoiceItem item = new VoiceItem
            {
                clip      = newClip,
                track     = cue.GetTrack(),
                source    = null,   //to be assigned
                loop      = IsLooping(type),
                length    = newClip.length,
                timeEnds  = Time.time + newClip.length,
                priority  = priority,
                isPlaying = false,
                isGarbage = false
            };

            return(item);
        }
예제 #7
0
    /// <summary>
    /// 오디오를 재생하고 싶으면 사용하세요
    /// </summary>
    /// <param name="_name">재생오디오 이름</param>
    /// <param name="_pos">재생 위치</param>
    /// <param name="_playType">재생 타입 기본 NONE</param>
    public void PlayAudio(string _name, Vector3 _pos, AudioPlayType _playType = AudioPlayType.NONE)
    {
        GameObject _audioSoundObject;

        if (emptyAudioSourceObjects.Count > 0)
        {
            _audioSoundObject = emptyAudioSourceObjects[emptyAudioSourceObjects.Count - 1];
            emptyAudioSourceObjects.Remove(_audioSoundObject);
        }
        else
        {
            _audioSoundObject = Instantiate(audioSoundObject, _pos, Quaternion.identity);
        }
        _audioSoundObject.SetActive(true);
        _audioSoundObject.transform.position = _pos;
        _audioSoundObject.GetComponent <AudioSound>().SetClip(audioDictionary[_name]);
        _audioSoundObject.GetComponent <AudioSound>().Play();

        if (_playType == AudioPlayType.LOOP)
        {
            _audioSoundObject.GetComponent <AudioSound>().LoopOn();
        }
    }
예제 #8
0
    public void LoadAsyncAudioClip(SoundPlayData Data, AudioPlayType PlayType)
    {
        ///해당 그룹에 클립이 있는가? => 해당 그룹에서 클립을 꺼내옴
        ///클립이 없는가? => 저장소에 클립이 있는가? (2)로 없는가? (1)로
        ///(1)로드후 저장소에 추가 => (2)저장소에서 해당 그룹에 클립을 할당
        ///
        ///위의 로직이 완료되면 Play 시작
        ///

        Data.m_PlayType = PlayType;

        AudioClip TargetClip = null;

        if (Data.m_AudioClipGroup.HasAudioClip(Data.m_strSoundFileName, out TargetClip))
        {
            Data.LoadComplete(TargetClip, 0.0f);
            Data.TryPlay();
        }
        else
        {
            ProcessLoad(Data);
        }
    }
        /*! \cond PRIVATE */
        public void PlayARandomSong(AudioPlayType playType, bool isMidsong) {
            if (!ControllerIsReady) {
                Debug.LogError(NotReadyMessage);
                return;
            }

            if (_clipsRemaining.Count == 0) {
                Debug.LogWarning(
                    "There are no clips left in this Playlist. Turn on Loop Playlist if you want to loop the entire song selection.");
                return;
            }

            if (IsCrossFading && playType == AudioPlayType.Schedule) {
                return; // this will kill the crossfade, so abort
            }

            if (isMidsong) {
                _nextSongScheduled = false;
            }

            var randIndex = UnityEngine.Random.Range(0, _clipsRemaining.Count);
            var clipIndex = _clipsRemaining[randIndex];

            switch (playType) {
                case AudioPlayType.PlayNow:
                    RemoveRandomClip(randIndex);
                    break;
                case AudioPlayType.Schedule:
                    _lastRandomClipIndex = randIndex;
                    break;
                case AudioPlayType.AlreadyScheduled:
                    if (_lastRandomClipIndex >= 0) {
                        RemoveRandomClip(_lastRandomClipIndex);
                    }
                    break;
            }

            PlaySong(_currentPlaylist.MusicSettings[clipIndex], playType);
        }
예제 #10
0
 public AudioLoadType(AudioPlayType PlayType)
 {
     m_PlayType = PlayType;
 }
예제 #11
0
    public void SetAudioPlay(UInt64 heroID, AudioPlayType audiotype = AudioPlayType.KillAudio)
    {
        if (!EntityManager.AllEntitys.ContainsKey(heroID))
        {
            return;
        }
        Ientity sEntity = EntityManager.AllEntitys[heroID];

        if (sEntity.GetDistanceToPos(PlayerManager.Instance.LocalPlayer.realObject.transform.position) > 30)
        {
            return;
        }

        HeroConfigInfo info = ConfigReader.GetHeroInfo((int)sEntity.ObjTypeID);

        if (info != null)
        {
            switch (audiotype)
            {
            case AudioPlayType.KillAudio:
            case AudioPlayType.TwentySconde:
            {
                System.Random rand       = new System.Random();
                int           randomdata = rand.Next(2);
                if (randomdata == 1)
                {
                    string           path      = "Audio/HeroSelect/";
                    string           adio_name = "";
                    int              audio_num = rand.Next(100);
                    List <AudioRand> reand     = SetAudioDate(heroID);
                    if (reand.Count < randomdata + 1)
                    {
                        return;
                    }
                    if (audio_num > reand[randomdata].RandNum)
                    {
                        adio_name = reand[1].AudioName;
                    }
                    else
                    {
                        adio_name = reand[0].AudioName;
                    }
                    //int int_hero1 = int.Parse(info.HeroScript1Rate.Substring(0, info.HeroScript1Rate.IndexOf(",")));
                    //if (audio_num < (int_hero1 % 90000)) adio_name = info.HeroScript1.Substring(0, info.HeroScript1.IndexOf(","));
                    //else adio_name = info.HeroScript1.Substring(info.HeroScript1.IndexOf(",") + 1, info.HeroScript1.Length - info.HeroScript1.IndexOf(",") - 1);

                    //AudioClip clip = Resources.Load(path + adio_name) as AudioClip;
                    //AudioManager.Instance.PlayGameKillAudio(clip);

                    ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(path + adio_name, ResourceType.ASSET);
                    AudioClip    clip     = clipUnit.Asset as AudioClip;

                    AudioManager.Instance.PlayGameKillAudio(clip);
                }
            }
            break;

            case AudioPlayType.FuhuoAudio:
            {
                if (info.HeroScript1 != null)
                {
                    string path      = "Audio/HeroSelect/";
                    string adio_name = info.HeroScript1.Substring(info.HeroScript1.IndexOf(",") + 1, info.HeroScript1.Length - info.HeroScript1.IndexOf(",") - 1);

                    ResourceUnit clipUnit = ResourcesManager.Instance.loadImmediate(path + adio_name, ResourceType.ASSET);
                    AudioClip    clip     = clipUnit.Asset as AudioClip;

                    AudioManager.Instance.PlayHeroLinesAudio(heroID, clip);
                }

                //AudioClip clip = Resources.Load(path + adio_name) as AudioClip;
                //AudioManager.Instance.PlayHeroLinesAudio(heroID, clip);
            }
            break;
            }
        }
    }
예제 #12
0
 public AudioLoadType_Effect(AudioPlayType PlayType)
     : base(PlayType)
 {
 }
예제 #13
0
 public AudioLoadType_CV(AudioPlayType PlayType)
     : base(PlayType)
 {
 }
        private void PlayNextOrRandom(AudioPlayType playType) {
            _nextSongRequested = true;

            if (_queuedSongs.Count > 0) {
                PlayFirstQueuedSong(playType);
            } else if (!isShuffle) {
                PlayTheNextSong(playType, false);
            } else {
                PlayARandomSong(playType, false);
            }
        }
        /*! \cond PRIVATE */
        public void PlayTheNextSong(AudioPlayType playType, bool isMidsong) {
            if (_currentPlaylist == null) {
                return;
            }

            if (IsCrossFading && playType == AudioPlayType.Schedule) {
                return; // this will kill the crossfade, so abort
            }

            if (playType != AudioPlayType.AlreadyScheduled && _songsPlayedFromPlaylist > 0 && !_nextSongScheduled) {
                AdvanceSongCounter();
            }

            if (_currentSequentialClipIndex >= _currentPlaylist.MusicSettings.Count) {
                Debug.LogWarning(
                    "There are no clips left in this Playlist. Turn on Loop Playlist if you want to loop the entire song selection.");
                return;
            }

            if (isMidsong) {
                _nextSongScheduled = false;
            }

            PlaySong(_currentPlaylist.MusicSettings[_currentSequentialClipIndex], playType);
        }
        private void PlayFirstQueuedSong(AudioPlayType playType) {
            if (_queuedSongs.Count == 0) {
                Debug.LogWarning("There are zero queued songs in PlaylistController '" + ControllerName +
                                 "'. Cannot play first queued song.");
                return;
            }

            var oldestQueued = _queuedSongs[0];
            _queuedSongs.RemoveAt(0); // remove before playing so the queued song can loop.

            _currentSequentialClipIndex = oldestQueued.songIndex;
            // keep track of which song we're playing so we don't loop playlist if it's not supposed to.
            PlaySong(oldestQueued, playType);
        }
        private void PlaySong(MusicSetting setting, AudioPlayType playType) {
            _newSongSetting = setting;

            if (_activeAudio == null) {
                Debug.LogError("PlaylistController prefab is not in your scene. Cannot play a song.");
                return;
            }

            AudioClip clipToPlay = null;

            var clipWillBeAudibleNow = playType == AudioPlayType.PlayNow || playType == AudioPlayType.AlreadyScheduled;
            if (clipWillBeAudibleNow && _currentSong != null && !CanSchedule) {
                if (_currentSong.songChangedEventExpanded && _currentSong.songChangedCustomEvent != string.Empty &&
                    _currentSong.songChangedCustomEvent != MasterAudio.NoGroupName) {
                    MasterAudio.FireCustomEvent(_currentSong.songChangedCustomEvent, Trans.position);
                }
            }

            if (playType != AudioPlayType.AlreadyScheduled) {
                if (_activeAudio.clip != null) {
                    var newSongName = string.Empty;
                    switch (setting.audLocation) {
                        case MasterAudio.AudioLocation.Clip:
                            if (setting.clip != null) {
                                newSongName = setting.clip.name;
                            }
                            break;
                        case MasterAudio.AudioLocation.ResourceFile:
                            newSongName = setting.resourceFileName;
                            break;
                    }

                    if (string.IsNullOrEmpty(newSongName)) {
                        Debug.LogWarning(
                            "The next song has no clip or Resource file assigned. Please fix. Ignoring song change request.");
                        return;
                    }
                }

                if (_activeAudio.clip == null) {
                    _audioClip = _activeAudio;
                    _transClip = _transitioningAudio;
                } else if (_transitioningAudio.clip == null) {
                    _audioClip = _transitioningAudio;
                    _transClip = _activeAudio;
                } else {
                    // both are busy!
                    _audioClip = _transitioningAudio;
                    _transClip = _activeAudio;
                }

                if (setting.clip != null) {
                    _audioClip.clip = setting.clip;
                    _audioClip.pitch = setting.pitch;
                }

                _audioClip.loop = SongShouldLoop(setting);

                switch (setting.audLocation) {
                    case MasterAudio.AudioLocation.Clip:
                        if (setting.clip == null) {
                            MasterAudio.LogWarning(
                                "MasterAudio will not play empty Playlist clip for PlaylistController '" +
                                ControllerName + "'.");
                            return;
                        }

                        clipToPlay = setting.clip;
                        break;
                    case MasterAudio.AudioLocation.ResourceFile:
                        if (MasterAudio.HasAsyncResourceLoaderFeature() && ShouldLoadAsync) {
                            StartCoroutine(AudioResourceOptimizer.PopulateResourceSongToPlaylistControllerAsync(
                                    setting.resourceFileName, CurrentPlaylist.playlistName, this, playType));
                        } else {
                            clipToPlay = AudioResourceOptimizer.PopulateResourceSongToPlaylistController(
                                ControllerName, setting.resourceFileName, CurrentPlaylist.playlistName);
                            if (clipToPlay == null) {
                                return;
                            }
                        }

                        break;
                }
            } else {
                FinishLoadingNewSong(null, AudioPlayType.AlreadyScheduled);
            }

            if (clipToPlay != null) {
                FinishLoadingNewSong(clipToPlay, playType);
            }
        }
        /*! \cond PRIVATE */
        public void FinishLoadingNewSong(AudioClip clipToPlay, AudioPlayType playType) {
            _nextSongRequested = false;

            var shouldPopulateClip = playType == AudioPlayType.PlayNow || playType == AudioPlayType.Schedule;
            var clipWillBeAudibleNow = playType == AudioPlayType.PlayNow || playType == AudioPlayType.AlreadyScheduled;

            if (shouldPopulateClip) {
                _audioClip.clip = clipToPlay;
                _audioClip.pitch = _newSongSetting.pitch;
            }

            // set last known time for current song.
            if (_currentSong != null) {
                _currentSong.lastKnownTimePoint = _activeAudio.timeSamples;
            }

            if (clipWillBeAudibleNow) {
                if (CrossFadeTime == 0 || _transClip.clip == null) {
                    CeaseAudioSource(_transClip);
                    _audioClip.volume = _newSongSetting.volume * PlaylistVolume;

                    if (!ActiveAudioSource.isPlaying && _currentPlaylist != null &&
                        (_currentPlaylist.fadeInFirstSong && CrossFadeTime > 0f)) {
                        CrossFadeNow(_audioClip);
                    }
                } else {
                    CrossFadeNow(_audioClip);
                }

                SetDuckProperties();
            }

            switch (playType) {
                case AudioPlayType.AlreadyScheduled:
                    // start crossfading now	
                    _nextSongScheduled = false;
                    RemoveScheduledClip();
                    break;
                case AudioPlayType.PlayNow:
                    _audioClip.Play(); // need to play before setting time or it sometimes resets back to zero.
                    _songsPlayedFromPlaylist++;
                    break;
                case AudioPlayType.Schedule:
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
					Debug.LogError("Master Audio cannot do gapless song transition on Unity 3. Please report this bug to Dark Tonic as it should not happen.");
					return;
#else
                    var scheduledPlayTime = CalculateNextTrackStartTime();

                    ScheduleClipPlay(scheduledPlayTime);

                    _nextSongScheduled = true;
                    _songsPlayedFromPlaylist++;
                    break;
#endif
            }

            var songTimeChanged = false;

            // ReSharper disable once PossibleNullReferenceException
            if (syncGroupNum > 0 &&
                _currentPlaylist.songTransitionType == MasterAudio.SongFadeInPosition.SynchronizeClips) {

                var firstMatchingGroupController = Instances.Find(delegate(PlaylistController obj) {
                    return obj != this &&
                           obj.syncGroupNum == syncGroupNum &&
                           obj.ActiveAudioSource != null &&
                           obj.ActiveAudioSource.isPlaying;
                });

                if (firstMatchingGroupController != null) {
                    var matchingTime = firstMatchingGroupController._activeAudio.timeSamples;
                    if (_audioClip.clip != null && matchingTime < _audioClip.clip.samples) {
                        _audioClip.timeSamples = matchingTime;
                    }

                    songTimeChanged = true;
                }
            }

            // this code will adjust the starting position of a song, but shouldn't do so when you first change Playlists.
            if (_currentPlaylist != null) {
                if (_songsPlayedFromPlaylist <= 1 && !songTimeChanged) {
                    _audioClip.timeSamples = 0;
                    // reset pointer so a new Playlist always starts at the beginning, but don't do it for synchronized! We need that first song to use the sync group.
                } else {
                    switch (_currentPlaylist.songTransitionType) {
                        case MasterAudio.SongFadeInPosition.SynchronizeClips:
                            if (!songTimeChanged) {
                                // otherwise the sync group code above will get defeated.
                                _transitioningAudio.timeSamples = _activeAudio.timeSamples;
                            }
                            break;
                        case MasterAudio.SongFadeInPosition.NewClipFromLastKnownPosition:
                            var thisSongInPlaylist = _currentPlaylist.MusicSettings.Find(delegate(MusicSetting obj) {
                                return
                                    obj ==
                                    _newSongSetting;
                            });

                            if (thisSongInPlaylist != null) {
                                _transitioningAudio.timeSamples = thisSongInPlaylist.lastKnownTimePoint;
                            }
                            break;
                        case MasterAudio.SongFadeInPosition.NewClipFromBeginning:
                            _audioClip.timeSamples = 0; // new song will start at beginning
                            break;
                    }
                }

                // account for custom start time.
                if (_currentPlaylist.songTransitionType == MasterAudio.SongFadeInPosition.NewClipFromBeginning &&
                    _newSongSetting.customStartTime > 0f) {
                    // ReSharper disable once PossibleNullReferenceException
                    _audioClip.timeSamples = (int)(_newSongSetting.customStartTime * _audioClip.clip.frequency);
                }
            }

            if (clipWillBeAudibleNow) {
                _activeAudio = _audioClip;
                _transitioningAudio = _transClip;

                // song changed
                if (songChangedCustomEvent != string.Empty && songChangedEventExpanded && songChangedCustomEvent != MasterAudio.NoGroupName) {
                    MasterAudio.FireCustomEvent(songChangedCustomEvent, Trans.position);
                }

                if (SongChanged != null) {
                    var clipName = String.Empty;
                    if (_audioClip != null) {
                        clipName = _audioClip.clip.name;
                    }
                    SongChanged(clipName);
                }
                // song changed end
            }

            _activeAudioEndVolume = _newSongSetting.volume * PlaylistVolume;
            var transStartVol = _transitioningAudio.volume;
            if (_currentSong != null) {
                transStartVol = _currentSong.volume;
            }

            _transitioningAudioStartVolume = transStartVol * PlaylistVolume;
            _currentSong = _newSongSetting;

            if (clipWillBeAudibleNow && _currentSong.songStartedEventExpanded && _currentSong.songStartedCustomEvent != string.Empty && _currentSong.songStartedCustomEvent != MasterAudio.NoGroupName) {
                MasterAudio.FireCustomEvent(_currentSong.songStartedCustomEvent, Trans.position);
            }

            if (CanSchedule && playType != AudioPlayType.Schedule && !_currentSong.isLoop) {
                ScheduleNextSong();
            }
        }