Question How can I apply the same randomness from FloatParamRandomizer to multiple receivers simultaneously?

Azpectrum

New member
Messages
3
Reactions
1
Points
3
Hello everyone, I'm going to try to explain my problem better!

I am currently using the FloatParamRandomizer plugin, and I would like to replicate the generated float value for multiple items simultaneously. For example:

I have a plugin called FloatParamRandomizer that is changing the float parameters of Plugin>TimeLine>Global Speed. Now, I want to use this same plugin to also change the float value of Geometry>Smile. Additionally, I want to use it to modify Plugin>DecalMaker>X.Trans displacement.

Essentially, I want to have just one generator that can change these three parameters simultaneously. I want all three parameters to respect the same float range and randomness provided by this generator.


As far as I know, there are three random generators available:
  1. MeshedVR: This generator doesn't meet my requirements.
  2. Everlaster: This generator is quite good, but it only changes one parameter at a time, which doesn't suit my needs.
  3. MultiFloatParamRandomizer: While this generator can change multiple receivers, it lacks the search functionality of the Everlaster plugin. Additionally, it sets individual generators for each item, which also doesn't suit my requirements.
So, none of the existing generators fully meet my needs.


How can I solve this problem?

Thank you in advance!
 
Have you tried having FloatRandomizer drive the value of a VariableTrigger atom (VaM build-in) or a ValueRelay (from LogicBricks)? You can use those to drive any number of other values. Only limitation is that the input value for both is 0...1, but you can remap that to any range on the output side.
 
Upvote 0
I think you can also do it with VUML and ActionGrouper
FloatRandomizer will change float from VUML, and ActionGrouper will use that float :unsure:
 
Upvote 0
FloatParamEchoRandomizer.cs :
C#:
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using SimpleJSON;

namespace SPQR {

    // This class will produce a random number that can be used to set any float param available in all atoms
    // includes random generation period, smoothing, and range selection options
    public class FloatParamEchoRandomizer : MVRScript {

        float receivedVal = 0f;
        JSONStorableBool isEcho;
        protected void SyncAtomChocies() {
            List<string> atomChoices = new List<string>();
            atomChoices.Add("None");
            foreach (string atomUID in SuperController.singleton.GetAtomUIDs()) {
                atomChoices.Add(atomUID);
            }
            atomJSON.choices = atomChoices;
        }

        // receiver Atom
        protected Atom receivingAtom;
        protected void SyncAtom(string atomUID) {
            List<string> receiverChoices = new List<string>();
            receiverChoices.Add("None");
            if (atomUID != null) {
                receivingAtom = SuperController.singleton.GetAtomByUid(atomUID);
                if (receivingAtom != null) {
                    foreach (string receiverChoice in receivingAtom.GetStorableIDs()) {
                        receiverChoices.Add(receiverChoice);
                        //SuperController.LogMessage("Found receiver " + receiverChoice);
                    }
                }
            } else {
                receivingAtom = null;
            }
            receiverJSON.choices = receiverChoices;
            receiverJSON.val = "None";
        }
        protected JSONStorableStringChooser atomJSON;

        protected string _missingReceiverStoreId = "";
        protected void CheckMissingReceiver() {
            if (_missingReceiverStoreId != "" && receivingAtom != null) {
                JSONStorable missingReceiver = receivingAtom.GetStorableByID(_missingReceiverStoreId);
                if (missingReceiver != null) {
                    //Debug.Log("Found late-loading receiver " + _missingReceiverStoreId);
                    string saveTargetName = _receiverTargetName;
                    SyncReceiver(_missingReceiverStoreId);
                    _missingReceiverStoreId = "";
                    insideRestore = true;
                    receiverTargetJSON.val = saveTargetName;
                    insideRestore = false;
                }
            }
        }

        // receiver JSONStorable
        protected JSONStorable receiver;
        protected void SyncReceiver(string receiverID) {
            List<string> receiverTargetChoices = new List<string>();
            receiverTargetChoices.Add("None");
            if (receivingAtom != null && receiverID != null) {
                receiver = receivingAtom.GetStorableByID(receiverID);
                if (receiver != null) {
                    foreach (string floatParam in receiver.GetFloatParamNames()) {
                        receiverTargetChoices.Add(floatParam);
                    }
                } else if (receiverID != "None") {
                    // some storables can be late loaded, like skin, clothing, hair, etc so must keep track of missing receiver
                    //Debug.Log("Missing receiver " + receiverID);
                    _missingReceiverStoreId = receiverID;
                }
            } else {
                receiver = null;
            }
            receiverTargetJSON.choices = receiverTargetChoices;
            receiverTargetJSON.val = "None";
        }
        protected JSONStorableStringChooser receiverJSON;

