VAUAuralizationMode.cs 8.24 KB
Newer Older
1 2 3 4 5
using UnityEngine;
using System.Collections;

public class VAUAuralizationMode : MonoBehaviour {

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    public bool DirectSound = true;
    public bool EarlyReflections = false;
    public bool DiffuseDecay = false;
    public bool SourceDirectivity = true;
    public bool AirAbsorption = false;
    public bool AtmosphericTemporalVariations = false;
    public bool Scattering = false;
    public bool Diffraction = false;
    public bool NearFielEffects = false;
    public bool DopplerShifts = true;
    public bool SphericalSpreadingLoss = true;

    private class AuralizationMode
    {
        public bool DirectSound = true;
        public bool EarlyReflections = true;
        public bool DiffuseDecay = true;
        public bool SourceDirectivity = true;
        public bool AirAbsorption = true;
        public bool AtmosphericTemporalVariations = true;
        public bool Scattering = true;
        public bool Diffraction = true;
        public bool NearFielEffects = true;
        public bool DopplerShifts = true;
        public bool SphericalSpreadingLoss = true;

        public static bool operator ==(AuralizationMode left, AuralizationMode right)
        {
            int iCompare = 0;

            iCompare += left.DirectSound != right.DirectSound ? 1 : 0;
            iCompare += left.EarlyReflections != right.EarlyReflections ? 1 : 0;
            iCompare += left.DiffuseDecay != right.DiffuseDecay ? 1 : 0;
            iCompare += left.SourceDirectivity != right.SourceDirectivity ? 1 : 0;
            iCompare += left.AirAbsorption != right.AirAbsorption ? 1 : 0;
            iCompare += left.AtmosphericTemporalVariations != right.AtmosphericTemporalVariations ? 1 : 0;
            iCompare += left.Scattering != right.Scattering ? 1 : 0;
            iCompare += left.Diffraction != right.Diffraction ? 1 : 0;
            iCompare += left.NearFielEffects != right.NearFielEffects ? 1 : 0;
            iCompare += left.DopplerShifts != right.DopplerShifts ? 1 : 0;
            iCompare += left.SphericalSpreadingLoss != right.SphericalSpreadingLoss ? 1 : 0;

            return ( iCompare == 0 );
        }

        public static bool operator !=(AuralizationMode left, AuralizationMode right)
        {
            return !(left == right);
        }
    }
    
    private AuralizationMode AuraModeShadow = new AuralizationMode();
    
    public delegate void OnAuraStringChangedDelegate(string sAuraString);
    public event OnAuraStringChangedDelegate AuraStringChanged;
61 62 63

