VAUAuralizationMode.cs 8.62 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
	[Tooltip("Toggle direct sound")]
8
    public bool DirectSound = true;
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

	[Tooltip("Toggle early reflections")]
	public bool EarlyReflections = false;

	[Tooltip("Toggle diffuse decay")]
	public bool DiffuseDecay = false;

	[Tooltip("Toggle source directivity")]
	public bool SourceDirectivity = true;

	[Tooltip("Toggle air absorption")]
	public bool AirAbsorption = false;

	[Tooltip("Toggle atmospheric temporal variations")]
	public bool AtmosphericTemporalVariations = false;

	[Tooltip("Toggle scattering")]
	public bool Scattering = false;

	[Tooltip("Toggle diffraction")]
	public bool Diffraction = false;

	[Tooltip("Toggle hear-field effects")]
	public bool NearFieldEffects = false;

	[Tooltip("Toggle Doppler shifts")]
	public bool DopplerShifts = true;

	[Tooltip("Toggle spherical spreading loss")]
38 39
    public bool SphericalSpreadingLoss = true;

40
    protected class AuralizationMode : System.Object
41 42 43 44 45 46 47 48 49
    {
        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;
50
        public bool NearFieldEffects = true;
51 52 53
        public bool DopplerShifts = true;
        public bool SphericalSpreadingLoss = true;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
54 55 56 57 58 59
        public override bool Equals(System.Object other)
        {
            return (GetHashCode() == other.GetHashCode());
        }

        override public int GetHashCode()
60 61 62
        {
            int iCompare = 0;

Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
63 64 65 66 67 68 69 70
            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;
71
            iCompare += NearFieldEffects ? 1 << 9 : 0;
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
72 73 74 75 76 77 78 79 80
            iCompare += DopplerShifts ? 1 << 10 : 0;
            iCompare += SphericalSpreadingLoss ? 1 << 11 : 0;

            return iCompare;
        }

        public static bool operator ==(AuralizationMode left, AuralizationMode right)
        {
            return left.Equals(right);
81 82 83 84
        }

        public static bool operator !=(AuralizationMode left, AuralizationMode right)
        {
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
85
            return !(left.Equals(right));
86 87
        }
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
88

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

91 92
    public delegate void OnAuraStringChangedDelegate(string sAuraString);
    public event OnAuraStringChangedDelegate AuraStringChanged;
93 94 95

    void Update()
    {
96 97 98 99 100 101 102 103 104
        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
105
            AuraString = AuraMode.DirectSound ? "+DS" : "-DS";
106 107 108 109 110 111 112 113 114 115 116 117
            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);
        }
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 158 159 160 161 162 163 164 165 166
        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);
        }

167
        if (AuraMode.NearFieldEffects != AuraModeShadow.NearFieldEffects)
168
        {
169 170
            AuraString = AuraMode.NearFieldEffects ? "+NF" : "-NF";
            AuraModeShadow.NearFieldEffects = AuraMode.NearFieldEffects;
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
            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);
        }
190 191
    }

192 193
    public void TriggerAuraStringChanged(string externAuraString)
    {
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
        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;
210 211
        if (externAuraString == "+NF") NearFieldEffects = true;
        if (externAuraString == "-NF") NearFieldEffects = false;
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
212 213 214 215
        if (externAuraString == "+DP") DopplerShifts = true;
        if (externAuraString == "-DP") DopplerShifts = false;
        if (externAuraString == "+SL") SphericalSpreadingLoss = true;
        if (externAuraString == "-SL") SphericalSpreadingLoss = false;
216 217
        AuraStringChanged(externAuraString);
    }
Dipl.-Ing. Jonas Stienen's avatar
Dipl.-Ing. Jonas Stienen committed
218

219
    protected AuralizationMode UpdateAuraModeSettings()
220 221 222 223 224 225 226 227 228 229
    {
        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;
230
        am.NearFieldEffects = NearFieldEffects;
231 232 233 234
        am.DopplerShifts = DopplerShifts;
        am.SphericalSpreadingLoss = SphericalSpreadingLoss;
        return am;
    }
235
}