GetListenerPos() private méthode

private GetListenerPos ( ) : Vector3
Résultat Vector3
Exemple #1
0
        private void OnEnable()
        {
            this.m_AudioClip             = base.serializedObject.FindProperty("m_audioClip");
            this.m_PlayOnAwake           = base.serializedObject.FindProperty("m_PlayOnAwake");
            this.m_Volume                = base.serializedObject.FindProperty("m_Volume");
            this.m_Pitch                 = base.serializedObject.FindProperty("m_Pitch");
            this.m_Loop                  = base.serializedObject.FindProperty("Loop");
            this.m_Mute                  = base.serializedObject.FindProperty("Mute");
            this.m_Spatialize            = base.serializedObject.FindProperty("Spatialize");
            this.m_SpatializePostEffects = base.serializedObject.FindProperty("SpatializePostEffects");
            this.m_Priority              = base.serializedObject.FindProperty("Priority");
            this.m_DopplerLevel          = base.serializedObject.FindProperty("DopplerLevel");
            this.m_MinDistance           = base.serializedObject.FindProperty("MinDistance");
            this.m_MaxDistance           = base.serializedObject.FindProperty("MaxDistance");
            this.m_Pan2D                 = base.serializedObject.FindProperty("Pan2D");
            this.m_RolloffMode           = base.serializedObject.FindProperty("rolloffMode");
            this.m_BypassEffects         = base.serializedObject.FindProperty("BypassEffects");
            this.m_BypassListenerEffects = base.serializedObject.FindProperty("BypassListenerEffects");
            this.m_BypassReverbZones     = base.serializedObject.FindProperty("BypassReverbZones");
            this.m_OutputAudioMixerGroup = base.serializedObject.FindProperty("OutputAudioMixerGroup");
            this.m_AudioCurves           = new AudioSourceInspector.AudioCurveWrapper[]
            {
                new AudioSourceInspector.AudioCurveWrapper(AudioSourceInspector.AudioCurveType.Volume, "Volume", 0, AudioSourceInspector.kRolloffCurveColor, base.serializedObject.FindProperty("rolloffCustomCurve"), 0f, 1f),
                new AudioSourceInspector.AudioCurveWrapper(AudioSourceInspector.AudioCurveType.SpatialBlend, "Spatial Blend", 1, AudioSourceInspector.kSpatialCurveColor, base.serializedObject.FindProperty("panLevelCustomCurve"), 0f, 1f),
                new AudioSourceInspector.AudioCurveWrapper(AudioSourceInspector.AudioCurveType.Spread, "Spread", 2, AudioSourceInspector.kSpreadCurveColor, base.serializedObject.FindProperty("spreadCustomCurve"), 0f, 1f),
                new AudioSourceInspector.AudioCurveWrapper(AudioSourceInspector.AudioCurveType.Lowpass, "Low-Pass", 3, AudioSourceInspector.kLowPassCurveColor, null, 0f, 1f),
                new AudioSourceInspector.AudioCurveWrapper(AudioSourceInspector.AudioCurveType.ReverbZoneMix, "Reverb Zone Mix", 4, AudioSourceInspector.kReverbZoneMixCurveColor, base.serializedObject.FindProperty("reverbZoneMixCustomCurve"), 0f, 1.1f)
            };
            AudioSourceInspector.m_CurveEditorSettings.hRangeMin = 0f;
            AudioSourceInspector.m_CurveEditorSettings.vRangeMin = 0f;
            AudioSourceInspector.m_CurveEditorSettings.vRangeMax = 1.1f;
            AudioSourceInspector.m_CurveEditorSettings.hRangeMax = 1f;
            AudioSourceInspector.m_CurveEditorSettings.vSlider   = false;
            AudioSourceInspector.m_CurveEditorSettings.hSlider   = false;
            TickStyle tickStyle = new TickStyle();

            tickStyle.tickColor.color = new Color(0f, 0f, 0f, 0.15f);
            tickStyle.distLabel       = 30;
            AudioSourceInspector.m_CurveEditorSettings.hTickStyle = tickStyle;
            TickStyle tickStyle2 = new TickStyle();

            tickStyle2.tickColor.color = new Color(0f, 0f, 0f, 0.15f);
            tickStyle2.distLabel       = 20;
            AudioSourceInspector.m_CurveEditorSettings.vTickStyle        = tickStyle2;
            AudioSourceInspector.m_CurveEditorSettings.undoRedoSelection = true;
            this.m_CurveEditor          = new CurveEditor(new Rect(0f, 0f, 1000f, 100f), new CurveWrapper[0], false);
            this.m_CurveEditor.settings = AudioSourceInspector.m_CurveEditorSettings;
            this.m_CurveEditor.margin   = 25f;
            this.m_CurveEditor.SetShownHRangeInsideMargins(0f, 1f);
            this.m_CurveEditor.SetShownVRangeInsideMargins(0f, 1.1f);
            this.m_CurveEditor.ignoreScrollWheelUntilClicked = true;
            this.m_LastSourcePosition   = this.GetSourcePos(base.target);
            this.m_LastListenerPosition = AudioUtil.GetListenerPos();
            EditorApplication.update    = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.Update));
            Undo.undoRedoPerformed      = (Undo.UndoRedoCallback)Delegate.Combine(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(this.UndoRedoPerformed));
            this.m_Expanded3D           = EditorPrefs.GetBool("AudioSourceExpanded3D", this.m_Expanded3D);
        }
