Ejemplo n.º 1
0
        protected IEnumerator Update_Routine()
        {
            while (true)
            {
                float waitTime = _updateRate.val / 1000;
                if (waitTime > 0.0f)
                {
                    yield return(new WaitForSecondsRealtime(waitTime));
                }
                else
                {
                    yield return(new WaitForFixedUpdate());

                    waitTime = Time.fixedUnscaledDeltaTime;
                }

                try
                {
                    foreach (var randomizer in _randomizerEnabledList)
                    {
                        randomizer.Update(waitTime);
                    }

                    if (null != _displayRandomizer._syncTarget && _displayPopup.isActiveAndEnabled)
                    {
                        ParamRandomizer.CopyValues(_displayRandomizer, _displayRandomizer._syncTarget);
                    }
                }
                catch (Exception e)
                {
                    SuperController.LogError(e.ToString());
                }
            }
        }
Ejemplo n.º 2
0
 public void SyncWith(ParamRandomizer aRandomizer)
 {
     _syncTarget           = aRandomizer;
     this._disableHandlers = true;
     CopyValues(this, _syncTarget);
     this._disableHandlers = false;
 }
Ejemplo n.º 3
0
        void DeregisterRandomizer(ParamRandomizer aRandomizer)
        {
            var floatList = aRandomizer.GetStorableFloats();

            foreach (var storable in floatList)
            {
                DeregisterFloat(storable);
            }

            var boolList = aRandomizer.GetStorableBools();

            foreach (var storable in boolList)
            {
                DeregisterBool(storable);
            }
        }
        public static void CopyValues(ParamRandomizer aDst, ParamRandomizer aSrc)
        {
            bool prevDisable = aDst._disableHandlers;

            aDst._disableHandlers = true;

            aDst._enabled.val = aSrc._enabled.val;
            CopyStorableFloat(aDst._period, aSrc._period, aDst._disableHandlers);
            CopyStorableFloat(aDst._periodRandomMin, aSrc._periodRandomMin, aDst._disableHandlers);
            CopyStorableFloat(aDst._periodRandomMax, aSrc._periodRandomMax, aDst._disableHandlers);
            CopyStorableFloat(aDst._percentage, aSrc._percentage, aDst._disableHandlers);
            CopyStorableFloat(aDst._quickness, aSrc._quickness, aDst._disableHandlers);
            CopyStorableFloat(aDst._minVal, aSrc._minVal, aDst._disableHandlers);
            CopyStorableFloat(aDst._maxVal, aSrc._maxVal, aDst._disableHandlers);
            CopyStorableFloat(aDst._curVal, aSrc._curVal, aDst._disableHandlers);
            CopyStorableFloat(aDst._targetVal, aSrc._targetVal, aDst._disableHandlers);

            aDst._disableHandlers = prevDisable;
        }
Ejemplo n.º 5
0
        // receiver JSONStorable
        protected void SyncReceiver(string receiverID)
        {
            List <string> targetChoices = new List <string>();

            foreach (ParamRandomizer randomizer in _randomizerList)
            {
                DeregisterRandomizer(randomizer);
            }

            Dictionary <string, ParamRandomizer> oldDict = null;

            // If this is just refreshing the list we need to save existing randomizers
            string defaultTarget;

            if (_skipUpdateVal)
            {
                oldDict         = _randomizerDict;
                _randomizerDict = new Dictionary <string, ParamRandomizer>();
                defaultTarget   = _targetJson.val;
            }
            else
            {
                // Otherwise if the receiver changed then clear the enabled list
                _randomizerEnabledList.Clear();
            }
            _randomizerDict.Clear();
            _randomizerList.Clear();

            if (_atom != null && receiverID != null)
            {
                if (!_skipUpdateVal)
                {
                    _receiver = _atom.GetStorableByID(receiverID);
                }
                if (_receiver != null)
                {
                    foreach (string paramName in _receiver.GetFloatParamNames())
                    {
                        ParamRandomizer randomizer;
                        // Use the old randomizer if it exists, otherwise make a new one
                        if (!(oldDict != null && oldDict.TryGetValue(paramName, out randomizer)))
                        {
                            randomizer = new ParamRandomizer(paramName, _receiver.GetFloatJSONParam(paramName));
                        }
                        RegisterRandomizer(randomizer);
                        _randomizerList.Add(randomizer);
                        _randomizerDict[paramName] = randomizer;
                        targetChoices.Add(paramName);
                    }
                }
                else
                {
                    // some storables can be late loaded, like skin, clothing, hair, etc so must keep track of missing receiver
                    //SuperController.LogMessage("Missing receiver: " + receiverID);
                    SetWaitForMissingReceiver(receiverID);
                }
            }
            else
            {
                _receiver = null;
            }

            _targetJson.choices = targetChoices;
            if (!_skipUpdateVal || !targetChoices.Contains(_receiverJSON.val))
            {
                if (targetChoices.Count > 0)
                {
                    _targetJson.val = targetChoices[0];
                }
                // Clear the display
                ParamRandomizer.CopyValues(_displayRandomizer, new ParamRandomizer("display", null));
            }
            UpdateEnabledList();
        }
