I want to have some helpfully-named variables show up in the Inspector (just measurable and recognition for now, but who knows what I might need later on). In this case, it's how many pixels you need to move your fingers on an iOS device for some stuff to happen, but my question is not specific to that; this example is just what I want to use to learn about good practice.
It seems to me that there ought to be a better way to write this code, but this is the first time I've ever even written an indexer, so I'm not all that knowledgeable about the possibilities. I thought maybe having SquareMagnitudes inherit from IEnumerable would be good (never used that as of yet), but I don't really know about that. I mean, I'd like the simplicity of foreach, but I'm modifying the values, so from what I know, that wouldn't be appropriate.
Basically, just school me on what you would do. If you're sure of it, you could even tell me that there's no better way than just doing...
tolerances.squareMagnitudes.measurable *= .25F;
tolerances.squareMagnitudes.recognition *= .25F;
// For the sake of learning, imagine several other quartering operations here.
...but I really hope not. Thanks!
[System.Serializable] public class Tolerances { // public only to get rid of annoying warnings
[System.Serializable] public class SquareMagnitudes { // Small movements are problematic.
public float measurable, recognition;
public float this [int index] {
get {return index > 0 ? recognition : measurable;}
set {
if (index > 0) recognition = value;
else measurable = value;
}
}
} [SerializeField] public SquareMagnitudes squareMagnitudes;
// Other important stuff not relevant to this question.
} [SerializeField] Tolerances tolerances;
void Awake () {
if ((int)iPhoneSettings.generation < 7) // 1/4 res devices.
for (int i = 0; i < 2; ++i) tolerances.squareMagnitudes _*= .25F;_
*}*
*```*