Exemplo n.º 1
0
        protected override void Start(SystemRegistry registry)
        {
            _input       = registry.GetSystem <InputSystem>();
            _ballState   = GameObject.GetComponent <BallState>();
            _audioSource = new AudioSourceComponent();
            GameObject.AddComponent(_audioSource);
            _audioSource.AudioClip = new AssetRef <WaveFile>("Audio/BoostNoise.wav");
            _audioSource.Gain      = 4.0f;

            var shs = registry.GetSystem <SynchronizationHelperSystem>();

            Task.Run(() =>
            {
                var particleChildPrefab = registry.GetSystem <AssetSystem>().Database.LoadAsset <SerializedPrefab>("Prefabs/LinearBoostParticles.prefab", false);
                var particleChild       = particleChildPrefab.Instantiate(registry.GetSystem <GameObjectQuerySystem>());
                var transformFollow     = new TransformFollow()
                {
                    Target = Transform
                };
                particleChild.AddComponent(transformFollow);
                _childParticleSystem = particleChild.GetComponent <ParticleSystem>();
            });

            _currentAvailableBoosts = MaxBoosts;
        }
Exemplo n.º 2
0
 protected override void Start(SystemRegistry registry)
 {
     _collider             = GameObject.GetComponent <Collider>();
     _rollSource           = GameObject.GetComponent <AudioSourceComponent>();
     _thudSource           = new AudioSourceComponent();
     _thudSource.AudioClip = ThudClip;
     GameObject.AddComponent(_thudSource);
 }
Exemplo n.º 3
0
        protected unsafe override void Start(SystemRegistry registry)
        {
            _assetSystem = registry.GetSystem <AssetSystem>();
            _sls         = registry.GetSystem <SceneLoaderSystem>();
            _gs          = registry.GetSystem <GraphicsSystem>();
            _audioSource = GameObject.GetComponent <AudioSourceComponent>();
            LoadFont();

            _gs.ImGuiRenderer.RecreateFontDeviceTexture(_gs.Context);

            _allScenes = _assetSystem.Database.GetAssetsOfType(typeof(SceneAsset));
        }
Exemplo n.º 4
0
 public PlayerController(GameObject nozzle, Mesh bulletModel, Texture bulletTexture, ShaderProgram bulletShader,
                         float speed, bool useGlobalForward, AudioSourceComponent audioSource)
 {
     AudioSource        = audioSource;
     this.bulletTexture = bulletTexture;
     bulletLayer        = LayerManager.NameToLayer("physics");
     this.nozzle        = nozzle;
     this.bulletModel   = bulletModel;
     this.bulletShader  = bulletShader;
     MoveSpeed          = speed;
     UseGlobalForward   = useGlobalForward;
     raycastLayer       = LayerManager.NameToLayer("raycast");
 }
Exemplo n.º 5
0
        public void SerializeAndDeserialize_WhenSoundIsNull()
        {
            // Arrange
            var component = new AudioSourceComponent
            {
                Sound     = null,
                IsPlaying = true
            };

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.Sound, Is.Null);
            Assert.That(actual.IsPlaying, Is.True);
        }
Exemplo n.º 6
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG");

            bgObj.Scale = new Vector3(25, 1, 25);
            bgObj.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                         TextureLoader.ColorToTexture(Color.MediumPurple), 1));
            Add(bgObj);

            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            c.Translate(new Vector3(0, 4, 0));
            camLookCommandComponent = new LookAtComponent();

            c.AddComponent(camLookCommandComponent);

            sourceCube = new GameObject(Vector3.UnitZ * -5, "Audio Source");

            AudioSourceComponent source = new AudioSourceComponent();

            sourceCube.AddComponent(source);
            sourceCube.AddComponent(new RotateAroundComponent());
            sourceCube.AddComponent(new MeshRendererComponent(DefaultFilepaths.DefaultUnlitShader, Prefabs.Cube,
                                                              DefaultFilepaths.DefaultTexture, 1));
            if (!AudioLoader.TryLoad("assets/sounds/test_mono_16.wav", out AudioFile clip))
            {
                Console.ReadLine();
            }

            source.Clip    = clip;
            source.Looping = true;
            source.Play();
            Add(sourceCube);

            AudioListener listener = new AudioListener();

            c.AddComponent(listener);
            Add(c);
            SetCamera(c);
        }
