Ejemplo n.º 1
0
        public override async Task Execute()
        {
            // Play explosion sound
            AudioEmitterComponent audioEmitter = Entity.Get <AudioEmitterComponent>();

            explosionSound = audioEmitter["Explosion"];
            explosionSound.PlayAndForget();

            Entity.Transform.UpdateWorldMatrix();

            var model = Entity.Get <ModelComponent>();

            // Scatter all the Rigidbody parts of the scattered drone model
            var     fracturedRigidBodies = Entity.GetAll <RigidbodyComponent>();
            Vector3 explosionCenter      = Entity.Transform.WorldMatrix.TranslationVector;
            Random  explosionRandom      = new Random();

            foreach (var fragment in fracturedRigidBodies)
            {
                Vector3 dir = fragment.PhysicsWorldTransform.TranslationVector - explosionCenter;
                dir.Normalize();

                fragment.IsKinematic = false;
                if (model.Skeleton.Nodes[fragment.BoneIndex].Name != "Drone_D_part_015")
                {
                    fragment.ApplyTorqueImpulse(-dir * (float)(explosionRandom.NextDouble() * 0.2f));
                    fragment.ApplyImpulse(dir * (float)(explosionRandom.NextDouble() * 2.5f + 2.5f));
                }
            }

            await Task.Delay(30000);

            // Despawn after a while to clean up drone parts
            SceneSystem.SceneInstance.RootScene.Entities.Remove(Entity);
        }
Ejemplo n.º 2
0
 public ControllerCollectionChangedEventArgs(Entity entity, AudioEmitterSoundController controller, AudioEmitterComponent component, NotifyCollectionChangedAction action)
 {
     Entity           = entity;
     Controller       = controller;
     EmitterComponent = component;
     Action           = action;
 }
Ejemplo n.º 3
0
        public override void Start()
        {
            if (Camera == null)
            {
                throw new ArgumentException("Camera is not set");
            }
            if (ShootSource == null)
            {
                throw new ArgumentException("ShootSource is not set");
            }
            if (BulletPerSeconds <= 0)
            {
                throw new ArgumentException("BulletPerSeconds must be > 0");
            }
            if (MaxAmmo <= 0)
            {
                throw new ArgumentException("MaxAmmo must be > 0");
            }
            CurrentAmmo = MaxAmmo;

            soldier     = Entity.Get <SoldierController>();
            reloadSound = ShootSource.Get <AudioEmitterComponent>()["Reload"];

            // Handle reload event
            soldier.Input.OnReload += (e) =>
            {
                if (!IsReloading && CurrentAmmo != MaxAmmo)
                {
                    Reload();
                }
            };
            BulletPerSeconds = 40;
        }
Ejemplo n.º 4
0
        public override async Task Execute()
        {
            sensor       = Entity.FindChild("AoESensor").Get <RigidbodyComponent>();
            explodeSound = Entity.Get <AudioEmitterComponent>()["Explode"];

            await base.Execute();
        }
Ejemplo n.º 5
0
        public override void Start()
        {
            // We need to create an instance of Sound object in order to play them
            ukuleleInstance = UkuleleSound.CreateInstance();

            audioEmitterComponent = Entity.Get <AudioEmitterComponent>();
            gunSoundEmitter       = audioEmitterComponent["Gun"];
        }
