Example #1
0
        public override void RestoreFromJSON(JSONClass jc, bool restorePhysical = true, bool restoreAppearance = true, JSONArray presetAtoms = null, bool setMissingToDefault = true)
        {
            base.RestoreFromJSON(jc, restorePhysical, restoreAppearance, presetAtoms, setMissingToDefault);

            _curve1JSON.RestoreFromJSON(jc, restorePhysical, restoreAppearance, setMissingToDefault);
            _curveEditor.UpdateCurve(_curve1JSON);
        }
        protected void CurveXAxisChooserCallback(string val)
        {
            _timeGroup.SetVisible(false);

            if (val == null)
            {
                return;
            }

            if (val == "Time")
            {
                _timeGroup.SetVisible(true);
                TimeSpanSlider.valNoCallback     = 1;
                TimeScrubberSlider.valNoCallback = 0;
                _editor.SetDrawScale(_storable, new Vector2(TimeSpanSlider.val, 1), _offset, true);
            }
            else
            {
                _editor.SetDrawScale(_storable, Vector2.one, _offset, true);
            }

            _storable.SetValToDefault();
            _editor.UpdateCurve(_storable);
        }
Example #3
0
        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);
            };
        }
Example #4
0
        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);
            };
        }