Exemplo n.º 7
0
        public void SerializeAndDeserialize_WhenSoundIsNotNull()
        {
            // Arrange
            var sound        = Substitute.For <ISound>();
            var soundAssetId = AssetId.CreateUnique();

            var component = new AudioSourceComponent
            {
                Sound     = sound,
                IsPlaying = true
            };

            AssetStore.GetAssetId(sound).Returns(soundAssetId);
            AssetStore.GetAsset <ISound>(soundAssetId).Returns(sound);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.Sound, Is.EqualTo(sound));
            Assert.That(actual.IsPlaying, Is.True);
        }
Exemplo n.º 8
0
        protected override void InitializeScene()
        {
            Add(DebugConsoleComponent.CreateConsole());
            Matrix4 proj = Matrix4.CreatePerspectiveFieldOfView(
                MathHelper.DegreesToRadians(75f), //Field of View Vertical
                16f / 9f,                         //Aspect Ratio
                0.1f,                             //Near Plane
                1000f);                           //Far Plane

            BasicCamera bc = new BasicCamera(proj, Vector3.UnitY * 7);

            bc.Rotate(Vector3.UnitX, MathHelper.DegreesToRadians(-90));
            Add(bc);                                                                  //Adding the BasicCamera(That is a gameobject under the hood) to the scene to receive events
            SetCamera(bc);                                                            //Sets the Camera as the "active" camera that the scene will be rendered from.
            bc.AddComponent(new AudioListener());
            GameObject boxContainer      = new GameObject("Container");               //Empty Container at origin
            GameObject box               = new GameObject(-Vector3.UnitZ * 6, "Box"); //Creating a new Empty GameObject
            LitMeshRendererComponent lmr = new LitMeshRendererComponent(              //Creating a Renderer Component
                DefaultFilepaths.DefaultLitShader,                                    //The OpenGL Shader used(Unlit and Lit shaders are provided)
                Prefabs.Cube,                                                         //The Mesh that is going to be used by the MeshRenderer
                TextureLoader.ColorToTexture(Color.Red),                              //Diffuse Texture to put on the mesh
                1);                                                                   //Render Mask (UI = 1 << 30)

            box.AddComponent(lmr);                                                    //Attaching the Renderer to the GameObject

            AudioSourceComponent asc = new AudioSourceComponent();

            AudioLoader.TryLoad("assets/sound.wav", out AudioFile file);
            asc.Clip    = file;
            asc.Looping = true;
            asc.Play();
            asc.UpdatePosition = true; //Enable 3D Tracking the Gameobjects movements and apply it to the audio source
            asc.Gain           = 0.6f;

            box.AddComponent(asc);
            boxContainer.AddComponent(new RotatingComponent());
            boxContainer.Add(box); //Adding the Object to the Scene.
            Add(boxContainer);
        }
Exemplo n.º 9
0
 protected override void Start(SystemRegistry registry)
 {
     _input       = registry.GetSystem <InputSystem>();
     _audioSource = GameObject.GetComponent <AudioSourceComponent>();
 }
Exemplo n.º 10
0
 void StopStream(int id)
 {
     AudioSourceComponent.Stop();
     m_BufferPosition = 0;
 }
