/// <summary>
        /// 初始化播放声音成功事件的新实例。
        /// </summary>
        /// <param name="e">内部事件。</param>
        public PlaySoundSuccessEventArgs(GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo playSoundInfo = e.UserData as PlaySoundInfo;

            SerialId       = e.SerialId;
            SoundAssetName = e.SoundAssetName;
            SoundAgent     = e.SoundAgent;
            BindingEntity  = playSoundInfo.BindingEntity;
            UserData       = playSoundInfo.UserData;
        }
        private void OnPlaySoundSuccess(object sender, GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo playSoundInfo = e.UserData as PlaySoundInfo;

            if (playSoundInfo != null && playSoundInfo.BindingEntity != null)
            {
                e.SoundAgent.SetBindingEntity(playSoundInfo.BindingEntity);
            }

            m_EventComponent.Fire(this, new PlaySoundSuccessEventArgs(e));
        }
        /// <summary>
        /// 填充播放声音成功事件
        /// </summary>
        /// <param name="e">内部事件</param>
        /// <returns>播放声音成功事件</returns>
        public PlaySoundSuccessEventArgs Fill(GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo playSoundInfo = (PlaySoundInfo)e.UserData;

            SerialId       = e.SerialId;
            SoundAssetName = e.SoundAssetName;
            SoundAgent     = e.SoundAgent;
            Duration       = e.Duration;
            BindingEntity  = playSoundInfo.BindingEntity;
            UserData       = playSoundInfo.UserData;

            return(this);
        }
        /// <summary>
        /// 创建播放声音成功事件。
        /// </summary>
        /// <param name="e">内部事件。</param>
        /// <returns>创建的播放声音成功事件。</returns>
        public static PlaySoundSuccessEventArgs Create(GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo             playSoundInfo             = (PlaySoundInfo)e.UserData;
            PlaySoundSuccessEventArgs playSoundSuccessEventArgs = ReferencePool.Acquire <PlaySoundSuccessEventArgs>();

            playSoundSuccessEventArgs.SerialId       = e.SerialId;
            playSoundSuccessEventArgs.SoundAssetName = e.SoundAssetName;
            playSoundSuccessEventArgs.SoundAgent     = e.SoundAgent;
            playSoundSuccessEventArgs.Duration       = e.Duration;
            playSoundSuccessEventArgs.BindingEntity  = playSoundInfo.BindingEntity;
            playSoundSuccessEventArgs.UserData       = playSoundInfo.UserData;
            ReferencePool.Release(playSoundInfo);
            return(playSoundSuccessEventArgs);
        }
        private void OnPlaySoundSuccess(object sender, GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo playSoundInfo = (PlaySoundInfo)e.UserData;

            if (playSoundInfo != null)
            {
                SoundAgentHelperBase soundAgentHelper = (SoundAgentHelperBase)e.SoundAgent.Helper;
                if (playSoundInfo.BindingEntity != null)
                {
                    soundAgentHelper.SetBindingEntity(playSoundInfo.BindingEntity);
                }
                else
                {
                    soundAgentHelper.SetWorldPosition(playSoundInfo.WorldPosition);
                }
            }

            m_EventComponent.Fire(this, PlaySoundSuccessEventArgs.Create(e));
        }
Beispiel #6
0
        private void OnPlaySoundSuccess(object sender, GameFramework.Sound.PlaySoundSuccessEventArgs e)
        {
            PlaySoundInfo playSoundInfo = (PlaySoundInfo)e.UserData;

            if (playSoundInfo != null)
            {
                SoundAgentHelperBase soundAgentHelper = (SoundAgentHelperBase)e.SoundAgent.Helper;
                if (playSoundInfo.BindingEntity != null)
                {
                    soundAgentHelper.SetBindingEntity(playSoundInfo.BindingEntity);
                }
                else
                {
                    soundAgentHelper.SetWorldPosition(playSoundInfo.WorldPosition);
                }
            }

            if (m_EnablePlaySoundSuccessEvent)
            {
                m_EventComponent.Fire(this, ReferencePool.Acquire <PlaySoundSuccessEventArgs>().Fill(e));
            }
        }
Beispiel #7
0
        private void LoadAssetSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData)
        {
            PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData;

            if (playSoundInfo == null)
            {
                throw new GameFrameworkException("Play sound info is invalid.");
            }

            if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId))
            {
                m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId);
                if (playSoundInfo.PlaySoundParams.Referenced)
                {
                    ReferencePool.Release(playSoundInfo.PlaySoundParams);
                }

                ReferencePool.Release(playSoundInfo);
                m_SoundHelper.ReleaseSoundAsset(soundAsset);
                return;
            }

            m_SoundsBeingLoaded.Remove(playSoundInfo.SerialId);

            PlaySoundErrorCode?errorCode  = null;
            ISoundAgent        soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode);

            if (soundAgent != null)
            {
                if (m_PlaySoundSuccessEventHandler != null)
                {
                    PlaySoundSuccessEventArgs playSoundSuccessEventArgs = PlaySoundSuccessEventArgs.Create(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData);
                    m_PlaySoundSuccessEventHandler(this, playSoundSuccessEventArgs);
                    ReferencePool.Release(playSoundSuccessEventArgs);
                }

                if (playSoundInfo.PlaySoundParams.Referenced)
                {
                    ReferencePool.Release(playSoundInfo.PlaySoundParams);
                }

                ReferencePool.Release(playSoundInfo);
                return;
            }

            m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId);
            m_SoundHelper.ReleaseSoundAsset(soundAsset);
            string errorMessage = Utility.Text.Format("Sound group '{0}' play sound '{1}' failure.", playSoundInfo.SoundGroup.Name, soundAssetName);

            if (m_PlaySoundFailureEventHandler != null)
            {
                PlaySoundFailureEventArgs playSoundFailureEventArgs = PlaySoundFailureEventArgs.Create(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, errorCode.Value, errorMessage, playSoundInfo.UserData);
                m_PlaySoundFailureEventHandler(this, playSoundFailureEventArgs);
                ReferencePool.Release(playSoundFailureEventArgs);

                if (playSoundInfo.PlaySoundParams.Referenced)
                {
                    ReferencePool.Release(playSoundInfo.PlaySoundParams);
                }

                ReferencePool.Release(playSoundInfo);
                return;
            }

            if (playSoundInfo.PlaySoundParams.Referenced)
            {
                ReferencePool.Release(playSoundInfo.PlaySoundParams);
            }

            ReferencePool.Release(playSoundInfo);
            throw new GameFrameworkException(errorMessage);
        }