C# allows you to assign values to your enum elements such as
public enum Animals
{
Dog = 0, Cat = 1,
}
And You can cast too and from them like so.
public void demo()
{
int dog = (int)Animals.Dog;
Animals cat = (Animals)(dog++);
}
But c# also lets you do things like this
public enum Animals
{
Dog = Vector2.One, Cat = Vector2.Zero,
}
However you cannot get the Vector2 back in and out with a cast. such as
Vector2 dog = (Vector2)Animals.Dog; //this fails
Is this problem solvable? *Note Vector2 is a class object and Vector2.One and Vector2.Zero are static declarations of such. Which means Dog is assigned to a memory reference.
The only way that C# will let you do
Is if there is an implicit cast from
Vector2to an integral type. Otherwise, you will get a compile error. This is why you cannot cast back toVector2– there is no cast fromintback toVector2.DogandCatare integer valued, and the values come from the implicit cast fromVector2.OneandVector2.Zerotoint, respectively.You could define your own explicit cast to make it work, but I’m guessing you won’t be able to get back all the information you want that way.