Exemplo n.º 11
0
    void ReceiveDataForStream(int id, int samples, IntPtr pcm, int channels)
    {
        int receivedSamples = channels * samples;

        if (receivedSamples > m_AudioBuffer.Length)
        {
            m_AudioBuffer = new float[receivedSamples];
        }

        for (int i = 0; i < channels; i++)
        {
            IntPtr channelData = Marshal.ReadIntPtr(pcm, i * ptrSize);
            Marshal.Copy(channelData, m_AudioBuffer, i * samples, samples);
        }

        if ((m_BufferPosition * channels) + receivedSamples > m_AudioClipData.Length)
        {
            int partOneSamples = m_AudioClipData.Length / channels - m_BufferPosition;
            int partTwoSamples = samples - partOneSamples;

            for (int i = 0; i < partOneSamples; i++)
            {
                for (int j = 0; j < channels; j++)
                {
                    m_AudioClipData[(m_BufferPosition + i) * channels + j] = m_AudioBuffer[i + j * samples];
                }
            }

            for (int i = 0; i < partTwoSamples; i++)
            {
                for (int j = 0; j < channels; j++)
                {
                    m_AudioClipData[i * channels + j] = m_AudioBuffer[partOneSamples + i + j * samples];
                }
            }
        }
        else
        {
            for (int i = 0; i < samples; i++)
            {
                for (int j = 0; j < channels; j++)
                {
                    m_AudioClipData[(m_BufferPosition + i) * channels + j] = m_AudioBuffer[i + j * samples];
                }
            }
        }

        m_AudioClip.SetData(m_AudioClipData, 0);

        bool inSync = m_BufferPosition >= m_AudioSource.timeSamples &&
                      m_BufferPosition - m_AudioSource.timeSamples < m_MaxBufferSize ||
                      m_BufferPosition < m_AudioSource.timeSamples &&
                      (m_AudioClip.samples - m_AudioSource.timeSamples) + m_BufferPosition < m_MaxBufferSize;

        if (!inSync)
        {
            Debug.LogWarning("[Coherent GT] Audio playback was out of sync with the video. " +
                             "Synchronizing audio now, this may cause a skip.");
            m_BufferPosition = AudioSourceComponent.timeSamples + m_PreBufferSize;
        }

        m_BufferPosition += samples;

        if (m_BufferPosition >= m_AudioClip.samples)
        {
            m_BufferPosition -= m_AudioClip.samples;
        }

        if (!AudioSourceComponent.isPlaying &&
            m_AutoPlayOnDataReceived &&
            m_BufferPosition > m_PreBufferSize)
        {
            AudioSourceComponent.Play();
            m_AutoPlayOnDataReceived = false;
        }
    }
Exemplo n.º 12
0
        protected override void InitializeScene()
        {
            Mesh bgBox = MeshLoader.FileToMesh("models/cube_flat.obj");


            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/UITextRender.fs" },
                { ShaderType.VertexShader, "shader/UIRender.vs" }
            }, out ShaderProgram textShader);

            ShaderProgram.TryCreate(new Dictionary <ShaderType, string>
            {
                { ShaderType.FragmentShader, "shader/texture.fs" },
                { ShaderType.VertexShader, "shader/texture.vs" }
            }, out ShaderProgram shader);

            DebugConsoleComponent dbg = DebugConsoleComponent.CreateConsole().GetComponent <DebugConsoleComponent>();

            dbg.AddCommand("mov", cmd_ChangeCameraPos);
            dbg.AddCommand("rot", cmd_ChangeCameraRot);
            dbg.AddCommand("reload", cmd_ReLoadScene);
            dbg.AddCommand("next", cmd_NextScene);
            dbg.AddCommand("lookat", cmd_LookAtAudioSource);
            GameEngine.Instance.CurrentScene.Add(dbg.Owner);

            GameObject bgObj = new GameObject(Vector3.UnitY * -3, "BG");

            bgObj.Scale = new Vector3(25, 1, 25);
            bgObj.AddComponent(new MeshRendererComponent(shader, bgBox,
                                                         TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            GameEngine.Instance.CurrentScene.Add(bgObj);

            BasicCamera c = new BasicCamera(
                Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(75f),
                                                     GameEngine.Instance.Width / (float)GameEngine.Instance.Height, 0.01f, 1000f), Vector3.Zero);

            c.Translate(new Vector3(0, 4, 0));
            _camLookCommandComponent = new LookAtComponent();

            c.AddComponent(_camLookCommandComponent);

            _sourceCube = new GameObject(Vector3.UnitZ * -5, "Audio Source");

            Mesh sourceCube             = MeshLoader.FileToMesh("models/cube_flat.obj");
            AudioSourceComponent source = new AudioSourceComponent();

            _sourceCube.AddComponent(source);
            _sourceCube.AddComponent(new RotateAroundComponent());
            _sourceCube.AddComponent(new MeshRendererComponent(shader, sourceCube,
                                                               TextureLoader.FileToTexture("textures/ground4k.png"), 1));
            if (!AudioLoader.TryLoad("sounds/test_mono_16.wav", out AudioFile clip))
            {
                Console.ReadLine();
            }

            source.Clip    = clip;
            source.Looping = true;
            source.Play();
            GameEngine.Instance.CurrentScene.Add(_sourceCube);

            AudioListener listener = new AudioListener();

            c.AddComponent(listener);
            GameEngine.Instance.CurrentScene.Add(c);
            GameEngine.Instance.CurrentScene.SetCamera(c);
        }
Exemplo n.º 13
0
        public static GameObject[] CreatePlayer(Vector3 position, BasicCamera cam)
        {
            Mesh mouseTargetModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");


            GameObject mouseTarget = new GameObject(Vector3.UnitY * -3, "BG");

            mouseTarget.Scale = new Vector3(1, 1, 1);
            mouseTarget.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, mouseTargetModel,
                                                                  Prefabs.White, 1));

            Mesh playerModel = MeshLoader.FileToMesh("assets/models/sphere_smooth.obj");
            Mesh headModel   = MeshLoader.FileToMesh("assets/models/cube_flat.obj");
            Mesh bullet      = MeshLoader.FileToMesh("assets/models/cube_flat.obj");


            GameObject player  = new GameObject(new Vector3(0, 10, 0), "Player");
            GameObject playerH = new GameObject(new Vector3(0, 10, 0), "PlayerHead");
            GameObject lightS  = new GameObject(Vector3.UnitY * 2f, "Light");

            playerH.Add(lightS);
            lightS.AddComponent(new LightComponent()
            {
                AmbientContribution = 0f
            });
            lightS.LocalPosition = Vector3.UnitY * 14f;



            //Movement for camera
            OffsetConstraint cameraController = new OffsetConstraint {
                Damping = 0, MoveSpeed = 2
            };

            cameraController.Attach(player, new Vector3(0, 15, 5));
            cam.AddComponent(cameraController);

            //Rotation for Player Head depending on mouse position
            cam.AddComponent(new CameraRaycaster(mouseTarget, playerH));

            //Movement for Player Head
            OffsetConstraint connection = new OffsetConstraint()
            {
                Damping   = 0,  //Directly over the moving collider, no inertia
                MoveSpeed = 20, //Even less inertia by moving faster in general
            };

            connection.Attach(player, Vector3.UnitY * 1);
            playerH.AddComponent(connection);
            playerH.Scale = new Vector3(0.6f);
            playerH.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, headModel,
                                                              TextureLoader.FileToTexture("assets/textures/playerHead.png"), 1));


            //Player Setup
            Collider collider = new Collider(new Sphere(Vector3.Zero, 1, 10), LayerManager.NameToLayer("physics"));

            collider.PhysicsCollider.PositionUpdateMode = PositionUpdateMode.Continuous;
            collider.PhysicsCollider.Material           = new Material(1.5f, 1.5f, 0);
            collider.PhysicsCollider.LinearDamping      = 0.99f;

            player.AddComponent(collider);


            player.AddComponent(new LitMeshRendererComponent(DefaultFilepaths.DefaultLitShader, playerModel,
                                                             TextureGenerator.GetPlayerTexture(), 1));

            AudioSourceComponent source = new AudioSourceComponent();

            AudioLoader.TryLoad("assets/audio/ShootSound.wav", out ShootSound);
            AudioLoader.TryLoad("assets/audio/ShootSound2.wav", out ShootSound2);
            AudioLoader.TryLoad("assets/audio/SpawnSound.wav", out SpawnSound);
            AudioLoader.TryLoad("assets/audio/JumpSound.wav", out JumpSound);
            source.Clip = SpawnSound;
            source.Play();
            source.UpdatePosition = false;
            source.Gain           = 0.5f;
            player.AddComponent(source);

            player.AddComponent(new PlayerController(playerH, bullet,
                                                     TextureLoader.ColorToTexture(Color.Red), DefaultFilepaths.DefaultLitShader, 650, false, source));
            player.LocalPosition = position;


            GameObject playerUI = new GameObject("PlayerHUD");

            playerUI.AddComponent(new PlayerHUD());


            return(new[] { player, playerH, playerUI });
        }