Ejemplo n.º 6
0
        public void TestAttachDetachSounds()
        {
            var testInst = new AudioEmitterComponent();

            using (var game = new Game())
            {
                Game.InitializeAssetDatabase();
                using (var audioStream1 = ContentManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read))
                    using (var audioStream2 = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                        using (var audioStream3 = ContentManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                        {
                            var sound1 = SoundEffect.Load(game.Audio.AudioEngine, audioStream1);
                            var sound2 = SoundEffect.Load(game.Audio.AudioEngine, audioStream2);
                            var sound3 = SoundEffect.Load(game.Audio.AudioEngine, audioStream3);

                            // Attach two soundEffect and check that their controller are correctly created.

                            AudioEmitterSoundController soundController1 = null;
                            AudioEmitterSoundController soundController2 = null;
                            Assert.DoesNotThrow(() => testInst.AttachSoundEffect(sound1), "Adding a first soundEffect failed");
                            Assert.DoesNotThrow(() => soundController1 = testInst.SoundEffectToController[sound1], "There are no sound controller for sound1.");
                            Assert.IsNotNull(soundController1, "Sound controller for sound1 is null");

                            Assert.DoesNotThrow(() => testInst.AttachSoundEffect(sound2), "Adding a second soundEffect failed");
                            Assert.DoesNotThrow(() => soundController2 = testInst.SoundEffectToController[sound2], "There are no sound controller for sound1.");
                            Assert.IsNotNull(soundController2, "Sound controller for sound2 is null");

                            // Remove the two soundEffect and check that their controller are correctly erased.

                            Assert.DoesNotThrow(() => testInst.DetachSoundEffect(sound2), "Removing a first soundEffect failed");
                            Assert.IsFalse(testInst.SoundEffectToController.ContainsKey(sound2), "The controller for sound2 is still present in the list.");

                            Assert.DoesNotThrow(() => testInst.DetachSoundEffect(sound1), "Removing a second soundEffect failed");
                            Assert.IsFalse(testInst.SoundEffectToController.ContainsKey(sound1), "The controller for sound1 is still present in the list.");

                            Assert.IsTrue(testInst.SoundEffectToController.Keys.Count == 0, "There are some controller left in the component list.");

                            // Check the exception thrwon by attachSoundEffect.

                            Assert.Throws <ArgumentNullException>(() => testInst.AttachSoundEffect(null), "AttachSoundEffect did not throw ArgumentNullException");
                            Assert.Throws <InvalidOperationException>(() => testInst.AttachSoundEffect(sound3), "AttachSoundEffect did not throw InvalidOperationException.");

                            // Check the exception thrown by detachSoundEffect.

                            Assert.Throws <ArgumentNullException>(() => testInst.DetachSoundEffect(null), "DetachSoundEffect did not throw ArgumentNullException.");
                            Assert.Throws <ArgumentException>(() => testInst.DetachSoundEffect(sound1), "DetachSoundEffect did not throw ArgumentException ");
                        }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Attach a <see cref="SoundBase"/> to this emitter component.
        /// Once attached a <see cref="AudioEmitterSoundController"/> can be queried using readonly <see cref="AudioEmitterComponent.Item(string)"/> indexer to control the attached SoundBase.
        /// </summary>
        /// <param name="sound">The SoundBase to attach</param>
        /// <exception cref="ArgumentNullException">The provided <paramref name="sound"/> is null.</exception>
        /// <exception cref="InvalidOperationException">The provided <paramref name="sound"/> can not be localized (contains more than one channel).</exception>
        /// <remarks>Attaching a SoundBase already attached has no effects.</remarks>
        public AudioEmitterSoundController AttachSound([NotNull] SoundBase sound)
        {
            if (sound == null) throw new ArgumentNullException(nameof(sound));
            if (sound.Channels > 1)
                throw new InvalidOperationException("The provided Sound has more than one channel. It can not be localized in the 3D scene, please check the spatialized option in the Sound asset.");

            if (SoundToController.ContainsKey(sound))
                return SoundToController[sound];

            var newController = new AudioEmitterSoundController(this, sound);
            SoundToController[sound] = newController;
            ControllerCollectionChanged?.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, newController, this, NotifyCollectionChangedAction.Add));

            return newController;
        }
Ejemplo n.º 8
0
        public override void Start()
        {
            base.Start();

            Character = Entity.Get <CharacterComponent>();
            Animation = Entity.Get <DroneAnimation>();
            if (Animation == null)
            {
                Animation = new DroneAnimation {
                    Animation = Model.Entity.Get <AnimationComponent>()
                };
                Entity.Add(Animation);
            }

            // Store original bone data, so they can be modified later
            for (int i = 0; i < Model.Skeleton.Nodes.Length; ++i)
            {
                var   nodeRot = Model.Skeleton.NodeTransformations[i].Transform.Rotation;
                var   mat = Matrix.RotationQuaternion(nodeRot);
                float yaw, pitch, roll;
                mat.Decompose(out yaw, out pitch, out roll);
                var node = Model.Model.Skeleton.Nodes[i];
                bones[node.Name] = new Bone
                {
                    EulerAngles = new Vector3(yaw, pitch, roll)
                };
            }

            Entity.Transform.PostOperations.Add(new DronePostTransformUpdater {
                Drone = this
            });

            // Engine sound
            engineSound           = EngineAudioEmitter["Engine"];
            engineSound.IsLooping = true;
            engineSound.Play();

            // Load sounds
            AudioEmitter = Entity.Get <AudioEmitterComponent>();
            deathSound   = AudioEmitter["Death"];

            // Load the variable amount of being hit sounds, "Hit0", "Hit1", etc.
            hitSounds = new RandomSoundSelector(AudioEmitter, "Hit");

            initialHeight = Model.Entity.Transform.Position.Y;

            weapon?.Init(this);
        }
Ejemplo n.º 9
0
        private void AddSoundEffectToEmitterComponents(Game game)
        {
            sounds = new List <SoundEffect>
            {
                game.Asset.Load <SoundEffect>("EffectBip"),
                game.Asset.Load <SoundEffect>("EffectToneA"),
            };

            emitComps[0].AttachSoundEffect(sounds[0]);
            emitComps[0].AttachSoundEffect(sounds[1]);

            soundControllers = new List <AudioEmitterSoundController>
            {
                emitComps[0].GetSoundEffectController(sounds[0]),
                emitComps[0].GetSoundEffectController(sounds[1]),
            };

            mainController = soundControllers[0];
        }
Ejemplo n.º 10
0
        private void AddSoundEffectToEmitterComponents(Game game)
        {
            sounds = new List<SoundEffect>
                {
                    game.Content.Load<SoundEffect>("EffectBip"),
                    game.Content.Load<SoundEffect>("EffectToneA"),
                };

            emitComps[0].AttachSoundEffect(sounds[0]);
            emitComps[0].AttachSoundEffect(sounds[1]);

            soundControllers = new List<AudioEmitterSoundController>
                {
                    emitComps[0].GetSoundEffectController(sounds[0]),
                    emitComps[0].GetSoundEffectController(sounds[1]),
                };

            mainController = soundControllers[0];
        }
Ejemplo n.º 11
0
        private void AddSoundEffectToEmitterComponents(Game game)
        {
            sounds = new List <Sound>
            {
                game.Content.Load <Sound>("EffectBip"),
                game.Content.Load <Sound>("EffectToneA"),
            };

            emitComps[0].Sounds["EffectBip"]   = sounds[0];
            emitComps[0].Sounds["EffectToneA"] = sounds[1];

            soundControllers = new List <AudioEmitterSoundController>
            {
                emitComps[0]["EffectBip"],
                emitComps[0]["EffectToneA"],
            };

            mainController = soundControllers[0];
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Attach a <see cref="Sound"/> to this emitter component.
        /// Once attached a <see cref="AudioEmitterSoundController"/> can be queried using <see cref="GetSoundController"/> to control the attached Sound.
        /// </summary>
        /// <param name="sound">The Sound to attach</param>
        /// <exception cref="ArgumentNullException">The provided <paramref name="sound"/> is null.</exception>
        /// <exception cref="InvalidOperationException">The provided <paramref name="sound"/> can not be localized (contains more than one channel).</exception>
        /// <remarks>Attaching a Sound already attached has no effects.</remarks>
        public void AttachSound(Sound sound)
        {
            if (sound == null)
            {
                throw new ArgumentNullException(nameof(sound));
            }
            if (sound.Channels > 1)
            {
                throw new InvalidOperationException("The provided Sound has more than one channel. It can not be localized in the 3D scene.");
            }

            if (SoundToController.ContainsKey(sound))
            {
                return;
            }

            var newController = new AudioEmitterSoundController(this, sound);

            SoundToController[sound] = newController;
            ControllerCollectionChanged?.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, newController, this, NotifyCollectionChangedAction.Add));
        }
