public int Play(int soundId)
        {
            if (Logger.IsDebugEnabled)
            {
                Logger.DebugFormat("play {0}", soundId);
            }
            if (null == _playerEntity)
            {
                return(UniversalConsts.InvalidIntId);
            }

            var soundConfigItem = _soundConfigManager.GetSoundById(soundId);

            if (null == soundConfigItem)
            {
                return(UniversalConsts.InvalidIntId);
            }
            var entity = soundConfigItem.Sync ?
                         _soundEntityFactory.CreateSyncSound(_playerEntity, soundConfigItem, true) :
                         _soundEntityFactory.CreateSelfOnlySound(soundConfigItem.Id,
                                                                 _playerEntity.position.Value,
                                                                 true);

            var soundEntity = entity as SoundEntity;

            if (null == soundEntity)
            {
                return(UniversalConsts.InvalidIntId);
            }
            return(soundEntity.entityKey.Value.EntityId);
        }
Esempio n. 2
0
        private Entity CreateSelfOnlySoundEntity(int id)
        {
            var config = _soundConfigManager.GetSoundById(id);

            if (config == null)
            {
                Logger.ErrorFormat("config with sound type {0} not exist", id);
                return(null);
            }
            var entity = CreateBaseSoundEntity(config);

            return(entity);
        }
Esempio n. 3
0
        public void OnPlayback()
        {
            var selfPlayer = _playerContext.flagSelfEntity;

            if (null == selfPlayer)
            {
                return;
            }
            foreach (var player in _playGroup.GetEntities())
            {
                SoundSyncUtil.NewNonLoopSoundFromComponent(player.sound, _playSoundList);
                for (var i = 0; i < _playSoundList.Count; i++)
                {
                    var cfg = _soundConfigManager.GetSoundById(_playSoundList[i]);
                    if (null != cfg)
                    {
                        if (Vector3.Distance(player.position.Value, selfPlayer.position.Value) <= cfg.Distance)
                        {
                            _soundEntityFactory.CreateSelfOnlyMoveSound(player.position.Value, player.entityKey.Value, _playSoundList[i], false);
                        }
                    }
                }
                SoundSyncUtil.NewLoopSoundFromComponent(player.sound, _playSoundList);
                for (var i = 0; i < _playSoundList.Count; i++)
                {
                    _soundEntityFactory.CreateSelfOnlyMoveSound(player.position.Value, player.entityKey.Value, _playSoundList[i], true);
                }
            }
        }
Esempio n. 4
0
        private SoundConfigItem ConvertTerrainSound(PlayerEntity playerEntity, ETerrainSoundType soundType)
        {
            var myTerrain = _terrainManager.GetTerrain(_mapConfigManager.SceneParameters.Id);
            var id        = myTerrain.GetSoundId(playerEntity.position.Value, soundType);

            if (id > 0)
            {
                return(_soundConfigManager.GetSoundById(id));
            }
            else
            {
                if (Logger.IsWarnEnabled)
                {
                    Logger.WarnFormat("no {0} sound assigned for terrain {1} in pos {2}", soundType, myTerrain, playerEntity.position.Value);
                }
                return(null);
            }
        }