Skip to content

Clamped Variables

Daniel Everland edited this page Nov 8, 2018 · 3 revisions

Introduction

Clamped Variables were created for two very simple reasons. We very often would like certain values to stay within a specific interval, and the point of ScriptableObject-Architecture being that we want to avoid constrictions of codebases. Let's imagine having a PlayerHealth variable without the Clamped Variable feature

We obviously don't want the PlayerHealth to exceed the maximum allowed health, nor do we want it to dip below 0. We would have to ensure that every single piece of code that references this variable ensured to clamp it properly, or force them to assign it through a static function that did it for them. That's not very Unity-like. So instead I decided to make a variable that does this dynamically. Code that references such an object doesn't need to know which values to clamp it to, it can simply assign whatever value it pleases without worry.

Script Reference

Clamped Variables inherit IClampedVariable<TType, TVariable, TReference> which contains the following members

TType ClampValue(TType value);
TReference MinValue { get; }
TReference MaxValue { get; }
Clone this wiki locally