Beispiel #1
0
        public void Play(bool loop = false)
        {
            if (stopFlag == true)
            {
                return;
            }
            var instance = Audio?.CreateInstance();

            instance.IsLooped = loop;
            instances.Add(instance);
        }
Beispiel #2
0
        public void Execute(Entity entity, GameTime gameTime)
        {
            if (entity.HasComponent <Components.AudioEmitter> ())
            {
                var emitter = entity.GetComponent <Components.AudioEmitter> ();
                foreach (var instance in emitter.instances)
                {
                    if (entity.HasComponent <Transform2D> ())
                    {
                        var transform = entity.GetComponent <Transform2D> ();
                        Apply3D(transform, emitter, instance);
                    }
                    instance.Play();

                    playingInstances.Add(instance);
                    instanceDict.TryAdd(instance, emitter);
                }
                emitter.instances.Clear();

                if (emitter.stopFlag)
                {
                    foreach (var kv in instanceDict)
                    {
                        if (kv.Value == emitter)
                        {
                            kv.Key.Stop();
                        }
                    }

                    emitter.stopFlag = false;
                }
            }
            else if (entity.HasComponent <Components.AudioListener> ())
            {
                var transform = entity.GetComponent <Transform2D> ();
                listener.Position = new Vector3(transform.Position.X, 0, transform.Position.Y);
                listener.Up       = new Vector3(0, 1, 0);
                listener.Forward  = new Vector3();

                foreach (var instance in playingInstances)
                {
                    var emitter          = instanceDict [instance];
                    var emitterTransform = EntityManager.SharedManager.GetEntityByComponent(emitter).GetComponent <Transform2D> ();
                    Apply3D(emitterTransform, emitter, instance);
                }
            }
        }