Ejemplo n.º 13
0
        public void TestGetController()
        {
            var testInst = new AudioEmitterComponent();

            using (var game = new Game())
            {
                Game.InitializeAssetDatabase();
                using (var audioStream1 = ContentManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read))
                    using (var audioStream2 = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                    {
                        var sound1 = SoundEffect.Load(game.Audio.AudioEngine, audioStream1);
                        var sound2 = SoundEffect.Load(game.Audio.AudioEngine, audioStream2);

                        AudioEmitterSoundController soundController1 = null;
                        AudioEmitterSoundController soundController2 = null;

                        // Add two soundEffect and try to get their controller.

                        testInst.AttachSoundEffect(sound1);
                        Assert.DoesNotThrow(() => soundController1 = testInst.GetSoundEffectController(sound1), "Failed to get the controller associated to the soundEffect1.");

                        testInst.AttachSoundEffect(sound2);
                        Assert.DoesNotThrow(() => soundController2 = testInst.GetSoundEffectController(sound2), "Failed to get the controller associated to the soundEffect1.");

                        // Suppress the two SoundEffects and check that the function throws the correct exception (ArgumentException)

                        testInst.DetachSoundEffect(sound1);
                        Assert.Throws <ArgumentException>(() => testInst.GetSoundEffectController(sound1), "GetController did not throw ArgumentException but sound1 was supposed to be detached.");

                        testInst.DetachSoundEffect(sound2);
                        Assert.Throws <ArgumentException>(() => testInst.GetSoundEffectController(sound2), "GetController did not throw ArgumentException but sound2 was supposed to be detached.");

                        // Check the ArgumentNullException
                        Assert.Throws <ArgumentNullException>(() => testInst.GetSoundEffectController(null), "GetController did not throw ArgumentNullException.");
                    }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Attach a <see cref="SoundEffect"/> to this emitter component.
        /// Once attached a <see cref="AudioEmitterSoundController"/> can be queried using <see cref="GetSoundEffectController"/> to control the attached SoundEffect.
        /// </summary>
        /// <param name="soundEffect">The SoundEffect to attach</param>
        /// <exception cref="ArgumentNullException">The provided <paramref name="soundEffect"/> is null.</exception>
        /// <exception cref="InvalidOperationException">The provided <paramref name="soundEffect"/> can not be localized (contains more than one channel).</exception>
        /// <remarks>Attaching a soundEffect already attached has no effects.</remarks>
        public void AttachSoundEffect(SoundEffect soundEffect)
        {
            if (soundEffect == null)
            {
                throw new ArgumentNullException("soundEffect");
            }
            if (soundEffect.WaveFormat.Channels > 1)
            {
                throw new InvalidOperationException("The provided SoundEffect has more than one channel. It can not be localized in the 3D scene.");
            }

            if (SoundEffectToController.ContainsKey(soundEffect))
            {
                return;
            }

            var newController = new AudioEmitterSoundController(this, soundEffect);

            SoundEffectToController[soundEffect] = newController;
            if (ControllerCollectionChanged != null)
            {
                ControllerCollectionChanged.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, newController, NotifyCollectionChangedAction.Add));
            }
        }
