Exemplo n.º 1
0
        /// <summary>
        ///     Play an audio stream at a static position.
        /// </summary>
        /// <param name="filename">The audio stream to play.</param>
        /// <param name="coordinates">The coordinates at which to play the audio.</param>
        public void Play(AudioStream stream, GridCoordinates coordinates, AudioParams?audioParams = null)
        {
            if (GameController.Mode == GameController.DisplayMode.Clyde)
            {
                var source = _clyde.CreateAudioSource(stream);
                source.SetPosition(coordinates.ToWorld().Position);
                if (audioParams.HasValue)
                {
                    source.SetPitch(audioParams.Value.PitchScale);
                    source.SetVolume(audioParams.Value.Volume);
                }

                source.StartPlaying();
                var playing = new PlayingClydeStream
                {
                    Source = source,
                    TrackingCoordinates = coordinates
                };
                PlayingClydeStreams.Add(playing);
                return;
            }

            if (GameController.Mode != GameController.DisplayMode.Godot)
            {
                return;
            }

            var player = new Godot.AudioStreamPlayer2D()
            {
                Stream  = stream.GodotAudioStream,
                Playing = true,
                // TODO: Handle grid and map of the coordinates.
                Position = (coordinates.Position * EyeManager.PIXELSPERMETER).Convert()
            };

            if (audioParams != null)
            {
                var val = audioParams.Value;
                player.Bus      = audioParams.Value.BusName;
                player.VolumeDb = val.Volume;
                //player.PitchScale = val.PitchScale;
                player.Attenuation = val.Attenuation;
                player.MaxDistance = EyeManager.PIXELSPERMETER * val.MaxDistance;
            }

            sceneTree.WorldRoot.AddChild(player);
            TrackGodotPlayer(player);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Play an audio stream following an entity.
        /// </summary>
        /// <param name="stream">The audio stream to play.</param>
        /// <param name="entity">The entity "emitting" the audio.</param>
        public void Play(AudioStream stream, IEntity entity, AudioParams?audioParams = null)
        {
            if (GameController.Mode == GameController.DisplayMode.Clyde)
            {
                var source = _clyde.CreateAudioSource(stream);
                source.SetPosition(entity.Transform.WorldPosition);
                if (audioParams.HasValue)
                {
                    source.SetPitch(audioParams.Value.PitchScale);
                    source.SetVolume(audioParams.Value.Volume);
                }

                source.StartPlaying();
                var playing = new PlayingClydeStream
                {
                    Source         = source,
                    TrackingEntity = entity,
                };
                PlayingClydeStreams.Add(playing);
                return;
            }

            if (GameController.Mode != GameController.DisplayMode.Godot)
            {
                return;
            }

            var parent = entity.GetComponent <IGodotTransformComponent>().SceneNode;
            var player = new Godot.AudioStreamPlayer2D()
            {
                Stream  = stream.GodotAudioStream,
                Playing = true
            };

            if (audioParams != null)
            {
                var val = audioParams.Value;
                player.Bus      = val.BusName;
                player.VolumeDb = val.Volume;
                //player.PitchScale = val.PitchScale;
                player.Attenuation = val.Attenuation;
                player.MaxDistance = EyeManager.PIXELSPERMETER * val.MaxDistance;
            }

            parent.AddChild(player);
            TrackGodotPlayer(player);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Play an audio stream globally, without position.
        /// </summary>
        /// <param name="stream">The audio stream to play.</param>
        public void Play(AudioStream stream, AudioParams?audioParams = null)
        {
            if (GameController.Mode == GameController.DisplayMode.Clyde)
            {
                var source = _clyde.CreateAudioSource(stream);
                if (audioParams.HasValue)
                {
                    source.SetPitch(audioParams.Value.PitchScale);
                    source.SetVolume(audioParams.Value.Volume);
                }

                source.SetGlobal();
                source.StartPlaying();
                var playing = new PlayingClydeStream
                {
                    Source = source,
                };
                PlayingClydeStreams.Add(playing);
                return;
            }

            if (GameController.Mode != GameController.DisplayMode.Godot)
            {
                return;
            }

            var player = new Godot.AudioStreamPlayer()
            {
                Stream  = stream.GodotAudioStream,
                Playing = true,
            };

            if (audioParams != null)
            {
                var val = audioParams.Value;
                player.Bus      = val.BusName;
                player.VolumeDb = val.Volume;
                //player.PitchScale = val.PitchScale;
                player.MixTarget = (Godot.AudioStreamPlayer.MixTargetEnum)val.MixTarget;
            }

            sceneTree.WorldRoot.AddChild(player);
            TrackGodotPlayer(player);
        }