Example #1
0
        void FrequencyJumpField(ref FrequencyJump jump, ref FrequencyData data, int index)
        {
            string saveHash = AssetDatabase.GetAssetPath(effect).GetHashCode().ToString();

            EditorGUI.indentLevel++;
            jump.start = EditorGUILayout.Slider(new GUIContent("Start Time", "Time the jumper starts. In Seconds."), jump.start, .0f, 1.0f);

            GUIHelpers.RangedSlider(ref jump.value, 1000.0f, "Jump " + index.ToString() + " Value",
                                    "How much the frequency changes. In Hertz.", saveHash, false);
            jump.repeatTime =
                EditorGUILayout.Slider(new GUIContent("Repeat Time", "Time to wait before each repeat. In Seconds."), jump.repeatTime, -.0f, 1.0f);
            jump.repeats = EditorGUILayout.IntSlider(new GUIContent("Jump Repeats", "How many times to repeat the jump. If negative repeats until the sound ends."), jump.repeats, -1, 25);
            EditorGUI.indentLevel--;
        }
        public override void OnInspectorGUI()
        {
            if (Application.isPlaying)
            {
                return;
            }

            MakePlayer();

            int sampleRate = EditorGUILayout.IntField(new GUIContent("Sample Rate", "Samples per second. Smaller values build faster larger values sound better."), effect.SampleRate);

            if (sampleRate > 50000)
            {
                sampleRate = 50000;
            }
            if (sampleRate > 1 && effect.SampleRate != sampleRate)
            {
                Undo.RecordObject(effect, "SounderEffect Sample Rate");
                effect.SampleRate = sampleRate;
            }


            Oscillator.WaveForm form = (Oscillator.WaveForm)EditorGUILayout.EnumPopup(new GUIContent("Waveform", "Waveform determines the base timbre of the sound."), effect.waveForm);
            if (form != effect.waveForm)
            {
                Undo.RecordObject(effect, "SounderEffect WaveForm");
                effect.waveForm = form;
            }

            #region WaveDraw
            Rect r = EditorGUILayout.BeginHorizontal();
            r.height = 48;

            if (waveTexture == null || GUI.changed || waveTexture.width != r.width)
            {
                if (waveTexture != null)
                {
                    DestroyImmediate(waveTexture);
                }
                waveTexture = WaveDrawer.TextureFromSamples(Oscillator.GetWaveTable(effect.waveForm), (int)r.width, (int)r.height);
            }
            EditorGUI.DrawPreviewTexture(r, waveTexture);

            EditorGUILayout.LabelField(new GUIContent(), GUILayout.Width(r.width), GUILayout.Height(r.height));
            EditorGUILayout.EndHorizontal();
            #endregion

            EditorGUILayout.Separator();

            float delay = EditorGUILayout.FloatField(new GUIContent("Delay", "Delay in seconds before starting"), effect.delay);
            if (delay < .0f)
            {
                delay = .0f;
            }

            if (delay != effect.delay)
            {
                Undo.RecordObject(effect, "SounderEffect Delay");
                effect.delay = delay;
            }

            EditorGUILayout.Separator();

            amplitudeEditor.DrawEditor();

            EditorGUILayout.Separator();

            frequencyEditor.DrawEditor();

            string saveHash = AssetDatabase.GetAssetPath(effect).GetHashCode().ToString();

            EditorGUILayout.Separator();
            float test = EditorGUILayout.Slider(new GUIContent("LFO Amplitude", "Amount the low frequency oscillator affects the sound."), effect.LFOAmplitude, .0f, 1.0f);
            if (test != effect.LFOAmplitude)
            {
                Undo.RecordObject(effect, "SounderEffect LFO Amplitude");
                effect.LFOAmplitude = test;
            }

            if (effect.LFOAmplitude > float.Epsilon)
            {
                Oscillator.WaveForm lfoForm = (Oscillator.WaveForm)EditorGUILayout.EnumPopup(new GUIContent("LFO Waveform", "Low Frequency Oscillator."), effect.LFOForm);
                if (lfoForm != effect.LFOForm)
                {
                    Undo.RecordObject(effect, "SounderEffect LFO WaveForm");
                    effect.LFOForm = lfoForm;
                }

                test = effect.LFOFrequency;
                GUIHelpers.RangedSlider(ref test, 100.0f, "LFO Frequency",
                                        "Frequency of the low frequency oscillator.", saveHash, false);
                if (test != effect.LFOFrequency)
                {
                    Undo.RecordObject(effect, "SounderEffect LFO Frequency");
                    effect.LFOFrequency = test;
                }
            }

            EditorGUILayout.Separator();
            test = EditorGUILayout.Slider(new GUIContent("Flanger Amplitude", "Resonates a copy of the sound."), effect.flangerAmplitude, .0f, 1.0f);
            if (test != effect.flangerAmplitude)
            {
                Undo.RecordObject(effect, "SounderEffect Flanger Amplitude");
                effect.flangerAmplitude = test;
            }
            if (effect.flangerAmplitude > float.Epsilon)
            {
                test = effect.flangerOffset;
                GUIHelpers.RangedSlider(ref test, 1.0f, "Flanger Offset", "Offset of the flanger, as a percent of the wavetable.", saveHash, false);
                if (test != effect.flangerOffset)
                {
                    Undo.RecordObject(effect, "SounderEffect Flanger Offset");
                    effect.flangerOffset = test;
                }

                test = effect.flangerOffsetDelta;
                GUIHelpers.RangedSlider(ref test, 25.0f, "Offset Delta", "Accellerate the flanger offset by this much.", saveHash, false);
                if (test != effect.flangerOffsetDelta)
                {
                    Undo.RecordObject(effect, "SounderEffect Flanger Offset Delta");
                    effect.flangerOffsetDelta = test;
                }
            }

            EditorGUILayout.Separator();
            test = EditorGUILayout.Slider(new GUIContent("Phase Reset", "Resets most variables to their starting values after this much time has passed."), effect.phaseReset, .0f, effect.Duration);
            if (test != effect.phaseReset)
            {
                Undo.RecordObject(effect, "SounderEffect Phase Reset");
                effect.phaseReset = test;
            }

            test = effect.echoTime;
            GUIHelpers.RangedSlider(ref test, 1.0f, "Echo Time", "Echoes the sound every echoTime seconds", saveHash, true);
            if (test != effect.echoTime)
            {
                Undo.RecordObject(effect, "SounderEffect Echo Time");
                effect.echoTime = test;
            }
            if (effect.echoTime > float.Epsilon)
            {
                test = EditorGUILayout.Slider(new GUIContent("Echo Value", "How loud the echo is as a percent of the original sound"), effect.echoValue, 0f, 1.0f);
                if (test != effect.echoValue)
                {
                    Undo.RecordObject(effect, "SounderEffect Echo Value");
                    effect.echoValue = test;
                }

                int itest = EditorGUILayout.IntSlider(new GUIContent("Echo Count", "How many times to echo. If less than 0 echoes until very quiet."), effect.echoCount, -1, 10);
                if (itest != effect.echoCount)
                {
                    Undo.RecordObject(effect, "SounderEffect Echo Count");
                    effect.echoCount = itest;
                }
            }

            EditorGUILayout.Separator();
            test = effect.highPass;
            GUIHelpers.RangedSlider(ref test, 8000.0f, "High Pass", "Frequencies lower than this are attenuated. Set to 0 to do nothing.", saveHash, true);
            if (test != effect.highPass)
            {
                Undo.RecordObject(effect, "SounderEffect High Pass");
                effect.highPass = test;
            }

            test = effect.lowPass;
            GUIHelpers.RangedSlider(ref test, 8000.0f, "Low Pass", "Frequencies higher than this are attenuated. Set to 0 to do nothing.", saveHash, true);
            if (test != effect.lowPass)
            {
                Undo.RecordObject(effect, "SounderEffect Low Pass");
                effect.lowPass = test;
            }

            test = effect.Q;
            GUIHelpers.RangedSlider(ref test, 10.0f, "Resonance", "Amount to attenuate outside frequencies.", saveHash, true);
            if (test != effect.Q)
            {
                Undo.RecordObject(effect, "SounderEffect Resonance");
                effect.Q = test;
            }
            EditorGUILayout.Separator();

            SubEffects();

            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            bool play = false;
            if (GUILayout.Button("Play"))
            {
                play = true;
            }
            EditorGUILayout.Separator();
            EditorGUIUtility.labelWidth = GUI.skin.label.CalcSize(new GUIContent("Play on Change")).x;
            playOnChange = EditorGUILayout.Toggle("Play on Change", playOnChange);
            EditorGUIUtility.labelWidth = GUI.skin.label.CalcSize(new GUIContent("Play Looping")).x;
            playLooping = EditorGUILayout.Toggle("Play Looping", playLooping);
            EditorGUIUtility.labelWidth = 0;

            if (GUILayout.Button("Save to .Wav"))
            {
                string path = "";
                try { path = Path.GetDirectoryName(AssetDatabase.GetAssetPath(effect)); } catch {}

                string wavName = EditorUtility.SaveFilePanel("Save sound to wav", path, effect.name, "wav");
                WavBuilder.WriteWav(wavName, effect.GetClip());
                AssetDatabase.Refresh();
            }
            GUILayout.EndHorizontal();


            play = play | DrawPresets();

            if (GUILayout.Button("Mutate"))
            {
                Undo.RecordObject(effect, "SounderEffect Mutate");

                SounderEffect se = Presets.Mutate(effect);
                effect.Copy(se);
                DestroyImmediate(se);
                play = true;
            }

            if (Event.current.type == EventType.ValidateCommand && Event.current.commandName.CompareTo("UndoRedoPerformed") == 0)
            {
                GUI.changed = true;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(effect);
                player.Stop();
                if (player.clip != null)
                {
                    DestroyImmediate(player.clip);
                }
                effect.MakeClip();

                if (effectTexture != null)
                {
                    DestroyImmediate(effectTexture);
                }
                effectTexture = null;
            }

            if (play || (GUI.changed && playOnChange))
            {
                player.clip   = effect.GetClip();
                player.volume = 1.0f;
                player.loop   = playLooping;
                player.Play();
            }
        }
Example #3
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;
                }
            }
        }