public FrequencyJump(FrequencyJump o)
 {
     value      = o.value;
     start      = o.start;
     repeatTime = o.repeatTime;
     repeats    = o.repeats;
 }
Beispiel #2
0
        void FrequencyJumps(ref FrequencyData data)
        {
            foldoutOpen = EditorGUILayout.Foldout(foldoutOpen, new GUIContent("Frequency Jumpers " + data.jumps.Length, "These jump the frequency up or down."));
            if (effect.frequencyManualCurve)
            {
                foldoutOpen = false;
            }

            if (foldoutOpen)
            {
                EditorGUI.indentLevel++;
                int count = EditorGUILayout.IntField(new GUIContent("Jumper Count"), data.jumps.Length);

                if (count != data.jumps.Length)
                {
                    if (count < 0)
                    {
                        count = 0;
                    }
                    FrequencyJump[] temp = new FrequencyJump[count];
                    for (int iii = 0; iii < data.jumps.Length || iii < count; iii++)
                    {
                        if (iii < data.jumps.Length && iii < count)
                        {
                            temp[iii] = data.jumps[iii];
                        }
                        else if (iii < temp.Length)
                        {
                            temp[iii] = new FrequencyJump();
                        }
                    }
                    data.jumps = temp;
                }
                while (subFolds.Count != count)
                {
                    if (subFolds.Count < count)
                    {
                        subFolds.Add(true);
                    }
                    else
                    {
                        subFolds.RemoveAt(subFolds.Count - 1);
                    }
                }

                for (int iii = 0; iii < data.jumps.Length; iii++)
                {
                    subFolds[iii] = EditorGUILayout.Foldout(subFolds[iii], new GUIContent("Jumper " + iii.ToString()));
                    if (subFolds[iii])
                    {
                        FrequencyJumpField(ref data.jumps[iii], ref data, iii);

                        EditorGUILayout.Separator();
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
        public static SounderEffect Pickup()
        {
            SounderEffect e = ScriptableObject.CreateInstance <SounderEffect>();

            e.waveForm = GetRandomWaveForm(Oscillator.WaveForm.Sine, Oscillator.WaveForm.HarmonicSaw, Oscillator.WaveForm.Triangle, Oscillator.WaveForm.HarmonicTriangle, Oscillator.WaveForm.Flow);

            e.AmplitudeData.attackTime       = RandomMulti(.005f, .02f, 3);
            e.AmplitudeData.attackAmplitude  = 1.0f;
            e.AmplitudeData.decayTime        = .0f;
            e.AmplitudeData.sustainAmplitude = 1.0f;
            e.AmplitudeData.sustainTime      = RandomMulti(.0f, .1f, 3);
            e.AmplitudeData.releaseTime      = RandomMulti(.05f, .15f, 3);

            e.FrequencyData.range     = new Range(20.0f, 5000.0f);
            e.FrequencyData.frequency = Random.Range(20.0f, 1000.0f);

            if (RandomChance(.0f))
            {
                e.FrequencyData.delta      = RandomMulti(0.0f, 50.0f, 10);
                e.FrequencyData.deltaAccel = Random.Range(-5.0f, 5.0f);

                e.FrequencyData.curveType = GetRandomCurve(FrequencyData.CurveType.Square, FrequencyData.CurveType.Hook);
            }
            else
            {
                FrequencyJump[] jumps = new FrequencyJump[1];
                for (int iii = 0; iii < jumps.Length; iii++)
                {
                    jumps[iii]            = new FrequencyJump();
                    jumps[iii].repeatTime = RandomMulti(.01f, .1f, iii + 1);
                    jumps[iii].value      = RandomMulti(1.0f, 50.0f, 2);
                }
                e.FrequencyData.jumps = jumps;

                e.FrequencyData.curveType = GetRandomCurve(FrequencyData.CurveType.Slope, FrequencyData.CurveType.Square, FrequencyData.CurveType.Square, FrequencyData.CurveType.Hook);
            }

            if (RandomChance(.25f))
            {
                e.echoTime  = Random.Range(e.Duration * .05f, e.Duration);
                e.echoValue = RandomMulti(.1f, .2f, 3);
            }

            if (RandomChance(.7f))
            {
                e.highPass = (int)(e.FrequencyData.frequency * Random.Range(.5f, 1.5f));
            }

            Round(e, 2);

            return(e);
        }
 public void Copy(FrequencyData other)
 {
     range      = new Range(other.range.min, other.range.max);
     frequency  = other.frequency;
     delta      = other.delta;
     deltaAccel = other.deltaAccel;
     jumps      = new FrequencyJump[other.jumps.Length];
     for (int iii = 0; iii < jumps.Length; iii++)
     {
         jumps[iii] = new FrequencyJump(other.jumps[iii]);
     }
     curveType = other.curveType;
 }
Beispiel #5
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--;
        }
        /// <summary>Creates and returns an Animation Curve that represents the frequency over time</summary>
        /// <param name="duration">How long, in seconds, the frequency curve must be.</param>
        public AnimationCurve GetCurve(float duration)
        {
            List <Keyframe> keys = new List <Keyframe>();

            float timeStep = .1f * duration;

            float time    = .0f;
            float curFreq = .0f;

            keys.Add(new Keyframe(.0f, frequency));
            keys.Add(new Keyframe(duration, frequency));

            if (jumps != null && jumps.Length > 0)
            {
                for (int iii = 0; iii < jumps.Length; iii++)
                {
                    FrequencyJump jump = jumps[iii];
                    if (jump.repeatTime <= .0f || Mathf.Abs(jump.value) <= .0f)
                    {
                        continue;
                    }

                    int index = 0;

                    const float match   = .0005f;
                    int         repeats = jump.repeats;
                    float       value   = .0f;
                    if (repeats < 0)
                    {
                        repeats = Mathf.CeilToInt((duration - jump.start) / jump.repeatTime);
                    }
                    for (int rrr = 1; rrr < repeats + 1; rrr++)
                    {
                        time  = rrr * jump.repeatTime + jump.start;
                        value = rrr * jump.value;

                        while (index < keys.Count && keys[index].time < (time - match * .5f))
                        {
                            Keyframe k = new Keyframe(keys[index].time, (rrr - 1) * jump.value + keys[index].value);
                            keys[index] = k;
                            index++;
                        }

                        if (index >= keys.Count)
                        {
                            break;
                        }

                        if (Math.Approximately(keys[index].time, time, match))
                        {
                            Keyframe k = new Keyframe(time, value + keys[index].value);
                            keys[index] = k;
                        }
                        else
                        {
                            Keyframe k = new Keyframe(time, value + keys[index].value);
                            keys.Insert(index, k);
                        }
                        index++;
                    }
                    for (int jjj = index; jjj < keys.Count; jjj++)
                    {
                        Keyframe k = new Keyframe(keys[jjj].time, value + keys[jjj].value);
                        keys[jjj] = k;
                    }
                }
            }

            if (deltaAccel != .0f)
            {
                time = .0f;
                for (int iii = 0; iii < keys.Count; iii++)
                {
                    if (keys[iii].time - time > timeStep)
                    {
                        time     = time + timeStep;
                        curFreq  = .5f * deltaAccel * (time * time);
                        curFreq += delta * time;
                        Keyframe k = new Keyframe(time, keys[iii].value + curFreq);
                        keys.Insert(iii, k);
                    }
                    else
                    {
                        time      = keys[iii].time;
                        curFreq   = .5f * deltaAccel * (time * time);
                        curFreq  += delta * time;
                        keys[iii] = new Keyframe(keys[iii].time, keys[iii].value + curFreq);
                    }
                }
            }
            else if (delta != .0f)
            {
                for (int iii = 0; iii < keys.Count; iii++)
                {
                    keys[iii] = new Keyframe(keys[iii].time, keys[iii].value + delta * keys[iii].time);
                }

                float diff = .0f;
                if (delta > 0)
                {
                    diff = range.max - frequency;
                }
                else
                {
                    diff = range.min - frequency;
                }
                float t = Mathf.Sqrt((diff * 2) / delta);

                if (t < duration && t > .0f)
                {
                    for (int iii = 0; iii < keys.Count; iii++)
                    {
                        if (t < keys[iii].time)
                        {
                            keys.Insert(iii, new Keyframe(t, (delta > 0) ? range.max : range.min));
                            break;
                        }
                    }
                }
            }

            for (int iii = 0; iii < keys.Count; iii++)
            {
                Keyframe k = new Keyframe(keys[iii].time, range.Clamp(keys[iii].value));

                if (curveType == CurveType.Linear)
                {
                    if (iii > 0)
                    {
                        k.inTangent = CalcTangent(new Vector2(keys[iii - 1].time, keys[iii - 1].value), new Vector2(k.time, k.value));
                    }
                    if (iii < keys.Count - 1)
                    {
                        k.outTangent = CalcTangent(new Vector2(k.time, k.value), new Vector2(keys[iii + 1].time, range.Clamp(keys[iii + 1].value)));
                    }
                }
                else if (curveType == CurveType.Square)
                {
                    k.inTangent = k.outTangent = float.PositiveInfinity;
                }
                else if (curveType == CurveType.Hook)
                {
                    if (iii > 0)
                    {
                        k.inTangent = -CalcTangent(new Vector2(keys[iii - 1].time, keys[iii - 1].value), new Vector2(k.time, k.value));
                    }
                    if (iii < keys.Count - 1)
                    {
                        k.outTangent = -CalcTangent(new Vector2(k.time, k.value), new Vector2(keys[iii + 1].time, keys[iii + 1].value));
                    }
                }

                keys[iii] = k;
            }
            AnimationCurve ac = new AnimationCurve(keys.ToArray());

            if (curveType == CurveType.Smooth)
            {
                for (int iii = 0; iii < ac.keys.Length; iii++)
                {
                    ac.SmoothTangents(iii, 0);
                }
            }

            return(ac);
        }