    void Update()
    {
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
        AuralizationMode AuraMode = UpdateAuraModeSettings();

        if (AuraMode == AuraModeShadow)
            return;

        string AuraString = "";

        if (AuraMode.DirectSound != AuraModeShadow.DirectSound)
        {
            AuraString = AuraMode.DirectSound ? "+DS" : "-DS";            
            AuraModeShadow.DirectSound = AuraMode.DirectSound;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.EarlyReflections != AuraModeShadow.EarlyReflections)
        {
            AuraString = AuraMode.EarlyReflections ? "+ER" : "-ER";
            AuraModeShadow.EarlyReflections = AuraMode.EarlyReflections;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }
86

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
        if (AuraMode.DiffuseDecay != AuraModeShadow.DiffuseDecay)
        {
            AuraString = AuraMode.DiffuseDecay ? "+DD" : "-DD";
            AuraModeShadow.DiffuseDecay = AuraMode.DiffuseDecay;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.SourceDirectivity != AuraModeShadow.SourceDirectivity)
        {
            AuraString = AuraMode.SourceDirectivity ? "+DIR" : "-DIR";
            AuraModeShadow.SourceDirectivity = AuraMode.SourceDirectivity;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.AirAbsorption != AuraModeShadow.AirAbsorption)
        {
            AuraString = AuraMode.AirAbsorption ? "+AA" : "-AA";
            AuraModeShadow.AirAbsorption = AuraMode.AirAbsorption;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.AtmosphericTemporalVariations != AuraModeShadow.AtmosphericTemporalVariations)
        {
            AuraString = AuraMode.AtmosphericTemporalVariations ? "+TV" : "-TV";
            AuraModeShadow.AtmosphericTemporalVariations = AuraMode.AtmosphericTemporalVariations;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.Scattering != AuraModeShadow.Scattering)
        {
            AuraString = AuraMode.Scattering ? "+SC" : "-SC";
            AuraModeShadow.Scattering = AuraMode.Scattering;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.Diffraction != AuraModeShadow.Diffraction)
        {
            AuraString = AuraMode.Diffraction ? "+DIF" : "-DIF";
            AuraModeShadow.Diffraction = AuraMode.Diffraction;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.NearFielEffects != AuraModeShadow.NearFielEffects)
        {
            AuraString = AuraMode.NearFielEffects ? "+NF" : "-NF";
            AuraModeShadow.NearFielEffects = AuraMode.NearFielEffects;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.DopplerShifts != AuraModeShadow.DopplerShifts)
        {
            AuraString = AuraMode.DopplerShifts ? "+DP" : "-DP";
            AuraModeShadow.DopplerShifts = AuraMode.DopplerShifts;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }

        if (AuraMode.SphericalSpreadingLoss != AuraModeShadow.SphericalSpreadingLoss)
        {
            AuraString = AuraMode.SphericalSpreadingLoss ? "+SL" : "-SL";
            AuraModeShadow.SphericalSpreadingLoss = AuraMode.SphericalSpreadingLoss;
            if (AuraStringChanged != null)
                AuraStringChanged(AuraString);
        }
158 159
    }

160 161
    public void TriggerAuraStringChanged(string externAuraString)
    {
Maurice Tayeb Andreas's avatar
[VAU]  
Maurice Tayeb Andreas committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
        if (externAuraString == "+DS") DirectSound = true;
        if (externAuraString == "-DS") DirectSound = false;
        if (externAuraString == "+ER") EarlyReflections = true;
        if (externAuraString == "-ER") EarlyReflections = false;
        if (externAuraString == "+DD") DiffuseDecay = true;
        if (externAuraString == "-DD") DiffuseDecay = false;
        if (externAuraString == "+DIR") SourceDirectivity = true;
        if (externAuraString == "-DIR") SourceDirectivity = false;
        if (externAuraString == "+AA") AirAbsorption = true;
        if (externAuraString == "-AA") AirAbsorption = false;
        if (externAuraString == "+TV") AtmosphericTemporalVariations = true;
        if (externAuraString == "-TV") AtmosphericTemporalVariations = false;
        if (externAuraString == "+SC") Scattering = true;
        if (externAuraString == "-SC") Scattering = false;
        if (externAuraString == "+DIF") Diffraction = true;
        if (externAuraString == "-DIF") Diffraction = false;
        if (externAuraString == "+NF") NearFielEffects = true;
        if (externAuraString == "-NF") NearFielEffects = false;
        if (externAuraString == "+DP") DopplerShifts = true;
        if (externAuraString == "-DP") DopplerShifts = false;
        if (externAuraString == "+SL") SphericalSpreadingLoss = true;
        if (externAuraString == "-SL") SphericalSpreadingLoss = false;
184 185
        AuraStringChanged(externAuraString);
    }
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    AuralizationMode UpdateAuraModeSettings()
    {
        AuralizationMode am = new AuralizationMode();
        am.DirectSound = DirectSound;
        am.EarlyReflections = EarlyReflections;
        am.DiffuseDecay = DiffuseDecay;
        am.SourceDirectivity = SourceDirectivity;
        am.AirAbsorption = AirAbsorption;
        am.AtmosphericTemporalVariations = AtmosphericTemporalVariations;
        am.Scattering = Scattering;
        am.Diffraction = Diffraction;
        am.NearFielEffects = NearFielEffects;
        am.DopplerShifts = DopplerShifts;
        am.SphericalSpreadingLoss = SphericalSpreadingLoss;
        return am;
    }
202
}