我正在尝试创建一个灵活的系统来为我的游戏中的角色穿衣。现在我有一个基类,所有 child 服装类都将从中扩展,还有额外的接口(interface),可以将他们实际穿着的 body 部位带入等式。这是我的代码:
public class Clothing
{
public EClothingBind[] Types;
public int ID;
public int Priority;
public bool HidesUnderlying;
public AnimatedSpriteMap Graphic;
public Color Blend = Color.White;
public virtual void Update(GameTime gameTime)
{
Graphic.Update(gameTime);
}
public virtual void Draw(Vector2 position)
{
Graphic.Tint = Blend;
Graphic.Draw(position);
}
}
public interface IClothingHead { ... }
public interface IClothingChest { ... }
public interface IClothingLegs { ... }
public interface IClothingFeet { ... }
现在这并不能很好地工作,因为设计并没有真正限制什么可以实现我的 IClothing 接口(interface)。有没有办法将接口(interface)实现限制为某些类型?我不想将我的接口(interface)变成类,因为我想要一件衣服,比如一件长袍,来覆盖整个 body (实现所有四个)。我对执行此操作的最佳方法有点迷茫,非常感谢所有意见。谢谢。
最佳答案
我认为您正在通过这种方法为 future 的艰难时期做好准备。当然,一件长袍包罗万象,从图形上看,它会而且可能会影响 4 个区域的“护甲”值。但是这样实现看起来很麻烦。您可能只需要一个 IClothing 界面并确定可以放置它的位置(例如:手/脚等)。传统上,长袍通常是胸甲,但在图形上它们覆盖了整个角色。
enum PositionType
{
Head,
Chest,
Hand,
Feet,
Finger,
Neck
}
public interface IClothing
{
PositionType Type { get; }
// Other things you need IClothing-classed to implement
}
我认为这可能是一种更好的方法,而不是试图通过实现多个接口(interface)来精确调整特定服装的 body 部位。
关于C#角色服装系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8451955/