static private TargetChoiceField ( UnityEditor.SerializedProperty property, |
||
property | UnityEditor.SerializedProperty | |
label | ||
return | void |
internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue) { // AnimProp can be called from other classes so styes have not necessarily been inited yet. InitStyles(); if (prop.hasMultipleDifferentValues) { EditorGUILayout.TargetChoiceField(prop, label); return; } AnimationCurve curve = prop.animationCurveValue; if (curve == null) { Debug.LogError(label.text + " curve is null!"); return; } else if (curve.length == 0) { Debug.LogError(label.text + " curve has no keys!"); return; } Rect position = EditorGUILayout.GetControlRect(); EditorGUI.BeginProperty(position, label, prop); if (curve.length != 1) { using (new EditorGUI.DisabledScope(true)) { EditorGUI.LabelField(position, label.text, ms_Styles.controlledByCurveLabel); } } else { float f = useNormalizedValue ? Mathf.Lerp(min, max, curve.keys[0].value) : curve.keys[0].value; f = MathUtils.DiscardLeastSignificantDecimal(f); EditorGUI.BeginChangeCheck(); if (max > min) { f = EditorGUI.Slider(position, label, f, min, max); } else { f = EditorGUI.Slider(position, label, f, max, min); } if (EditorGUI.EndChangeCheck()) { Keyframe kf = curve.keys[0]; kf.time = 0.0f; kf.value = useNormalizedValue ? Mathf.InverseLerp(min, max, f) : f; curve.MoveKey(0, kf); } } EditorGUI.EndProperty(); prop.animationCurveValue = curve; }
internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue) { InitStyles(); if (prop.hasMultipleDifferentValues) { EditorGUILayout.TargetChoiceField(prop, label, new GUILayoutOption[0]); } else { AnimationCurve animationCurveValue = prop.animationCurveValue; if (animationCurveValue == null) { Debug.LogError(label.text + " curve is null!"); } else if (animationCurveValue.length == 0) { Debug.LogError(label.text + " curve has no keys!"); } else { if (animationCurveValue.length != 1) { using (new EditorGUI.DisabledScope(true)) { EditorGUILayout.LabelField(label.text, ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]); } } else { float v = !useNormalizedValue ? animationCurveValue.keys[0].value : Mathf.Lerp(min, max, animationCurveValue.keys[0].value); v = MathUtils.DiscardLeastSignificantDecimal(v); EditorGUI.BeginChangeCheck(); if (max > min) { v = EditorGUILayout.Slider(label, v, min, max, new GUILayoutOption[0]); } else { v = EditorGUILayout.Slider(label, v, max, min, new GUILayoutOption[0]); } if (EditorGUI.EndChangeCheck()) { Keyframe key = animationCurveValue.keys[0]; key.time = 0f; key.value = !useNormalizedValue ? v : Mathf.InverseLerp(min, max, v); animationCurveValue.MoveKey(0, key); } } prop.animationCurveValue = animationCurveValue; } } }
private void Audio3DGUI() { EditorGUILayout.Slider(this.m_DopplerLevel, 0f, 5f, AudioSourceInspector.ms_Styles.dopplerLevelLabel, new GUILayoutOption[0]); EditorGUI.BeginChangeCheck(); AudioSourceInspector.AnimProp(AudioSourceInspector.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)) { SerializedProperty arg_C5_0 = this.m_AudioCurves[0].curveProp; GUIContent arg_C5_1 = AudioSourceInspector.ms_Styles.rolloffLabel; if (AudioSourceInspector.< > f__mg$cache0 == null) { AudioSourceInspector.< > f__mg$cache0 = new TargetChoiceHandler.TargetChoiceMenuFunction(AudioSourceInspector.SetRolloffToTarget); } EditorGUILayout.TargetChoiceField(arg_C5_0, arg_C5_1, AudioSourceInspector.< > f__mg$cache0, new GUILayoutOption[0]);
internal static void AnimProp(GUIContent label, SerializedProperty prop, float min, float max, bool useNormalizedValue) { AudioSourceInspector.InitStyles(); if (prop.hasMultipleDifferentValues) { EditorGUILayout.TargetChoiceField(prop, label, new GUILayoutOption[0]); return; } AnimationCurve animationCurveValue = prop.animationCurveValue; if (animationCurveValue == null) { Debug.LogError(label.text + " curve is null!"); return; } if (animationCurveValue.length == 0) { Debug.LogError(label.text + " curve has no keys!"); return; } if (animationCurveValue.length != 1) { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.LabelField(label.text, AudioSourceInspector.ms_Styles.controlledByCurveLabel, new GUILayoutOption[0]); EditorGUI.EndDisabledGroup(); } else { float num = (!useNormalizedValue) ? animationCurveValue.keys[0].value : Mathf.Lerp(min, max, animationCurveValue.keys[0].value); num = MathUtils.DiscardLeastSignificantDecimal(num); EditorGUI.BeginChangeCheck(); if (max > min) { num = EditorGUILayout.Slider(label, num, min, max, new GUILayoutOption[0]); } else { num = EditorGUILayout.Slider(label, num, max, min, new GUILayoutOption[0]); } if (EditorGUI.EndChangeCheck()) { Keyframe key = animationCurveValue.keys[0]; key.time = 0f; key.value = ((!useNormalizedValue) ? num : Mathf.InverseLerp(min, max, num)); animationCurveValue.MoveKey(0, key); } } prop.animationCurveValue = animationCurveValue; }
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; } } } } } }
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; } } } } }
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; } } } } }