If you have an exposed scrip variable in the inspector that has an enum as its type, Unity provides a nice little drop down menu to let you choose from the types contained in the enum.
Is there a way to control which of those are visible/a user can select?
Actually, if you call it with ints, the int overload is called, and it returns an int, so no need for casting.
Just ressurecting the post in case of someone needs: I’ve made a slightly different approach.
First, I’ve created a custom enum with the values I wanted to show.
Then, each value of my custom enum receites the value of the Unity Enum type I want to set. Then, I only need to cast to the Unity Enum Type to set the value to object.
See the example with an Input Field
//That's my custom enum. Only exposes 2 types of numeric values
public enum CustomInputType
{
Integer = InputField.ContentType.IntegerNumber,
Decimal = InputField.ContentType.DecimalNumber
}
//That's the cast I do to set the content type on my InputField
this.inputField.contentType = (InputField.ContentType) this.CustomInputType;
I would look into creating a custom property drawer that ignores specified values.
Having a bit of trouble figuring out how I'd go about telling it what values of the enum to ignore, how do I access the inside of the enum like that? I've used property drawers before, but I don't have a great grasp of them. I feel like the answer will have to do with some sort of mask (given the nature of enums), but I'm really at a loss.
Why not create 2 Enum, one public that only have the values you want exposed in the inspector, and another one private that you use in your script. At Start() you can changes the private version based what is in the public instance with IF statements.
Use the attribute [UnityEngine.HideInInspector] above the entry of your enum you want to hide.
,Use the attribute [UnityEngine.HideInInspector] above the entry you want to hide.
AFAIK this is only allowed for fields and doesn't help much with enum values.
Actually, if you call it with ints, the int overload is called, and it returns an int, so no need for casting.
– TehniqueRight, I missed that part in the documentation. Sorry!
– Chelmney