Runtime Variables are Serializable Classes that provide some kind of value. Many of them have an Update method, updating the value to behave in an unique way. You can add these variables as members to your behaviours, and call their updates in your behaviour update.
Some provide a speed value, or a value which on its update moves smoothly to a target value, or a timer which counts down, or a Sin(x) wave. By using them, you don't have to program their functionality time and time again for all your behaviours.
Most settings of Runtime Variables are Referenceable Variables, allowing you to reference assets for default speed or randomization values.
When a Runtime Variable has an update method, you can optionally pass a deltaTime value to determine what timescale to use and influence how fast it plays out. Consider what type of deltaTime is most appropiate to the situation. Here are some suggestions:
In the behaviour's Update method, leave it empty, or pass Time.deltaTime.
In the behaviour's FixedUpdate method, pass Time.fixedDeltaTime.
If running in the Update method, but for user interface elements, use DuskUtility.interfaceDeltaTime.
You can multiply the passed deltaTime value with a speed multiplier to have additional control over how fast the Runtime Variable runs.
Float value with an Update method, which moves its value over time to a target value. The value accelerates and is affected by drag towards the target, resulting in a very smooth and natural value increase that can overshoot the target and bounce back.
Available settings:
Acceleration. How fast it speeds up towards the target.
Drag. Slows down the speed the faster the speed currently is.
LinearDrag. Slows down the speed by a constant amount.
LinearSpeed. Moves the value by a constant amount.
MinimumLimit. Optional value. If set, value can't pass below it.
MaximumLimit. Optional value. If set, value can't pass above it.
The AcceleratedValue is useful for example for making objects 'grow' from 0 to full size over time, with a 'pop-in' effect. It could also be used to make objects slide in from off-screen, overshooting the target a little bit.
Float value with an Update method. It contains a LerpMoveValue as speed, with which it updates its value to match a target value over time.
Basically the same use as an AcceleratedValue, but without overshoot.
Same functionality as SmoothValue, but smoothly moves a Vector2, Vector3 or Quaternion respectively.
Extension of SmoothValue. The target value cannot be directly set. Instead, the target value changes to a random new target at random intervals.
Useful for certain visual effects, such as a flickering fire, or the intensity of wind effects, that morph randomly over time.
These two variables expose a minimum and maximum value within the Inspector GUI. When getting the value from them, it returns a random value between the min and max values. It's possible to get the lastValue instead of having it generate a new value at every call.
The LerpMoveValue differs somewhat from most Runtime Values. It does not contain a resulting value. Instead, you can use the LerpMoveValue.Move method to move floats, Vectors or Quaternions smoothly from one value to another. It uses Time.deltaTime by default, but you can pass other deltaTimes as parameter if needed.
It acts a lot like the MoveTowards method, but adds a more smooth motion to it. For example:
transform.position = moveSpeed.Move(transform.position, targetPos);The SinusValue contains a sinus wave. It has a frequency and strength value, which are SmoothValues that can adjust over time as well.
A variety of visual wobbles can be achieved with SinusValue. If the strength target is set to 0, and clicking on the object sets the strength's active value to 0.2, the object will wobble violently before reducing the wobble's intensity back to nothing.
For example, you can apply the SinusValue resulting value to the scale of an object:
transform.localScale = Vector3.one * (1 + sizeWobble.value);The TimerValue is simply a timer. You can start it with for example:
abilityCooldown.Run(RechargeAbility);The time used for the timer can be set in the Inspector. Optionally, if the timer is hidden in Inspector and constructed on awake, you should set the time by code:
abilityCooldown.Run(time, RechargeAbility);Whatever method is passed as callback will be triggered when the timer completes. Don't forget to call the update in your own update. Or don't, if you want to pause the timer.
abilityCooldown.Update();There are more features, summarized here:
abilityCooldown.Stop(); // Stops the timer, does not trigger callback.float p = abilityCooldown.percent; // Gets timer range (0 - 1)if (abilityCooldown.isRunning) // Whether the timer is runningA MonoBehaviour which references an IntVariable ScriptableObject, using it as the index pointer for a list of positions. It then moves itself to the target position.
Useful for certain UI or background elements that have multiple positions, scales or rotations to be at, depending on what UI screen is currently active.
To use it, attach the behaviour to the element you need to move. Then assign a IntVariable named something similar to 'UI-Element-Index'. Then all you have to do is change the IntVariable to move the behaviour.
A Mode setter is a behaviour that sets a target IntVariable to a predetermined value when the behaviour is enabled. This works well with the ModeRelocator.
Attach the ModeSetter to any screen, causing it to enable when the screen is opened. When that happens, it updates the IntVariable, which in turn updates the ModeRelocator.