using System; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Threading.Tasks; // VaM throws an error when this is left included. Not needed? namespace NoButYeaNS { class NBYPluginTest01: MVRScript { protected JSONStorableFloat jsonFloat; protected UIDynamicButton myButton; protected Int16 counterValue; // store the value of our counter protected Boolean counterValueIsValid; // set to false upon making a change. So we can recoginse a change was made in Update() protected float sliderValue; // tracks the slider value (frame to frame) public override void Init() { pluginLabelJSON.val = "NoButYea Test 1.0"; // CreateSlider needs a JSONStorableFloat value so.. // Initialize storable values. jsonFloat = new JSONStorableFloat("jsonFloat", 0.0f, 0.0f, 1.0f); RegisterFloat(jsonFloat); // Registering the float is important -- if not they wont save CreateSlider(jsonFloat, true); // the second argument is for 'rightSide'. Supplying true will render the slider on the right-side // track the value of the slider so that... // we can track if a change was made since last frame. sliderValue = jsonFloat.val; // initialize to whatever the slider is now. // Initialize the counter (that the button will influence) counterValue = 0; counterValueIsValid = false; // Add a button and a click handler myButton = CreateButton("My Button", false); myButton.height = 100; myButton.button.onClick.AddListener(delegate () { // increase counter value counterValue++; counterValueIsValid = false; // so we can detect a change was made }); } // Runs once when plugin loads - after Init() protected void Start() { // show a message SuperController.LogMessage(pluginLabelJSON.val + " Loaded"); } // A Unity thing - runs every physics cycle public void FixedUpdate() { // put code here } // Unity thing - runs every rendered frame public void Update() { if(counterValueIsValid == false) // check if counter has changed since last frame { SuperController.LogMessage("counter change detected: " + counterValue); counterValueIsValid = true; // set to true to avoid log message every frame } if(jsonFloat.val != sliderValue) // check if slider was changed since last frame { sliderValue = jsonFloat.val; // update our tracking value SuperController.LogMessage("slider value change detected: " + sliderValue); } } } }