I’m trying to setup an EditorWindow script that can create separate builds. So far everything is going well and works. The only issue I seem to be having is setting up a BuildOptions mask in the editor.
I want to have code that does something like this:
Thus, I was wondering how would we setup a BuildOptions mask that correctly uses the values picked in the mask. Currently, the code I posted does not work.
EDIT: Dmitriy Yukhanov found a bug with Unity’s BuildOptions, so to correctly implement the mask the way it is suppose to be please see his comment here.
Well, EnumMaskField doesn’t quite do what you would expect. What it does is this:
string[] flagNames = (
from x in Enum.GetNames(enumValue.GetType())
select ObjectNames.NicifyVariableName(x)).ToArray<string>();
int value = MaskFieldGUI.DoMaskField(position2, controlID, Convert.ToInt32(enumValue), flagNames, style);
return EditorGUI.EnumFlagsToInt(type, value);
EnumFlagsToInt just does this:
private static Enum EnumFlagsToInt(Type type, int value)
{
return Enum.Parse(type, value.ToString()) as Enum;
}
So it doesn’t really care about the actual values of the enum members. It just shows the enum member names in the order they are returned by “Enum.GetNames” and treat them as 1,2,4,8,16, … regardless of their actual value.
That’s why i wrote this wrapper a long time ago. It should work with all bitflag enums and will also handle “combined” values like: