Esempio n. 1
0
        static void Main(string[] args)
        {
            //playSound("C:/acoustics.wav");
            GSound.GSound.Init();
            //GSound.GSound.AddSource(Environment.CurrentDirectory + "/Data/acoustics.wav", 0, 1, -3, 1);
            GSound.GSound.AddSource("C:/acoustics.wav", -1.5f, 1, -3, 1);
            var box      = new AABB(-2, 2, 0, 3, -4, 4);
            var material = new SoundMaterial(Material.Soil);

            GSound.GSound.AddAABB(box, material);
            var time = new Stopwatch();

            time.Start();
            while (time.ElapsedMilliseconds < 5000)
            {
                Console.WriteLine("Updating sound..." + time.ElapsedMilliseconds);
                GSound.GSound.Update();
            }
            GSound.GSound.Stop();
            //GSound.Clear();

            // Try if it can be run again real quick;
            GSound.GSound.Init();
            GSound.GSound.Update();
            GSound.GSound.Stop();
        }
Esempio n. 2
0
    public void CheckMaterial(GameObject go)
    {
        if (Physics.Raycast(trn.position + checkOffset, direction, out hit, layermask))
        {
            SoundMaterial sm = hit.collider.gameObject.GetComponent <SoundMaterial>();

            if (sm != null)
            {
                sm.material.SetValue(go);
            }
        }
    }
Esempio n. 3
0
    public AK.Wwise.Switch GetMaterial()
    {
        if (Physics.Raycast(trn.position + checkOffset, direction, out hit, layermask))
        {
            SoundMaterial sm = hit.collider.gameObject.GetComponent <SoundMaterial>();

            if (sm != null)
            {
                return(sm.material);
            }
        }
        return(null);
    }