Ejemplo n.º 15
0
 public ControllerCollectionChangedEventArgs(Entity entity, AudioEmitterSoundController controller, NotifyCollectionChangedAction action)
 {
     Entity = entity;
     Controller = controller;
     Action = action;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Attach a <see cref="SoundEffect"/> to this emitter component.
        /// Once attached a <see cref="AudioEmitterSoundController"/> can be queried using <see cref="GetSoundEffectController"/> to control the attached SoundEffect.
        /// </summary>
        /// <param name="soundEffect">The SoundEffect to attach</param>
        /// <exception cref="ArgumentNullException">The provided <paramref name="soundEffect"/> is null.</exception>
        /// <exception cref="InvalidOperationException">The provided <paramref name="soundEffect"/> can not be localized (contains more than one channel).</exception>
        /// <remarks>Attaching a soundEffect already attached has no effects.</remarks>
        public void AttachSoundEffect(SoundEffect soundEffect)
        {
            if (soundEffect == null)
            {
                throw new ArgumentNullException("soundEffect");
            }
            if (soundEffect.WaveFormat.Channels > 1)
            {
                throw new InvalidOperationException("The provided SoundEffect has more than one channel. It can not be localized in the 3D scene.");
            }

            if(SoundEffectToController.ContainsKey(soundEffect))
                return;

            var newController = new AudioEmitterSoundController(this, soundEffect);
            SoundEffectToController[soundEffect] = newController;
            if(ControllerCollectionChanged != null)
                ControllerCollectionChanged.Invoke(this, new ControllerCollectionChangedEventArgs(Entity, newController, NotifyCollectionChangedAction.Add ));
        }
Ejemplo n.º 17
0
        public override void Init(Drone drone)
        {
            base.Init(drone);

            shootSound = ProjectileSpawnPoint.Get <AudioEmitterComponent>()["Fire"];
        }
Ejemplo n.º 18
0
 public static Entity GetSoundController(this Entity entity, string key, out AudioEmitterSoundController soundController)
 {
     soundController = entity.Get <AudioEmitterComponent>()[key];
     return(entity);
 }
Ejemplo n.º 19
0
        public override void Start()
        {
            if (Entity.Transform.Parent != null)
            {
                throw new ArgumentException("SoldierController must be root");
            }
            if (Camera == null)
            {
                throw new ArgumentException("Camera is not set");
            }
            if (AnimationComponent == null)
            {
                throw new ArgumentException("AnimationComponent is not set");
            }
            if (CameraController == null)
            {
                throw new ArgumentException("CameraController is not set");
            }
            if (DroneCrosshair == null)
            {
                throw new ArgumentException("DroneCrosshair is not set");
            }
            if (RotationSpeed < 0 || RotationSpeed > 1)
            {
                throw new ArgumentException("Rotation Speed must be between 0 and 1");
            }

            //this.GetSimulation().ColliderShapesRendering = true;

            // Enable UI
            IStarbreach ipbrGame = Game as IStarbreach;

            //Entity statusBarEntity = ipbrGame.PlayerUiEntity.FindChild("StatusBar");
            //uiComponent = statusBarEntity.Get<UIComponent>();
            //uiComponent.Enabled = true;

            stateMachine = new FiniteStateMachine("SoldierController");
            stateMachine.RegisterState(new State(IdleState)
            {
                UpdateMethod = UpdateIdle
            });
            stateMachine.RegisterState(new State(RunState)
            {
                UpdateMethod = UpdateRun
            });
            stateMachine.RegisterState(new State(WalkState)
            {
                EnterMethod = StartWalk, UpdateMethod = UpdateWalk
            });
            stateMachine.Start(Script, IdleState);
            Instance = this;

            character        = Entity.Get <CharacterComponent>();
            sphereCastOrigin = Entity.FindChild("SphereCastOrigin");

            AudioEmitterComponent emitter = Entity.Get <AudioEmitterComponent>();

            // Load 3 different being hit sounds
            hitSounds = new AudioEmitterSoundController[3];
            for (int i = 0; i < 3; i++)
            {
                hitSounds[i]           = emitter["Hit" + i];
                hitSounds[i].IsLooping = false;
            }
            deathSound = emitter["Death"];
        }
Ejemplo n.º 20
0
 public static AudioEmitterComponent GetSoundController(this AudioEmitterComponent audioEmitter, string key, out AudioEmitterSoundController soundController)
 {
     soundController = audioEmitter[key];
     return(audioEmitter);
 }