Hi basically I’m using [Flag] enum’s to determine the allowed options for some objects e.g what types of objects there allowed to target. I’m trying to expose these options to the user so they can decide how they want the object to function. since I want it to be possible to have multiple options on at a time the only obvious GUI option is GUI.Toggle
however to use them I’m having to use the following code that seam far to long winded as i have to convert the enum to an array of bools but I’m sure there’s an easier way but I cant seam to find it.
//enum setup
[Flags]
public enum MyEnum
{
Group1 = 1,
Group2 = 2, //etc
//get the current enum setup into the bools
for(int i = 0; i < 10; i++) //assuming 10 items in the enum
bools *= ((enumInstance & (MyEnum) Mathf.Pow(i,2)) == (MyEnum) Mathf.Pow(i,2));*
//user gui options and save any changes
bool changed = false;
for (int j = 0; j < 10; j++)
{
bool temp = bools*;*
bools[j] = GUI.Toggle (new Rect (220, (Screen.height - 190) + (15 * (j)), 100, 15), bools[j], ((TurretGroup)Mathf.Pow (2, j)).ToString ());
if(selectedgroup[j] != temp)
changed = true;
}
if(changed)
{
object.enumInstance = 0;
for(int k = 0; k < 10; k++)
if(bools[k])
object.enumInstance = object.enumInstance | (TurretGroup)Mathf.Pow (2, k);
}