Ejemplo n.º 6
0
        public override void Init()
        {
            try
            {
                _lastBrowseDir = CreateDirectory(GetPluginPath() + @"fmpr_presets\");

                _displayRandomizer = new ParamRandomizer("display", null);
                _displayRandomizer.UpdateEnabledListEvnt += UpdateEnabledList;

                // make atom selector
                _atomJSON           = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom);
                _atomJSON.storeType = JSONStorableParam.StoreType.Physical;
                RegisterStringChooser(_atomJSON);
                SyncAtomChoices();
                _displayPopup = CreateScrollablePopup(_atomJSON);
                _displayPopup.popupPanelHeight = 1100f;
                // want to always resync the atom choices on opening popup since atoms can be added/removed
                _displayPopup.popup.onOpenPopupHandlers += SyncAtomChoices;
                _displayPopup.label = "Atom in Scene";

                // make receiver selector
                _receiverJSON           = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver);
                _receiverJSON.storeType = JSONStorableParam.StoreType.Physical;
                RegisterStringChooser(_receiverJSON);
                _displayPopup = CreateScrollablePopup(_receiverJSON);
                _displayPopup.popupPanelHeight = 960f;
                // want to always resync the receivers, since plugins can be added/removed
                _displayPopup.popup.onOpenPopupHandlers += SyncReceiverChoices;
                _displayPopup.label = "Receiver on Atom";

                // make receiver target selector
                _targetJson                    = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncTargets);
                _targetJson.storeType          = JSONStorableParam.StoreType.Physical;
                _displayPopup                  = CreateScrollablePopup(_targetJson);
                _displayPopup.popupPanelHeight = 820f;
                // want to always resync the targets, since morphs can be marked animatable
                _displayPopup.popup.onOpenPopupHandlers += SyncTargetChoices;
                _displayPopup.label = "Parameter on Receiver";

                // Add Load/Save buttons
                var btn = CreateButton("Load Preset");
                btn.button.onClick.AddListener(() =>
                {
                    SuperController.singleton.NormalizeMediaPath(_lastBrowseDir); // This sets the path iff it exists
                    SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, saveExt);
                });


                _addAnimatable = new JSONStorableBool("autoSetAnimatable", true);
                var toggle = CreateToggle(_addAnimatable);
                toggle.label       = "Auto-set 'animatable' on load";
                _setReceiverOnLoad = new JSONStorableBool("setReceiverOnLoad", true);
                toggle             = CreateToggle(_setReceiverOnLoad);
                toggle.label       = "Set 'receiver' on load";

                _setAtomOnLoad = new JSONStorableBool("setAtomOnLoad", false);

                btn = CreateButton("Save Preset");
                btn.button.onClick.AddListener(() =>
                {
                    SuperController.singleton.NormalizeMediaPath(_lastBrowseDir); // This sets the path iff it exists
                    SuperController.singleton.GetMediaPathDialog(HandleSavePreset, saveExt);

                    // Update the browser to be a Save browser
                    uFileBrowser.FileBrowser browser = SuperController.singleton.mediaFileBrowserUI;
                    browser.SetTextEntry(true);
                    browser.fileEntryField.text = String.Format("{0}.{1}", ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(), saveExt);
                    browser.ActivateFileNameField();
                });


                // set atom to current atom to initialize
                _atomJSON.val = containingAtom.uid;

                var spacer = CreateSpacer();
                spacer.height = 40;

                btn = CreateButton("Set Min to Current");
                btn.button.onClick.AddListener(() =>
                {
                    _displayRandomizer._minVal.val = _displayRandomizer._curVal.val;
                });

                btn = CreateButton("Set Max to Current");
                btn.button.onClick.AddListener(() =>
                {
                    _displayRandomizer._maxVal.val = _displayRandomizer._curVal.val;
                });

                spacer        = CreateSpacer();
                spacer.height = 40;

                var countLabel = CreateTextField(new JSONStorableString("", ""));
                JSONStorableFloat.SetFloatCallback callback = (float aVal) =>
                {
                    countLabel.text = pluginName + " " + pluginVersion + "\n"
                                      + "\n"
                                      + "Active randomizers: " + aVal.ToString()
                    ;
                    pluginLabelJSON.val = String.Format("{0}->{1}, {2} running [{3}]", _atom.name, _receiverJSON.val, _randomizerEnabledList.Count.ToString(), pluginVersion);
                };
                countLabel.height      = 10;
                _activeRandomizersJson = new JSONStorableFloat("activeRandomizers", -1.0f, callback, 0.0f, 0.0f, false, false);

                spacer        = CreateSpacer();
                spacer.height = 40;

                _updateRate = new JSONStorableFloat("update_rate_ms", 15.0f, 0.0f, 1000f, false);
                RegisterFloat(_updateRate);
                var slider = CreateSlider(_updateRate);
                slider.label = "Update Delay (ms)";
                toggle       = CreateToggle(_displayRandomizer._enabled);
                toggle.label = "Enable Randomizer";


                // Create per-randomizer sliders
                slider       = CreateSlider(_displayRandomizer._period, true);
                slider.label = "Period\nSec between updates";

                slider       = CreateSlider(_displayRandomizer._periodRandomMin, true);
                slider.label = "Period min val";

                slider       = CreateSlider(_displayRandomizer._periodRandomMax, true);
                slider.label = "Period max val";

                slider       = CreateSlider(_displayRandomizer._quickness, true);
                slider.label = "Quickness";

                slider       = CreateSlider(_displayRandomizer._minVal, true);
                slider.label = "Random range min val";

                slider       = CreateSlider(_displayRandomizer._maxVal, true);
                slider.label = "Random range max val";

                slider       = CreateSlider(_displayRandomizer._deltaMinPercent, true);
                slider.label = "Min target val change %";

                slider       = CreateSlider(_displayRandomizer._deltaMaxPercent, true);
                slider.label = "Max target val change %";

                slider       = CreateSlider(_displayRandomizer._curVal, true);
                slider.label = "Current value\nYou can slide manually";
                slider.defaultButtonEnabled = false;
                slider.quickButtonsEnabled  = false;

                slider       = CreateSlider(_displayRandomizer._targetVal, true);
                slider.label = "Target Value";
                slider.defaultButtonEnabled = false;
                slider.quickButtonsEnabled  = false;

                // Trigger setting labels
                _activeRandomizersJson.val = 0.0f;
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }
        public override void Init()
        {
            try
            {
                _origFileFormat = SuperController.singleton.fileBrowserUI.fileFormat;

                _displayRandomizer = new ParamRandomizer("display", null);
                _displayRandomizer.UpdateEnabledListEvnt += UpdateEnabledList;

                // make atom selector
                _atomJSON = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom);
                RegisterStringChooser(_atomJSON);
                SyncAtomChoices();
                _displayPopup = CreateScrollablePopup(_atomJSON);
                _displayPopup.popupPanelHeight = 1100f;
                // want to always resync the atom choices on opening popup since atoms can be added/removed
                _displayPopup.popup.onOpenPopupHandlers += SyncAtomChoices;
                _displayPopup.label = "Atom in Scene";

                // make receiver selector
                _receiverJSON = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver);
                RegisterStringChooser(_receiverJSON);
                _displayPopup = CreateScrollablePopup(_receiverJSON);
                _displayPopup.popupPanelHeight = 960f;
                // want to always resync the receivers, since plugins can be added/removed
                _displayPopup.popup.onOpenPopupHandlers += SyncReceiverChoices;
                _displayPopup.label = "Receiver on Atom";

                // make receiver target selector
                _targetJson   = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncTargets);
                _displayPopup = CreateScrollablePopup(_targetJson);
                _displayPopup.popupPanelHeight = 820f;
                // want to always resync the targets, since morphs can be marked animatable
                _displayPopup.popup.onOpenPopupHandlers += SyncTargetChoices;
                _displayPopup.label = "Parameter on Receiver";

                // Add Load/Save buttons
                var btn = CreateButton("Load Preset");
                btn.button.onClick.AddListener(() =>
                {
                    uFileBrowser.FileBrowser browser = SuperController.singleton.fileBrowserUI;

                    browser.defaultPath = _lastBrowseDir;
                    browser.SetTextEntry(false);
                    browser.fileFormat = saveExt;
                    browser.Show(HandleLoadPreset);
                });


                _addAnimatable = new JSONStorableBool("autoSetAnimatable", true);
                var toggle = CreateToggle(_addAnimatable);
                toggle.label  = "Auto-set 'animatable' on load";
                _loadReceiver = new JSONStorableBool("Set 'receiver' on load", true);
                CreateToggle(_loadReceiver);

                btn = CreateButton("Save Preset");
                btn.button.onClick.AddListener(() =>
                {
                    uFileBrowser.FileBrowser browser = SuperController.singleton.fileBrowserUI;

                    browser.defaultPath = _lastBrowseDir;
                    browser.SetTextEntry(true);
                    browser.fileFormat = saveExt;
                    browser.Show(HandleSavePreset);
                    browser.fileEntryField.text = String.Format("{0}.{1}", ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString(), saveExt);
                    browser.ActivateFileNameField();
                });


                // set atom to current atom to initialize
                _atomJSON.val = containingAtom.uid;

                if (String.IsNullOrEmpty(_lastBrowseDir))
                {
                    _lastBrowseDir = SuperController.singleton.mediaFileBrowserUI.defaultPath;
                }

                // Create per-randomizer sliders
                var spacer = CreateSpacer();
                spacer.height = 40;

                var slider = CreateSlider(_displayRandomizer._period, true);
                slider.label = "Period\nSec between updates";

                slider       = CreateSlider(_displayRandomizer._periodRandomMin, true);
                slider.label = "Period min val";

                slider       = CreateSlider(_displayRandomizer._periodRandomMax, true);
                slider.label = "Period max val";

                slider       = CreateSlider(_displayRandomizer._quickness, true);
                slider.label = "Quickness";

                slider       = CreateSlider(_displayRandomizer._minVal, true);
                slider.label = "Random range min val";

                slider       = CreateSlider(_displayRandomizer._maxVal, true);
                slider.label = "Random range max val";

                slider       = CreateSlider(_displayRandomizer._percentage, true);
                slider.label = "Max target val change %";

                slider       = CreateSlider(_displayRandomizer._targetVal, true);
                slider.label = "Target Value";
                slider.defaultButtonEnabled = false;
                slider.quickButtonsEnabled  = false;

                slider       = CreateSlider(_displayRandomizer._curVal, true);
                slider.label = "Current value\nYou can slide manually";
                slider.defaultButtonEnabled = false;
                slider.quickButtonsEnabled  = false;

                var countLabel = CreateTextField(new JSONStorableString("", ""));
                JSONStorableFloat.SetFloatCallback callback = (float aVal) =>
                {
                    countLabel.text = pluginName + " " + pluginVersion + "\n"
                                      + "\n"
                                      + "Active randomizers: " + aVal.ToString() + "\n"
                                      + "\n"
                                      + "Update delay of 0 updates every frame."
                    ;
                };
                _activeRandomizersJson     = new JSONStorableFloat("activeRandomizers", -1.0f, callback, 0.0f, 0.0f, false, false);
                _activeRandomizersJson.val = 0.0f;

                _updateRate = new JSONStorableFloat("update_rate_ms", 15.0f, 0.0f, 1000f, false);
                RegisterFloat(_updateRate);
                slider       = CreateSlider(_updateRate);
                slider.label = "Update Delay (ms)";

                spacer        = CreateSpacer();
                spacer.height = 120;
                toggle        = CreateToggle(_displayRandomizer._enabled);
                toggle.label  = "Enable Randomizer";
            }
            catch (Exception e)
            {
                SuperController.LogError("Exception caught: " + e);
            }
        }