Esempio n. 4
0
        private void setSlideTargetVolumes(GameObject otherObject, Vector3 relativeVelocity, Vector3 normal, Vector3 contactPoint, bool exit)
        {
            //log("Sliding! " + gameObject.name + " against " + otherObject.name + " - Relative Velocity: " + relativeVelocity + ", Normal: " + normal + ", Contact Point: " + contactPoint + ", Exit: " + exit);

            if (SoundMaterial == null || !this.enabled || SoundMaterial.AudioSets.Count == 0)
            {
                return;
            }

            PhysSoundMaterial m = null;
            PhysSoundBase     b = otherObject == null ? null : otherObject.GetComponent <PhysSoundBase>();

            if (b)
            {
                //Special case for sliding against a terrain
                if (b is PhysSoundTerrain)
                {
                    PhysSoundTerrain terr = b as PhysSoundTerrain;
                    Dictionary <int, PhysSoundComposition> compDic = terr.GetComposition(contactPoint);

                    foreach (PhysSoundAudioContainer c in _audioContainersDic.Values)
                    {
                        PhysSoundComposition comp;
                        float mod = 0;

                        if (compDic.TryGetValue(c.KeyIndex, out comp))
                        {
                            mod = comp.GetAverage();
                        }

                        c.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit, mod);
                    }

                    return;
                }
                else
                {
                    m = b.GetPhysSoundMaterial(contactPoint);
                }
            }

            //General cases
            //If the other object has a PhysSound material
            if (m)
            {
                PhysSoundAudioContainer aud;

                if (_audioContainersDic.TryGetValue(m.MaterialTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
                else if (!SoundMaterial.HasAudioSet(m.MaterialTypeKey) && SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
            }
            //If it doesnt we set volumes based on the fallback setting of our material
            else
            {
                PhysSoundAudioContainer aud;

                if (SoundMaterial.FallbackTypeKey != -1 && _audioContainersDic.TryGetValue(SoundMaterial.FallbackTypeKey, out aud))
                {
                    aud.SetTargetVolumeAndPitch(this.gameObject, otherObject, relativeVelocity, normal, exit);
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes the PhysSoundObject. Use this if you adding a PhysSoundObject component to an object at runtime.
        /// </summary>
        public override void Initialize()
        {
            _r   = GetComponent <Rigidbody>();
            _r2D = GetComponent <Rigidbody2D>();

            if (AutoCreateSources)
            {
                baseImpactVol   = ImpactAudio.volume;
                baseImpactPitch = ImpactAudio.pitch;

                _audioContainersDic = new Dictionary <int, PhysSoundAudioContainer>();
                AudioContainers     = new List <PhysSoundAudioContainer>();

                foreach (PhysSoundAudioSet audSet in SoundMaterial.AudioSets)
                {
                    if (audSet.Slide == null)
                    {
                        continue;
                    }

                    PhysSoundAudioContainer audCont = new PhysSoundAudioContainer(audSet.Key);
                    audCont.SlideAudio = PhysSoundTempAudioPool.GetAudioSourceCopy(ImpactAudio, this.gameObject);

                    audCont.Initialize(this);
                    _audioContainersDic.Add(audCont.KeyIndex, audCont);
                    AudioContainers.Add(audCont);
                }

                ImpactAudio.loop = false;
            }
            else
            {
                if (ImpactAudio)
                {
                    ImpactAudio.loop = false;
                    baseImpactVol    = ImpactAudio.volume;
                    baseImpactPitch  = ImpactAudio.pitch;
                }

                if (AudioContainers.Count > 0)
                {
                    _audioContainersDic = new Dictionary <int, PhysSoundAudioContainer>();

                    foreach (PhysSoundAudioContainer audCont in AudioContainers)
                    {
                        if (!SoundMaterial.HasAudioSet(audCont.KeyIndex))
                        {
                            Debug.LogError("PhysSound Object " + gameObject.name + " has an audio container for an invalid Material Type! Select this object in the hierarchy to update its audio container list.");
                            continue;
                        }

                        if (PlayClipAtPoint)
                        {
                            audCont.Initialize(this, ImpactAudio);
                        }
                        else
                        {
                            audCont.Initialize(this);
                        }

                        _audioContainersDic.Add(audCont.KeyIndex, audCont);
                    }
                }
            }

            if (PlayClipAtPoint)
            {
                PhysSoundTempAudioPool.Create();
            }
            else if (ImpactAudio != null && !ImpactAudio.isActiveAndEnabled)
            {
                ImpactAudio = PhysSoundTempAudioPool.GetAudioSourceCopy(ImpactAudio, gameObject);
            }
        }
Esempio n. 6
0
    void OnCollisionEnter(Collision col)
    {
        if (playerWeapon)
        {
            if (equipped && col.gameObject.tag != "Player")
            {
                Vector3 playerToHitPoint = col.contacts[0].point - PlayerManager.Instance.player.transform.position;
                Attack  attack           = new Attack(BaseDamage, playerToHitPoint, knockbackStrength, SwingTypes.None, weaponType, col.contacts[0].point);

                AnimatorStateInfo currentAnimation = PlayerManager.Instance.playerAnimator.GetCurrentAnimatorStateInfo(0);
                if (currentAnimation.IsName("Player_RightSwing"))
                {
                    attack.swingType = SwingTypes.Right;
                    // HINT: Weapon combo state 1, you may want to take this into account when playing the weapon swing sound
                    combo_state = 1;
                }
                else if (currentAnimation.IsName("Player_LeftSwing"))
                {
                    attack.swingType = SwingTypes.Left;
                    // HINT: Weapon combo state 2, you may want to take this into account when playing the weapon swing sound
                    combo_state = 2;
                }
                else if (currentAnimation.IsName("Player_TopSwing"))
                {
                    attack.swingType = SwingTypes.Top;
                    // HINT: Weapon combo state 3, you may want to take this into account when playing the weapon swing sound
                    combo_state = 3;
                }

                if (!alreadyHitObjects.Contains(col.gameObject))
                {
                    // HINT: Get material of the contact point
                    SoundMaterial sm = col.gameObject.GetComponent <SoundMaterial>();
                    if (sm != null)
                    {
                        uint thisSwitch = 0;
                        //print("Current Switch: "+ thisSwitch +", New: "+ sm.material.ID);

                        // HINT: Update impact material

                        /*if (thisSwitch != (uint)sm.material.ID)
                         * {
                         *  sm.material.SetValue(transform.parent.gameObject); // Set Impact Material
                         *                                                     //print("New Impact Material: "+ sm.gameObject.name);
                         * }*/
                    }

                    SetAndPlayWeaponImpact(col.gameObject);
                    GameManager.DamageObject(col.gameObject, attack);

                    GameObject hit = Instantiate(hitEffect, transform.position, Quaternion.identity) as GameObject; //TODO: Pool hit effects
                    Destroy(hit, 5f);

                    if (col.gameObject.layer == LayerMask.NameToLayer("Agent"))
                    {
                        //ComboEvent.Post(transform.parent.gameObject);
                        attack.damage += applyBonusDamage ? comboCompletionBonusDamage : 0;

                        float newTimeScale   = applyBonusDamage ? 0.2f : 0.5f;
                        float transitionTime = 0.1f;
                        float holdTime       = applyBonusDamage ? 0.2f : 0.1f;
                        float shakeDuration  = applyBonusDamage ? 0.3f : 0.15f;
                        float shakeScale     = applyBonusDamage ? 0.2f : 0.1f;

                        GameManager.Instance.gameSpeedHandler.SetGameSpeed(gameObject.GetInstanceID(), newTimeScale, transitionTime, transitionTime, holdTime);
                        PlayerManager.Instance.CamShake(new PlayerCamera.CameraShake(shakeScale, shakeDuration));
                    }
                }
            }
        }
        else
        {
            if (col.gameObject.CompareTag("Player"))
            {
                Attack attack = new Attack(BaseDamage, col.contacts[0].point - PlayerManager.Instance.player.transform.position, BaseDamage);
                GameManager.DamageObject(col.gameObject, attack);
                // HINT: Play weapon impact event here, weapon type = transform.parent.gameObject
                //weapon type = transform.parent.gameObject
            }
        }
    }
Esempio n. 7
0
    void OnCollisionEnter(Collision col)
    {
        if (playerWeapon)
        {
            if (equipped && col.gameObject.tag != "Player")
            {
                Vector3 playerToHitPoint = col.contacts[0].point - PlayerManager.Instance.player.transform.position;
                Attack  attack           = new Attack(BaseDamage, playerToHitPoint, knockbackStrength, SwingTypes.None, weaponType, col.contacts[0].point);

                AnimatorStateInfo currentAnimation = PlayerManager.Instance.playerAnimator.GetCurrentAnimatorStateInfo(0);
                if (currentAnimation.IsName("Player_RightSwing"))
                {
                    attack.swingType = SwingTypes.Right;
                    WeaponCombo1.SetValue();
                }
                else if (currentAnimation.IsName("Player_LeftSwing"))
                {
                    attack.swingType = SwingTypes.Left;
                    WeaponCombo2.SetValue();
                }
                else if (currentAnimation.IsName("Player_TopSwing"))
                {
                    attack.swingType = SwingTypes.Top;
                    WeaponCombo3.SetValue();
                }

                if (!alreadyHitObjects.Contains(col.gameObject))
                {
                    //get material of the contact point
                    SoundMaterial sm = col.gameObject.GetComponent <SoundMaterial>();
                    if (sm != null)
                    {
                        uint thisSwitch = 0;
                        AkSoundEngine.GetSwitch((uint)sm.material.GroupId, transform.parent.gameObject, out thisSwitch);
                        //print("Current Switch: "+ thisSwitch +", New: "+ sm.material.ID);

                        if (thisSwitch != (uint)sm.material.Id)
                        {
                            sm.material.SetValue(transform.parent.gameObject); // Set Impact Material
                                                                               //print("New Impact Material: "+ sm.gameObject.name);
                        }
                    }

                    SetAndPlayWeaponImpact(col.gameObject);
                    // AUDIO UNITY EXERCISE ----------
                    m_audio.PlayOneShot(audioManager.GetWeaponImpact(sm.material.Name, weaponType));
                    // -------------------------------

                    GameManager.DamageObject(col.gameObject, attack);

                    GameObject hit = Instantiate(hitEffect, transform.position, Quaternion.identity) as GameObject; //TODO: Pool hit effects
                    Destroy(hit, 5f);

                    if (col.gameObject.layer == LayerMask.NameToLayer("Agent"))
                    {
                        //ComboEvent.Post(transform.parent.gameObject);
                        attack.damage += applyBonusDamage ? comboCompletionBonusDamage : 0;

                        float newTimeScale   = applyBonusDamage ? 0.2f : 0.5f;
                        float transitionTime = 0.1f;
                        float holdTime       = applyBonusDamage ? 0.2f : 0.1f;
                        float shakeDuration  = applyBonusDamage ? 0.3f : 0.15f;
                        float shakeScale     = applyBonusDamage ? 0.2f : 0.1f;

                        GameManager.Instance.gameSpeedHandler.SetGameSpeed(gameObject.GetInstanceID(), newTimeScale, transitionTime, transitionTime, holdTime);
                        PlayerManager.Instance.CamShake(new PlayerCamera.CameraShake(shakeScale, shakeDuration));
                    }
                }
            }
        }
        else
        {
            if (col.gameObject.CompareTag("Player"))
            {
                Attack attack = new Attack(BaseDamage, col.contacts[0].point - PlayerManager.Instance.player.transform.position, BaseDamage);
                GameManager.DamageObject(col.gameObject, attack);
                WeaponTypeSwitch.SetValue(transform.parent.gameObject); // Weapon Type
                WeaponImpact.Post(transform.parent.gameObject);
            }
        }
    }