예제 #1
0
        public void DrawEditor()
        {
            string saveHash = AssetDatabase.GetAssetPath(effect).GetHashCode().ToString();

            Range r = new Range(data.range.min, data.range.max);

            GUIHelpers.RangeField(ref r, "Frequency Range", "Frequencies that move outside this range will be clamped into it when creating the frequency curve.");
            if (data.range.min < .0f)
            {
                data.range.min = .0f;
            }
            if (data.range.max > 20000.0f)
            {
                data.range.max = 20000.0f;
            }

            if (r.min != data.range.min || r.max != data.range.max)
            {
                Undo.RecordObject(effect, "SounderEffect Frequency Range");
                data.range = r;
            }

            EditorGUI.BeginDisabledGroup(effect.frequencyManualCurve);

            float test = EditorGUILayout.Slider(new GUIContent("Frequency", "Starting frequency of the sound."), data.frequency, data.range.min, data.range.max);

            if (test != data.frequency)
            {
                Undo.RecordObject(effect, "SounderEffect Frequency");
                data.frequency = test;
            }

            test = data.delta;
            GUIHelpers.RangedSlider(ref test, 1000.0f, "Frequency Delta", "Frequency changes by this much per second.", saveHash, false);
            if (test != data.delta)
            {
                Undo.RecordObject(effect, "SounderEffect Frequency Delta");
                data.delta = test;
            }

            test = data.deltaAccel;
            GUIHelpers.RangedSlider(ref test, 100.0f, "Delta Acceleration", "Frequency delta accelerates by this much per second.", saveHash, false);
            if (test != data.deltaAccel)
            {
                Undo.RecordObject(effect, "SounderEffect Frequency Delta Acceleration");
                data.deltaAccel = test;
            }


            FrequencyData.CurveType ct = (FrequencyData.CurveType)EditorGUILayout.EnumPopup(new GUIContent("Frequency Curve Type", "Determines the tangents and tangent mode of the frequency curve"),
                                                                                            data.curveType);
            if (ct != data.curveType)
            {
                Undo.RecordObject(effect, "SounderEffect Curve Type");
                data.curveType = ct;
            }

            FrequencyJumps(ref data);

            EditorGUI.EndDisabledGroup();

            float amplitudeDuration = effect.AmplitudeCurve.keys[effect.AmplitudeCurve.keys.Length - 1].time;
            float frequencyDuration = amplitudeDuration;

            if (effect.FrequencyCurve.keys.Length > 0)
            {
                frequencyDuration = effect.FrequencyCurve.keys[effect.FrequencyCurve.keys.Length - 1].time;
            }
            frequencyDuration = Mathf.Max(frequencyDuration, amplitudeDuration);
            Rect frequencyRect = new Rect(0, effect.FrequencyData.range.min, frequencyDuration, effect.FrequencyData.range.max);

            EditorGUI.BeginChangeCheck();

            AnimationCurve ac = new AnimationCurve(effect.FrequencyCurve.keys);

            ac = EditorGUILayout.CurveField(new GUIContent("Frequency Curve", "The above values compile to this.\nCan be edited manually."), ac, Color.cyan, frequencyRect);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(effect, "SounderEffect Frequency Curve");
                effect.FrequencyCurve = ac;

                if (!effect.frequencyManualCurve)
                {
                    effect.frequencyManualCurve = true;
                    return;
                }
            }

            if (effect.frequencyManualCurve)
            {
                EditorGUILayout.HelpBox("Frequency curve manualy edited. \nEditing sliders will overwrite manual curve changes.", MessageType.Warning);
                if (GUILayout.Button("Edit Frequency Sliders"))
                {
                    Undo.RecordObject(effect, "SounderEffect Frequency Manual Curve Disabled");
                    effect.frequencyManualCurve = false;
                }
            }
        }