Пример #1
0
        /// <summary>
        /// リソース接続.
        /// </summary>
        public AudioController Attach(AudioResource targetResource)
        {
            if (targetResource == null)
            {
                return(null);
            }

            // AudioClipのチェック.
            AudioClip[] clips = targetResource.clips;
            if (clips == null || clips.Length <= 0)
            {
                Debug.LogError("failed to attach AudioResource!! Not found AudioClip's.");
                return(null);
            }

            int dataHandle = EMPTY_DATA;

            for (int idx = 0; idx < m_resourceTable.Length; idx++)
            {
                if (m_resourceTable[idx] == null)
                {
                    m_resourceTable[idx] = targetResource;
                    dataHandle           = idx;
                    break;
                }
            }

            if (dataHandle == EMPTY_DATA)
            {
                Debug.LogError("Failed to attach AudioResource!!");
                return(null);
            }

            return(new AudioController(dataHandle, this));
        }
Пример #2
0
        /// <summary>
        /// 再生.
        /// </summary>
        public void Play(int clipIndex,
                         AudioResource resource,
                         int audioHandle,
                         Transform targetTrans,
                         bool isLoop,
                         float fadeInTime,
                         float volume,
                         bool isTracking,
                         System.Action onPlayEnded)
        {
            float startVolume;

            if (fadeInTime > 0.0f)
            {
                ChangeState(AudioState.FadeIn);
                m_fadeEndTime = fadeInTime;
                m_fadeTimer   = 0.0f;
                startVolume   = 0.0f;
                m_fadeVolume  = volume;
            }
            else
            {
                ChangeState(AudioState.Playing);
                startVolume = volume;
            }

            float spatialBlend = 0.0f;

            if (targetTrans != null)
            {
                spatialBlend = 1.0f;
                m_sourceTrans.localPosition = targetTrans.localPosition;
                m_trackingTrans             = targetTrans;
            }
            else
            {
                m_sourceTrans.localPosition = Vector3.zero;
                m_trackingTrans             = null;
            }

            AudioSource source = m_audioSource;

            source.outputAudioMixerGroup = resource.group;
            source.priority     = resource.priority;
            source.volume       = startVolume;
            source.spatialBlend = spatialBlend;
            source.clip         = resource.clips[clipIndex];
            source.loop         = isLoop;
            source.Play();

            Handle = audioHandle;

            m_onPlayEnded = onPlayEnded;
            m_isTracking  = isTracking;
            m_nowRes      = resource;
        }
Пример #3
0
        /// <summary>
        /// 再生.
        /// </summary>
        public int Play(int dataHandle, int clipIndex, bool isLoop = false, float fadeInTime = 0.0f, float volume = 1.0f, Transform trackingTrans = null, bool isTracking = false, System.Action onPlayEnded = null)
        {
            AudioResource resource = m_resourceTable[dataHandle];

            // 同時発音数制限.
            if (m_numPlayRequestPerFrame >= m_config.simultaneousPlayMax)
            {
                Debug.LogWarning("[AudioManager] Over the number of simultaneous play per frame!! " + clipIndex);
                return(AudioExtensions.EmptyAudioHandle);
            }

            // 空きがあるか
            int freeIdx = (m_freeList.Count - 1);

            if (freeIdx < 0)
            {
                Debug.LogWarning("[AudioManager] Not found free index!! " + clipIndex);
                return(AudioExtensions.EmptyAudioHandle);
            }

            AudioObject audioObj = m_freeList[freeIdx];

            m_freeList.RemoveAt(freeIdx);
            m_activeList.Add(audioObj);

            int audioHandle = MakeAudioHandle(audioObj.Index, clipIndex, dataHandle, (m_activeList.Count - 1));

            audioObj.Play(clipIndex,
                          resource,
                          audioHandle,
                          trackingTrans,
                          isLoop,
                          fadeInTime,
                          volume,
                          isTracking,
                          onPlayEnded);

            m_numPlayRequestPerFrame++;

            return(audioHandle);
        }
Пример #4
0
        /// <summary>
        /// 接続解除.
        /// </summary>
        public void Detach(ref AudioController audioInteface)
        {
            if (audioInteface == null)
            {
                return;
            }

            int dataHandle = audioInteface.DataHandle;

            if (dataHandle == EMPTY_DATA)
            {
                return;
            }

            for (int idx = (m_activeList.Count - 1); idx >= 0; idx--)
            {
                AudioObject audioObj         = m_activeList[idx];
                int         targetDataHandle = ((audioObj.Handle >> BITSHIFT_DATA_HANDLE) & 0xFF);
                if (dataHandle == targetDataHandle)
                {
                    RemoveActiveAudioObject(idx);
                }
            }

            AudioResource targetData = m_resourceTable[dataHandle];

            if (targetData != null)
            {
                AudioClip[] clips = targetData.clips;
                for (int idx = 0; idx < clips.Length; idx++)
                {
                    clips[idx].UnloadAudioData();
                }
            }
            m_resourceTable[dataHandle] = null;

            audioInteface = null;
        }
 void OnEnable()
 {
     res = ( AudioResource )target;
 }
Пример #6
0
 public AudioController AttachVoiceData( AudioResource targetData ){ return m_voicePlayer.Attach( targetData ); }
Пример #7
0
 public AudioController AttachSEData( AudioResource targetData ){ return m_sePlayer.Attach( targetData ); }
Пример #8
0
 public AudioController AttachBgmData( AudioResource data ){ return m_bgmPlayer.Attach( data ); }