Exemple #2
0
        private void Update()
        {
            Vector3 listenerPos = AudioUtil.GetListenerPos();

            if ((this.m_LastListenerPosition - listenerPos).sqrMagnitude > 0.0001f)
            {
                this.m_LastListenerPosition = listenerPos;
                base.Repaint();
            }
        }
        private void Update()
        {
            Vector3 listenerPos = AudioUtil.GetListenerPos();

            if ((double)(this.m_LastListenerPosition - listenerPos).sqrMagnitude <= 9.99999974737875E-05)
            {
                return;
            }
            this.m_LastListenerPosition = listenerPos;
            this.Repaint();
        }
Exemple #4
0
        private void Update()
        {
            Vector3 sourcePos   = this.GetSourcePos(base.target);
            Vector3 listenerPos = AudioUtil.GetListenerPos();

            if ((this.m_LastSourcePosition - sourcePos).sqrMagnitude > 0.0001f || (this.m_LastListenerPosition - listenerPos).sqrMagnitude > 0.0001f)
            {
                this.m_LastSourcePosition   = sourcePos;
                this.m_LastListenerPosition = listenerPos;
                base.Repaint();
            }
        }
Exemple #5
0
        private void Update()
        {
            // listener moved?
            Vector3 sourcePos   = GetSourcePos(target);
            Vector3 listenerPos = AudioUtil.GetListenerPos();

            if ((m_LastSourcePosition - sourcePos).sqrMagnitude > EPSILON || (m_LastListenerPosition - listenerPos).sqrMagnitude > EPSILON)
            {
                m_LastSourcePosition   = sourcePos;
                m_LastListenerPosition = listenerPos;
                Repaint();
            }
        }
