VAUAuralizationMode.cs 8.21 KB
Newer Older
1 2 3
using UnityEngine;
using System.Collections;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
4 5
public class VAUAuralizationMode : MonoBehaviour
{
6

7 8 9 10 11 12 13 14
    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;
15
    public bool NearFieldEffects = false;
16 17 18
    public bool DopplerShifts = true;
    public bool SphericalSpreadingLoss = true;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
19
    private class AuralizationMode : System.Object
20 21 22 23 24 25 26 27 28
    {
        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;
29
        public bool NearFieldEffects = true;
30 31 32
        public bool DopplerShifts = true;
        public bool SphericalSpreadingLoss = true;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
33 34 35 36 37 38
        public override bool Equals(System.Object other)
        {
            return (GetHashCode() == other.GetHashCode());
        }

        override public int GetHashCode()
39 40 41
        {
            int iCompare = 0;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
42 43 44 45 46 47 48 49
            iCompare += DirectSound ? 1 << 1 : 0;
            iCompare += EarlyReflections ? 1 << 2 : 0;
            iCompare += DiffuseDecay ? 1 << 3 : 0;
            iCompare += SourceDirectivity ? 1 << 4 : 0;
            iCompare += AirAbsorption ? 1 << 5 : 0;
            iCompare += AtmosphericTemporalVariations ? 1 << 6 : 0;
            iCompare += Scattering ? 1 << 7 : 0;
            iCompare += Diffraction ? 1 << 8 : 0;
50
            iCompare += NearFieldEffects ? 1 << 9 : 0;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
51 52 53 54 55 56 57 58 59
            iCompare += DopplerShifts ? 1 << 10 : 0;
            iCompare += SphericalSpreadingLoss ? 1 << 11 : 0;

            return iCompare;
        }

        public static bool operator ==(AuralizationMode left, AuralizationMode right)
        {
            return left.Equals(right);
60 61 62 63
        }

        public static bool operator !=(AuralizationMode left, AuralizationMode right)
        {
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
64
            return !(left.Equals(right));
65 66
        }
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
67

68
    private AuralizationMode AuraModeShadow = new AuralizationMode();
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
69

70 71
    public delegate void OnAuraStringChangedDelegate(string sAuraString);
    public event OnAuraStringChangedDelegate AuraStringChanged;
72 73 74

    void Update()
    {
75 76 77 78 79 80 81 82 83
        AuralizationMode AuraMode = UpdateAuraModeSettings();

        if (AuraMode == AuraModeShadow)
            return;

        string AuraString = "";

        if (AuraMode.DirectSound != AuraModeShadow.DirectSound)
        {
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
84
            AuraString = AuraMode.DirectSound ? "+DS" : "-DS";
85 86 87 88 89 90 91 92 93 94 95 96
            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);
        }
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
        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);
        }

146
        if (AuraMode.NearFieldEffects != AuraModeShadow.NearFieldEffects)
147
        {
148 149
            AuraString = AuraMode.NearFieldEffects ? "+NF" : "-NF";
            AuraModeShadow.NearFieldEffects = AuraMode.NearFieldEffects;
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
            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);
        }
169 170
    }

171 172
    public void TriggerAuraStringChanged(string externAuraString)
    {
Maurice Tayeb Andreas's avatar
[VAU]  
Maurice Tayeb Andreas committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        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;
189 190
        if (externAuraString == "+NF") NearFieldEffects = true;
        if (externAuraString == "-NF") NearFieldEffects = false;
Maurice Tayeb Andreas's avatar
[VAU]  
Maurice Tayeb Andreas committed
191 192 193 194
        if (externAuraString == "+DP") DopplerShifts = true;
        if (externAuraString == "-DP") DopplerShifts = false;
        if (externAuraString == "+SL") SphericalSpreadingLoss = true;
        if (externAuraString == "-SL") SphericalSpreadingLoss = false;
195 196
        AuraStringChanged(externAuraString);
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
197

198 199 200 201 202 203 204 205 206 207 208
    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;
209
        am.NearFieldEffects = NearFieldEffects;
210 211 212 213
        am.DopplerShifts = DopplerShifts;
        am.SphericalSpreadingLoss = SphericalSpreadingLoss;
        return am;
    }
214
}