我想将Texture2D用于基本枚举。类似于Color Works的方式。即。 Color.Black
这不能编译,因为你不能使用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;
答案 0 :(得分:3)
您不能将对象用作枚举的基础。你可以做的是将不同的纹理作为静态属性添加到类中:
public static class Texture
{
public static Texture2D Player { get; private set; }
public static Texture2D BackGround { get; private set; }
...
static Texture()
{
Player = Content.Textures["Player"];
BackGround = Content.Textures["BackGround"];
...
}
}
这样你可以按照自己的意愿使用它们:
Texture2D myTexture = Texture.Player;