Exemple #6
0
        private void Audio3DGUI()
        {
            EditorGUILayout.Slider(m_DopplerLevel, 0.0f, 5.0f, Styles.dopplerLevelLabel);

            // Spread control
            AnimProp(Styles.spreadLabel, m_AudioCurves[kSpreadCurveID].curveProp, 0.0f, 360.0f, true);

            // Rolloff mode
            if (m_RolloffMode.hasMultipleDifferentValues ||
                (m_RolloffMode.enumValueIndex == (int)AudioRolloffMode.Custom && m_AudioCurves[kRolloffCurveID].curveProp.hasMultipleDifferentValues)
                )
            {
                EditorGUILayout.TargetChoiceField(m_AudioCurves[kRolloffCurveID].curveProp, Styles.rolloffLabel, SetRolloffToTarget);
            }
            else
            {
                EditorGUILayout.PropertyField(m_RolloffMode, Styles.rolloffLabel);

                if ((AudioRolloffMode)m_RolloffMode.enumValueIndex != AudioRolloffMode.Custom)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(m_MinDistance);
                    if (EditorGUI.EndChangeCheck())
                    {
                        m_MinDistance.floatValue = Mathf.Clamp(m_MinDistance.floatValue, 0, m_MaxDistance.floatValue / 1.01f);
                    }
                }
                else
                {
                    using (new EditorGUI.DisabledScope(true))
                    {
                        EditorGUILayout.LabelField(m_MinDistance.displayName, Styles.controlledByCurveLabel);
                    }
                }
            }

            // Max distance control
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_MaxDistance);
            if (EditorGUI.EndChangeCheck())
            {
                m_MaxDistance.floatValue = Mathf.Min(Mathf.Max(Mathf.Max(m_MaxDistance.floatValue, 0.01f), m_MinDistance.floatValue * 1.01f), 1000000.0f);
            }

            Rect r = GUILayoutUtility.GetAspectRect(1.333f, GUI.skin.textField);

            r.xMin += EditorGUI.indent;
            if (Event.current.type != EventType.Layout && Event.current.type != EventType.Used)
            {
                m_CurveEditor.rect = new Rect(r.x, r.y, r.width, r.height);
            }

            // Draw Curve Editor
            UpdateWrappersAndLegend();
            GUI.Label(m_CurveEditor.drawRect, GUIContent.none, "TextField");

            m_CurveEditor.hRangeLocked = Event.current.shift;
            m_CurveEditor.vRangeLocked = EditorGUI.actionKey;

            m_CurveEditor.OnGUI();

            // Draw current listener position
            if (targets.Length == 1)
            {
                AudioSource   t             = (AudioSource)target;
                AudioListener audioListener = (AudioListener)FindObjectOfType(typeof(AudioListener));
                if (audioListener != null)
                {
                    float distToListener = (AudioUtil.GetListenerPos() - t.transform.position).magnitude;
                    DrawLabel("Listener", distToListener, r);
                }
            }

            // Draw legend
            DrawLegend();

            if (!m_CurveEditor.InLiveEdit())
            {
                // Check if any of the curves changed
                foreach (AudioCurveWrapper audioCurve in m_AudioCurves)
                {
                    if ((m_CurveEditor.GetCurveWrapperFromID(audioCurve.id) != null) && (m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).changed))
                    {
                        AnimationCurve changedCurve = m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).curve;

                        // Never save a curve with no keys
                        if (changedCurve.length > 0)
                        {
                            audioCurve.curveProp.animationCurveValue = changedCurve;
                            m_CurveEditor.GetCurveWrapperFromID(audioCurve.id).changed = false;

                            // Volume curve special handling
                            if (audioCurve.type == AudioCurveType.Volume)
                            {
                                m_RolloffMode.enumValueIndex = (int)AudioRolloffMode.Custom;
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
        void OnEnable()
        {
            m_AudioClip             = serializedObject.FindProperty("m_audioClip");
            m_PlayOnAwake           = serializedObject.FindProperty("m_PlayOnAwake");
            m_Volume                = serializedObject.FindProperty("m_Volume");
            m_Pitch                 = serializedObject.FindProperty("m_Pitch");
            m_Loop                  = serializedObject.FindProperty("Loop");
            m_Mute                  = serializedObject.FindProperty("Mute");
            m_Spatialize            = serializedObject.FindProperty("Spatialize");
            m_SpatializePostEffects = serializedObject.FindProperty("SpatializePostEffects");
            m_Priority              = serializedObject.FindProperty("Priority");
            m_DopplerLevel          = serializedObject.FindProperty("DopplerLevel");
            m_MinDistance           = serializedObject.FindProperty("MinDistance");
            m_MaxDistance           = serializedObject.FindProperty("MaxDistance");
            m_Pan2D                 = serializedObject.FindProperty("Pan2D");
            m_RolloffMode           = serializedObject.FindProperty("rolloffMode");
            m_BypassEffects         = serializedObject.FindProperty("BypassEffects");
            m_BypassListenerEffects = serializedObject.FindProperty("BypassListenerEffects");
            m_BypassReverbZones     = serializedObject.FindProperty("BypassReverbZones");
            m_OutputAudioMixerGroup = serializedObject.FindProperty("OutputAudioMixerGroup");

            m_AudioCurves = new AudioCurveWrapper[]
            {
                new AudioCurveWrapper(AudioCurveType.Volume, "Volume", kRolloffCurveID, kRolloffCurveColor, serializedObject.FindProperty("rolloffCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.SpatialBlend, "Spatial Blend", kSpatialBlendCurveID, kSpatialCurveColor, serializedObject.FindProperty("panLevelCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.Spread, "Spread", kSpreadCurveID, kSpreadCurveColor, serializedObject.FindProperty("spreadCustomCurve"), 0, 1),
                new AudioCurveWrapper(AudioCurveType.Lowpass, "Low-Pass", kLowPassCurveID, kLowPassCurveColor, null, 0, 1),
                new AudioCurveWrapper(AudioCurveType.ReverbZoneMix, "Reverb Zone Mix", kReverbZoneMixCurveID, kReverbZoneMixCurveColor, serializedObject.FindProperty("reverbZoneMixCustomCurve"), 0, 1.1f)
            };

            m_CurveEditorSettings.hRangeMin = 0.0f;
            m_CurveEditorSettings.vRangeMin = 0.0f;
            m_CurveEditorSettings.vRangeMax = 1.1f;
            m_CurveEditorSettings.hRangeMax = 1.0f;
            m_CurveEditorSettings.vSlider   = false;
            m_CurveEditorSettings.hSlider   = false;

            TickStyle hTS = new TickStyle();

            hTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            hTS.distLabel       = 30;
            m_CurveEditorSettings.hTickStyle = hTS;
            TickStyle vTS = new TickStyle();

            vTS.tickColor.color = new Color(0.0f, 0.0f, 0.0f, 0.15f);
            vTS.distLabel       = 20;
            m_CurveEditorSettings.vTickStyle = vTS;

            m_CurveEditorSettings.undoRedoSelection = true;

            m_CurveEditor          = new CurveEditor(new Rect(0, 0, 1000, 100), new CurveWrapper[0], false);
            m_CurveEditor.settings = m_CurveEditorSettings;
            m_CurveEditor.margin   = 25;
            m_CurveEditor.SetShownHRangeInsideMargins(0.0f, 1.0f);
            m_CurveEditor.SetShownVRangeInsideMargins(0.0f, 1.1f);
            m_CurveEditor.ignoreScrollWheelUntilClicked = true;

            m_LastSourcePosition      = GetSourcePos(target);
            m_LastListenerPosition    = AudioUtil.GetListenerPos();
            EditorApplication.update += Update;

            m_Expanded3D = EditorPrefs.GetBool("AudioSourceExpanded3D", m_Expanded3D);
        }
Exemple #8
0
        private void Audio3DGUI()
        {
            EditorGUILayout.Slider(this.m_DopplerLevel, 0f, 5f, AudioSourceInspector.ms_Styles.dopplerLevelLabel, new GUILayoutOption[0]);
            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            if (this.m_RolloffMode.hasMultipleDifferentValues || (this.m_RolloffMode.enumValueIndex == 2 && this.m_AudioCurves[0].curveProp.hasMultipleDifferentValues))
            {
                EditorGUILayout.TargetChoiceField(this.m_AudioCurves[0].curveProp, AudioSourceInspector.ms_Styles.rolloffLabel, new TargetChoiceHandler.TargetChoiceMenuFunction(AudioSourceInspector.SetRolloffToTarget), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.m_RolloffMode, AudioSourceInspector.ms_Styles.rolloffLabel, new GUILayoutOption[0]);
                EditorGUI.indentLevel++;
                if (this.m_RolloffMode.enumValueIndex != 2)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(this.m_MinDistance, new GUILayoutOption[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.m_MinDistance.floatValue = Mathf.Clamp(this.m_MinDistance.floatValue, 0f, this.m_MaxDistance.floatValue / 1.01f);
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.LabelField(this.m_MinDistance.displayName, AudioSourceInspector.ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
                    EditorGUI.EndDisabledGroup();
                }
                EditorGUI.indentLevel--;
            }
            AudioSourceInspector.AnimProp(AudioSourceInspector.ms_Styles.spreadLabel, this.m_AudioCurves[2].curveProp, 0f, 360f, true);
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_MaxDistance, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.m_MaxDistance.floatValue = Mathf.Min(Mathf.Max(Mathf.Max(this.m_MaxDistance.floatValue, 0.01f), this.m_MinDistance.floatValue * 1.01f), 1000000f);
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_RefreshCurveEditor = true;
            }
            Rect aspectRect = GUILayoutUtility.GetAspectRect(1.333f, GUI.skin.textField);

            aspectRect.xMin += EditorGUI.indent;
            if (Event.current.type != EventType.Layout && Event.current.type != EventType.Used)
            {
                this.m_CurveEditor.rect = new Rect(aspectRect.x, aspectRect.y, aspectRect.width, aspectRect.height);
            }
            this.UpdateWrappersAndLegend();
            GUI.Label(this.m_CurveEditor.drawRect, GUIContent.none, "TextField");
            this.m_CurveEditor.hRangeLocked = Event.current.shift;
            this.m_CurveEditor.vRangeLocked = EditorGUI.actionKey;
            this.m_CurveEditor.OnGUI();
            if (base.targets.Length == 1)
            {
                AudioSource   audioSource = (AudioSource)this.target;
                AudioListener x           = (AudioListener)UnityEngine.Object.FindObjectOfType(typeof(AudioListener));
                if (x != null)
                {
                    float magnitude = (AudioUtil.GetListenerPos() - audioSource.transform.position).magnitude;
                    this.DrawLabel("Listener", magnitude, aspectRect);
                }
            }
            this.DrawLegend();
            AudioSourceInspector.AudioCurveWrapper[] audioCurves = this.m_AudioCurves;
            for (int i = 0; i < audioCurves.Length; i++)
            {
                AudioSourceInspector.AudioCurveWrapper audioCurveWrapper = audioCurves[i];
                if (this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id) != null && this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).changed)
                {
                    AnimationCurve curve = this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).curve;
                    if (curve.length > 0)
                    {
                        audioCurveWrapper.curveProp.animationCurveValue = curve;
                        this.m_CurveEditor.getCurveWrapperById(audioCurveWrapper.id).changed = false;
                        if (audioCurveWrapper.type == AudioSourceInspector.AudioCurveType.Volume)
                        {
                            this.m_RolloffMode.enumValueIndex = 2;
                        }
                        if (audioCurveWrapper.type == AudioSourceInspector.AudioCurveType.Lowpass && audioCurveWrapper.curveProp.animationCurveValue.length == 1)
                        {
                            Keyframe keyframe = audioCurveWrapper.curveProp.animationCurveValue.keys[0];
                            this.m_CutoffFrequency.floatValue = (1f - keyframe.value) * 22000f;
                        }
                    }
                }
            }
        }
Exemple #9
0
        private void Audio3DGUI()
        {
            EditorGUILayout.Slider(this.m_DopplerLevel, 0f, 5f, ms_Styles.dopplerLevelLabel, new GUILayoutOption[0]);
            EditorGUI.BeginChangeCheck();
            AnimProp(ms_Styles.spreadLabel, this.m_AudioCurves[2].curveProp, 0f, 360f, true);
            if (this.m_RolloffMode.hasMultipleDifferentValues || ((this.m_RolloffMode.enumValueIndex == 2) && this.m_AudioCurves[0].curveProp.hasMultipleDifferentValues))
            {
                EditorGUILayout.TargetChoiceField(this.m_AudioCurves[0].curveProp, ms_Styles.rolloffLabel, new TargetChoiceHandler.TargetChoiceMenuFunction(AudioSourceInspector.SetRolloffToTarget), new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.PropertyField(this.m_RolloffMode, ms_Styles.rolloffLabel, new GUILayoutOption[0]);
                if (this.m_RolloffMode.enumValueIndex != 2)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUILayout.PropertyField(this.m_MinDistance, new GUILayoutOption[0]);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.m_MinDistance.floatValue = Mathf.Clamp(this.m_MinDistance.floatValue, 0f, this.m_MaxDistance.floatValue / 1.01f);
                    }
                }
                else
                {
                    EditorGUI.BeginDisabledGroup(true);
                    EditorGUILayout.LabelField(this.m_MinDistance.displayName, ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]);
                    EditorGUI.EndDisabledGroup();
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(this.m_MaxDistance, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.m_MaxDistance.floatValue = Mathf.Min(Mathf.Max(Mathf.Max(this.m_MaxDistance.floatValue, 0.01f), this.m_MinDistance.floatValue * 1.01f), 1000000f);
            }
            if (EditorGUI.EndChangeCheck())
            {
                this.m_RefreshCurveEditor = true;
            }
            Rect aspectRect = GUILayoutUtility.GetAspectRect(1.333f, GUI.skin.textField);

            aspectRect.xMin += EditorGUI.indent;
            if ((Event.current.type != EventType.Layout) && (Event.current.type != EventType.Used))
            {
                this.m_CurveEditor.rect = new Rect(aspectRect.x, aspectRect.y, aspectRect.width, aspectRect.height);
            }
            this.UpdateWrappersAndLegend();
            GUI.Label(this.m_CurveEditor.drawRect, GUIContent.none, "TextField");
            this.m_CurveEditor.hRangeLocked = Event.current.shift;
            this.m_CurveEditor.vRangeLocked = EditorGUI.actionKey;
            this.m_CurveEditor.OnGUI();
            if (base.targets.Length == 1)
            {
                AudioSource   target   = (AudioSource)this.target;
                AudioListener listener = (AudioListener)Object.FindObjectOfType(typeof(AudioListener));
                if (listener != null)
                {
                    Vector3 vector    = AudioUtil.GetListenerPos() - target.transform.position;
                    float   magnitude = vector.magnitude;
                    this.DrawLabel("Listener", magnitude, aspectRect);
                }
            }
            this.DrawLegend();
            foreach (AudioCurveWrapper wrapper in this.m_AudioCurves)
            {
                if ((this.m_CurveEditor.getCurveWrapperById(wrapper.id) != null) && this.m_CurveEditor.getCurveWrapperById(wrapper.id).changed)
                {
                    AnimationCurve curve = this.m_CurveEditor.getCurveWrapperById(wrapper.id).curve;
                    if (curve.length > 0)
                    {
                        wrapper.curveProp.animationCurveValue = curve;
                        this.m_CurveEditor.getCurveWrapperById(wrapper.id).changed = false;
                        if (wrapper.type == AudioCurveType.Volume)
                        {
                            this.m_RolloffMode.enumValueIndex = 2;
                        }
                    }
                }
            }
        }