public UICurveEditor CreateCurveEditor(float height, bool rightSide = false) { var container = CreateSpacer(height, rightSide); UICurveEditor curveEditor = null; var buttons = Enumerable.Range(0, 4) .Select(_ => UnityEngine.Object.Instantiate(UIManager.ConfigurableButtonPrefab)) .Select(t => t.GetComponent <UIDynamicButton>()) .ToList(); foreach (var b in buttons) { b.buttonText.fontSize = 18; b.buttonColor = Color.white; } buttons[0].label = "Mode"; buttons[1].label = "In Mode"; buttons[2].label = "Out Mode"; buttons[3].label = "Linear"; buttons[0].button.onClick.AddListener(() => curveEditor.ToggleHandleMode()); buttons[1].button.onClick.AddListener(() => curveEditor.ToggleInHandleMode()); buttons[2].button.onClick.AddListener(() => curveEditor.ToggleOutHandleMode()); buttons[3].button.onClick.AddListener(() => curveEditor.SetLinear()); curveEditor = new UICurveEditor(container, 510, height, buttons: buttons); curveEditor.settings.allowViewDragging = false; curveEditor.settings.allowViewScaling = false; curveEditor.settings.allowViewZooming = false; curveEditor.settings.showScrubbers = true; return(curveEditor); }
public void CreateUI() { pluginLabelJSON.val = PluginName; var container = CreateSpacer(); container.height = 300; var curveEditorButtons = Enumerable.Range(0, 4) .Select(_ => UnityEngine.Object.Instantiate(manager.configurableButtonPrefab)) .Select(t => t.GetComponent <UIDynamicButton>()) .ToList(); foreach (var b in curveEditorButtons) { b.buttonText.fontSize = 18; b.buttonColor = Color.white; } curveEditorButtons[0].label = "Mode"; curveEditorButtons[1].label = "In Mode"; curveEditorButtons[2].label = "Out Mode"; curveEditorButtons[3].label = "Linear"; curveEditorButtons[0].button.onClick.AddListener(() => _curveEditor.ToggleHandleMode()); curveEditorButtons[1].button.onClick.AddListener(() => _curveEditor.ToggleInHandleMode()); curveEditorButtons[2].button.onClick.AddListener(() => _curveEditor.ToggleOutHandleMode()); curveEditorButtons[3].button.onClick.AddListener(() => _curveEditor.SetLinear()); _curveEditor = new UICurveEditor(container, 520, container.height, buttons: curveEditorButtons); _curveEditor.AddCurve(_curve1JSON, UICurveLineColors.CreateFrom(new Color(0.388f, 0.698f, 0.890f))); _curveEditor.SetValueBounds(_curve1JSON, new Rect(0, 0, 2, 10), true, true); _curveEditor.AddCurve(_curve2JSON, UICurveLineColors.CreateFrom(new Color(0.890f, 0.388f, 0.398f))); _curveEditor.SetValueBounds(_curve2JSON, new Rect(0, 0, 2, 1), true, true); var resetButton = CreateButton("Reset"); var playButton = CreateButton("Play"); var stopButton = CreateButton("Stop"); var fitButton = CreateButton("Fit View"); resetButton.button.onClick.AddListener(() => { _curve1JSON.SetValToDefault(); _curveEditor.UpdateCurve(_curve1JSON); _curve2JSON.SetValToDefault(); _curveEditor.UpdateCurve(_curve2JSON); }); playButton.button.onClick.AddListener(() => { _animation.Play("CurveEditorDemo"); }); stopButton.button.onClick.AddListener(() => { _animation.Stop(); }); fitButton.button.onClick.AddListener(() => { _curveEditor.SetViewToFit(new Vector4(0.2f, 1, 0.2f, 1)); }); var readOnlyStorable = new JSONStorableBool("ReadOnly", false); var readOnlyToggle = CreateToggle(readOnlyStorable); readOnlyStorable.setCallbackFunction = v => _curveEditor.readOnly = v; var showScrubberStorable = new JSONStorableBool("Show Scrubbers", true); var showScrubberToggle = CreateToggle(showScrubberStorable); showScrubberStorable.setCallbackFunction = v => _curveEditor.showScrubbers = v; var scrubberSliderStorable = new JSONStorableFloat("Scrubber time", 0, 0, 2); var scrubberSlider = CreateSlider(scrubberSliderStorable); scrubberSliderStorable.setCallbackFunction = v => { var state = _animation["CurveEditorDemo"]; if (state != null) { state.time = v; } _curveEditor.SetScrubber(_curve1JSON, v); _curveEditor.SetScrubber(_curve2JSON, 2 - v); }; var normalizeScaleStorable = new JSONStorableBool("Normalize to view", false); var normalizeScaleToggle = CreateToggle(normalizeScaleStorable); var offsetScaleStorable = new JSONStorableBool("Offset to center", false); var offsetScaleToggle = CreateToggle(offsetScaleStorable); var timeScaleSliderStorable = new JSONStorableFloat("Time Scale", 1, 0.5f, 8); var valueScaleSliderStorable = new JSONStorableFloat("Value Scale", 1, 0.5f, 8); var timeScaleSlider = CreateSlider(timeScaleSliderStorable); timeScaleSliderStorable.setCallbackFunction = v => { _curveEditor.SetValueBounds(_curve1JSON, new Rect(0, 0, v, valueScaleSliderStorable.val), normalizeScaleStorable.val, offsetScaleStorable.val); _curveEditor.SetValueBounds(_curve2JSON, new Rect(0, 0, v, valueScaleSliderStorable.val), normalizeScaleStorable.val, offsetScaleStorable.val); }; var valueScaleSlider = CreateSlider(valueScaleSliderStorable); valueScaleSliderStorable.setCallbackFunction = v => { _curveEditor.SetValueBounds(_curve1JSON, new Rect(0, 0, timeScaleSliderStorable.val, v), normalizeScaleStorable.val, offsetScaleStorable.val); _curveEditor.SetValueBounds(_curve2JSON, new Rect(0, 0, timeScaleSliderStorable.val, v), normalizeScaleStorable.val, offsetScaleStorable.val); }; }
public void CreateUI() { pluginLabelJSON.val = PluginName; var container = CreateSpacer(); container.height = 300; var curveEditorButtons = Enumerable.Range(0, 4) .Select(_ => UnityEngine.Object.Instantiate(manager.configurableButtonPrefab)) .Select(t => t.GetComponent <UIDynamicButton>()) .ToList(); foreach (var b in curveEditorButtons) { b.buttonText.fontSize = 18; b.buttonColor = Color.white; } curveEditorButtons[0].label = "Mode"; curveEditorButtons[1].label = "In Mode"; curveEditorButtons[2].label = "Out Mode"; curveEditorButtons[3].label = "Linear"; curveEditorButtons[0].button.onClick.AddListener(() => _curveEditor.ToggleHandleMode()); curveEditorButtons[1].button.onClick.AddListener(() => _curveEditor.ToggleInHandleMode()); curveEditorButtons[2].button.onClick.AddListener(() => _curveEditor.ToggleOutHandleMode()); curveEditorButtons[3].button.onClick.AddListener(() => _curveEditor.SetLinear()); _curveEditor = new UICurveEditor(container, 520, container.height, buttons: curveEditorButtons); _curveEditor.AddCurve(_curveJSON, UICurveLineColors.CreateFrom(new Color(0.388f, 0.698f, 0.890f))); _curveEditor.AddCurve(_curve2JSON, UICurveLineColors.CreateFrom(new Color(0.890f, 0.388f, 0.398f))); var resetButton = CreateButton("Reset"); var playButton = CreateButton("Play"); var stopButton = CreateButton("Stop"); resetButton.button.onClick.AddListener(() => { _curveJSON.SetValToDefault(); _curveEditor.UpdateCurve(_curveJSON); }); playButton.button.onClick.AddListener(() => { _animation.Play("CurveEditorDemo"); }); stopButton.button.onClick.AddListener(() => { _animation.Stop(); }); var readOnlyStorable = new JSONStorableBool("ReadOnly", false); var readOnlyToggle = CreateToggle(readOnlyStorable); readOnlyStorable.setCallbackFunction = v => _curveEditor.readOnly = v; var showScrubberStorable = new JSONStorableBool("Show Scrubbers", true); var showScrubberToggle = CreateToggle(showScrubberStorable); showScrubberStorable.setCallbackFunction = v => _curveEditor.showScrubbers = v; var sliderStorable = new JSONStorableFloat("Scrubber time", 0, 0, 1); var slider = CreateSlider(sliderStorable); sliderStorable.setCallbackFunction = v => { _curveEditor.SetScrubber(_curveJSON, v); _curveEditor.SetScrubber(_curve2JSON, 1 - v); }; }