1
我想使用Texture2D作为基础枚举。类似于Color Works的方式。即。 Color.Black有没有办法使用Texture2D作为枚举的基础
这不能编译,因为你不能使用Texture2D作为基础,我使用这段代码来演示我想要的。
public class Content
{
public Dictionary<string,Texture2D> Textures =new Dictionary<string, Texture2D>();
}
public enum Texture:Texture2D
{
Player = Content.Textures["Player"],
BackGround = Content.Textures["BackGround"],
SelectedBox = Content.Textures["SelectedBox"],
Border = Content.Textures["Border"],
HostButton = Content.Textures["HostButton"]
}
然后可以像使用
Texture2D myTexture= Content.Texture.Player;
我喜欢这一个,它基本上做同样的事情作为枚举。 – 2012-07-09 13:08:09