public override void Init() { try { ui = new UI(this, 0.001f); ui.canvas.transform.SetParent(containingAtom.mainController.transform, false); ui.canvas.transform.localPosition = new Vector3(0, -0.15f, 0); thrustValue = new JSONStorableFloat("thrust", 0, 0, SLIDER_MAX, true, true); RegisterFloat(thrustValue); UIDynamicSlider thrustSlider = ui.CreateSlider("Thrust Control", 300, 120); thrustSlider.valueFormat = "n0"; thrustValue.slider = thrustSlider.slider; thrustSlider.slider.onValueChanged.AddListener((float value) => { if (ap != null) { float speed = Remap(thrustValue.val, 0, SLIDER_MAX, 0, maxSpeed.val); ap.SetFloatParamValue("speed", speed); } }); apName = new JSONStorableString("apName", ""); RegisterString(apName); CreateButton("Select Animation Pattern").button.onClick.AddListener(() => { SuperController.singleton.SelectModeAtom((atom) => { if (atom.GetStorableByID("AnimationPattern") == null) { SuperController.LogError("You must select an animation pattern."); return; } apName.SetVal(atom.name); ap = atom.GetStorableByID("AnimationPattern") as AnimationPattern; }); }); maxSpeed = new JSONStorableFloat("maxSpeed", 4, 0, 10, false, true); RegisterFloat(maxSpeed); CreateSlider(maxSpeed, true); } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } }
public void OnSimulatorUpdate(float prevPos, float newPos, float deltaTime) { if (_targetAnimationPattern == null) { if (!string.IsNullOrEmpty(_targetAnimationAtomChooser.val)) { _targetAnimationAtomChooser.SetVal(""); } return; } if (_pluginFreeController.selected && SuperController.singleton.editModeToggle.isOn) { _lineDrawer0.SetLinePoints(_pluginFreeController.transform.position, _animationAtomController.transform.position); _lineDrawer0.Draw(); } var currentTime = _targetAnimationPattern.GetFloatJSONParam("currentTime"); float totalTime = _targetAnimationPattern.GetTotalTime(); float normOldTime = currentTime.val / totalTime; float normalizedLaunchPos = Mathf.InverseLerp(_minPosition.val, _maxPosition.val, newPos); float newTime; if (_moveUpwards) { newTime = Mathf.Lerp(0.0f, totalTime * 0.5f, normalizedLaunchPos); } else { newTime = Mathf.Lerp(totalTime, totalTime * 0.5f, normalizedLaunchPos); } newTime = (newTime + (totalTime * _animationOffset.val)) % totalTime; float normNewTime = newTime / totalTime; if (Mathf.Abs(normNewTime - normOldTime) > 0.05f) { currentTime.SetVal(newTime); } _targetAnimationPattern.SetFloatParamValue("speed", totalTime / (_dirChangeDuration * 2.0f)); }