        // receiver target parameter
        protected string _receiverTargetName;
        protected JSONStorableFloat receiverTarget;
        protected void SyncReceiverTarget(string receiverTargetName) {
            _receiverTargetName = receiverTargetName;
            receiverTarget = null;
            if (receiver != null && receiverTargetName != null) {
                receiverTarget = receiver.GetFloatJSONParam(receiverTargetName);
                if (receiverTarget != null) {
                    lowerValueJSON.min = receiverTarget.min;
                    lowerValueJSON.max = receiverTarget.max;
                    upperValueJSON.min = receiverTarget.min;
                    upperValueJSON.max = receiverTarget.max;
                    currentValueJSON.min = receiverTarget.min;
                    currentValueJSON.max = receiverTarget.max;
                    targetValueJSON.min = receiverTarget.min;
                    targetValueJSON.max = receiverTarget.max;
                    if (!insideRestore) {
                        // only sync up val if not in restore
                        lowerValueJSON.val = receiverTarget.val;
                        upperValueJSON.val = receiverTarget.val;
                        currentValueJSON.val = receiverTarget.val;
                        targetValueJSON.val = receiverTarget.val;
                    }
                }
            }
        }
        protected JSONStorableStringChooser receiverTargetJSON;

        protected JSONStorableFloat periodJSON;
        protected JSONStorableFloat quicknessJSON;
        protected JSONStorableFloat lowerValueJSON;
        protected JSONStorableFloat upperValueJSON;
        protected JSONStorableFloat targetValueJSON;
        protected JSONStorableFloat currentValueJSON;

        public override void Init() {
            try {

                // JSONStorableToggle
                isEcho = new JSONStorableBool("Is Echo", false);
                CreateToggle(isEcho, false);
                RegisterBool(isEcho);

                // make atom selector
                atomJSON = new JSONStorableStringChooser("atom", SuperController.singleton.GetAtomUIDs(), null, "Atom", SyncAtom);
                atomJSON.representsAtomUid = true;
                RegisterStringChooser(atomJSON);
                SyncAtomChocies();
                UIDynamicPopup dp = CreateFilterablePopup(atomJSON);
                dp.popupPanelHeight = 1100f;
                // want to always resync the atom choices on opening popup since atoms can be added/removed
                dp.popup.onOpenPopupHandlers += SyncAtomChocies;

                // make receiver selector
                receiverJSON = new JSONStorableStringChooser("receiver", null, null, "Receiver", SyncReceiver);
                RegisterStringChooser(receiverJSON);
                dp = CreateFilterablePopup(receiverJSON);
                dp.popupPanelHeight = 960f;

                // make receiver target selector
                receiverTargetJSON = new JSONStorableStringChooser("receiverTarget", null, null, "Target", SyncReceiverTarget);
                RegisterStringChooser(receiverTargetJSON);
                dp = CreateFilterablePopup(receiverTargetJSON);
                dp.popupPanelHeight = 820f;

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

                // create random value generation period
                periodJSON = new JSONStorableFloat("period", 0.5f, 0f, 10f, false);
                RegisterFloat(periodJSON);
                CreateSlider(periodJSON, true);

                // quickness (smoothness)
                quicknessJSON = new JSONStorableFloat("quickness", 10f, 0f, 100f, true);
                RegisterFloat(quicknessJSON);
                CreateSlider(quicknessJSON, true);

                // lower val
                lowerValueJSON = new JSONStorableFloat("lowerValue", 0f, 0f, 1f, false);
                RegisterFloat(lowerValueJSON);
                CreateSlider(lowerValueJSON, true);

                // upper val
                upperValueJSON = new JSONStorableFloat("upperValue", 0f, 0f, 1f, false);
                RegisterFloat(upperValueJSON);
                CreateSlider(upperValueJSON, true);

                // target val
                targetValueJSON = new JSONStorableFloat("targetValue", 0f, 0f, 1f, false, false);
                // don't register - this is for viewing only and is generated
                UIDynamicSlider ds = CreateSlider(targetValueJSON, true);
                ds.defaultButtonEnabled = false;
                ds.quickButtonsEnabled = false;

                // current val
                currentValueJSON = new JSONStorableFloat("currentValue", 0f, 0f, 1f, false, false);
                // don't register - this is for viewing only and is generated
                ds = CreateSlider(currentValueJSON, true);
                ds.defaultButtonEnabled = false;
                ds.quickButtonsEnabled = false;

            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }

        protected float timer = 0f;

        protected void Update() {
            try {
                timer -= Time.deltaTime;
                if (timer < 0.0f) {
                    // reset timer and set a new random target value
                    timer = periodJSON.val;
                    targetValueJSON.val = UnityEngine.Random.Range(lowerValueJSON.val, upperValueJSON.val);
                }
                if (isEcho.val)
                {
                    targetValueJSON.val = receivedVal;
                    currentValueJSON.val = receivedVal;
                } else {
                    currentValueJSON.val =  Mathf.Lerp(currentValueJSON.val, targetValueJSON.val, Time.deltaTime * quicknessJSON.val);
                    containingAtom.gameObject.BroadcastMessage("FloatParamSingleton", currentValueJSON.val);
                }
                // check for receivers that might have been missing on load due to asynchronous load of some assets like skin, clothing, hair
                
                CheckMissingReceiver();
                if (receiverTarget != null) {
                    receiverTarget.val = currentValueJSON.val;
                }
            }
            catch (Exception e) {
                SuperController.LogError("Exception caught: " + e);
            }
        }

        public void FloatParamSingleton(float val)
        {
            if (!isEcho.val) return;
            receivedVal = val;
        }

    }
}

You can use this modified version to echo the random value to different instances of the plugin.
atom > plugin 1 > is echo: off > works as the normal script
atom > plugin 2 > is echo: on > gets the random value from plugin 1
atom > plugin 3 > is echo: on > gets the random value from plugin 1
 
Upvote 0
Back
Top Bottom