예제 #1
0
        /// <summary>
        /// 사운드를 실행합니다. <see cref="SoundSlot"/>을 반환합니다.
        /// </summary>
        /// <param name="strSoundName">플레이할 사운드의 이름</param>
        /// <param name="fLocalVolume">사운드의 볼륨 최종볼륨=(설정 볼륨 * 변수)</param>
        /// <param name="OnFinishSound">사운드가 끝났을 때 이벤트</param>
        public SoundSlot DoPlaySound(string strSoundName, float fLocalVolume, bool bIsLoop, string strSoundCategory = "SoundEffect", System.Action <string> OnFinishSound = null)
        {
            SoundSlot pSoundSlot = _pSlotPool.DoPop(_pSlotOriginal, false);

            pSoundSlot.OnFinish_Sound.DoClear_Observer();

            if (OnFinishSound != null)
            {
                pSoundSlot.OnFinish_Sound.Subscribe_Once += (Args) => OnFinishSound?.Invoke(strSoundName);
            }

            if (_OnGetSoundClip == null)
            {
                Debug.LogError("OnGetSoundClip == null");
                return(null);
            }

            AudioClip pAudioClip = _OnGetSoundClip(strSoundName);

            if (pAudioClip == null)
            {
                _pSlotPool.DoPush(pSoundSlot);
                Debug.LogError($"{nameof(SoundManager)} - Not Found Sound {strSoundName}");
                return(null);
            }

            pSoundSlot.transform.SetParent(instance.transform);
            pSoundSlot.DoInit(strSoundName, pAudioClip, bIsLoop, OnFinish_PlaySound);
            pSoundSlot.ISoundPlayer_PlaySound(Calculate_SoundVolume(strSoundCategory, fLocalVolume));

            AddPlayingSlot(pAudioClip, strSoundCategory, pSoundSlot);

            return(pSoundSlot);
        }
예제 #2
0
        public SoundSlot DoPlaySound_3D(string strSoundName, float fLocalVolume, Vector3 vecPos, bool bIsLoop, string strSoundCategory = "SoundEffect", System.Action <string> OnFinishSound = null)
        {
            SoundSlot pSoundSlot = DoPlaySound(strSoundName, fLocalVolume, bIsLoop, strSoundCategory, OnFinishSound);

            pSoundSlot.transform.position = vecPos;

            return(pSoundSlot);
        }
예제 #3
0
        private void AddPlayingSlot(AudioClip pAudioClip, string strSoundCategory, SoundSlot pSoundSlot)
        {
            _mapPlayingSoundSlot_KeyIs_AudioName.Add_Safe(pAudioClip.name, new List <SoundSlot>());
            _mapPlayingSoundSlot_KeyIs_AudioName[pAudioClip.name].Add(pSoundSlot);

            _mapPlayingSoundSlot_KeyIs_Category.Add_Safe(strSoundCategory, new List <SoundSlot>());
            _mapPlayingSoundSlot_KeyIs_Category[strSoundCategory].Add(pSoundSlot);
        }
예제 #4
0
        /* protected - [abstract & virtual]         */


        // ========================================================================== //

        #region Private

        private void OnFinish_PlaySound(SoundPlayArg obj)
        {
            SoundSlot pSlot = (SoundSlot)obj.pSoundPlayer;

            _pSlotPool.DoPush(pSlot);

            if (string.IsNullOrEmpty(obj.strSoundName) == false && _mapPlayingSoundSlot_KeyIs_AudioName.ContainsKey(obj.strSoundName))
            {
                _mapPlayingSoundSlot_KeyIs_AudioName[obj.strSoundName].Remove(pSlot);
            }
        }
예제 #5
0
        public void ISoundPlayer_PlaySound(float fVolume)
        {
            if (bIs3D)
            {
                pSoundSlot = SoundManager.instance.DoPlaySound_3D(strPlaySoundName, fLocalVolume * fVolume, transform.position, bIsLoop);
            }
            else
            {
                pSoundSlot = SoundManager.instance.DoPlaySound(strPlaySoundName, fLocalVolume * fVolume, bIsLoop);
            }

            pSoundSlot.OnFinish_Sound.Subscribe += _OnFinish_PlaySound.DoNotify;
        }
예제 #6
0
        protected override void OnMakeGameObject(GameObject pObject, CSingletonNotMono pMono)
        {
            base.OnMakeGameObject(pObject, pMono);

            _pSlotPool.transform.SetParent(transform);

            _pSlotOriginal = new GameObject(nameof(SoundSlot) + "_Original").AddComponent <SoundSlot>();
            _pSlotOriginal.transform.SetParent(instance.transform);
            _pSlotOriginal.gameObject.SetActive(false);

            GameObject.DontDestroyOnLoad(instance.gameObject);

            SceneManager.sceneLoaded += OnSceneLoad;

#if UNITY_EDITOR
            pMono.StartCoroutine(CoPlayDebug());
#endif
        }