public override bool Calculate() { float value = 0; float t = Time.time; amplitude = amplInputKnob.connected() ? amplInputKnob.GetValue <float>() : amplitude; period = periodInputKnob.connected() ? periodInputKnob.GetValue <float>() : period; phase = phaseInputKnob.connected() ? phaseInputKnob.GetValue <float>() : phase; offset = 0; if (paramStyle.SelectedOption() == "min max") { amplitude = (max - min) / 2; offset = min + amplitude; } var newParams = (period, amplitude, phase); var oldParams = (lastPeriod, lastAmplitude, lastPhase); if (newParams != oldParams) { if (period != lastPeriod) { phase = (t - period / lastPeriod * (t - lastPhase)) % period; } } value = signalGenerators[signalType.SelectedOption()](t, period, amplitude, phase, 0); outputKnob.SetValue(value + offset); lastPeriod = period; lastPhase = phase; lastAmplitude = amplitude; return(true); }
public override bool Calculate() { signalValue = inputSignalKnob.GetValue <float>(); switch (triggerMode.SelectedOption()) { case "leadingEdge": output = (signalValue > threshold) && !wasOverThreshold; break; case "trailingEdge": output = (signalValue < threshold) && wasOverThreshold; break; case "high": output = signalValue > threshold; break; case "low": output = signalValue < threshold; break; default: output = false; break; } wasOverThreshold = signalValue > threshold; outputEventKnob.SetValue(output); return(true); }
public override void NodeGUI() { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); RadioButtonsVertical(signalType); GUILayout.BeginVertical(); GUILayout.Label("Param config:"); RadioButtons(paramStyle); outputKnob.DisplayLayout(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (paramStyle.SelectedOption() == "amplitude") { amplInputKnob.DisplayLayout(); if (!amplInputKnob.connected()) { amplitude = RTEditorGUI.FloatField(amplitude); } } else if (paramStyle.SelectedOption() == "min max") { min = RTEditorGUI.FloatField("Min", min); max = RTEditorGUI.FloatField("Max", max); } FloatKnobOrSlider(ref period, 0.01f, 50, periodInputKnob); FloatKnobOrSlider(ref phase, -period, period, phaseInputKnob); GUILayout.Space(4); GUILayout.EndVertical(); if (GUI.changed) { NodeEditor.curNodeCanvas.OnNodeChange(this); } }