在我的程序中,我有以下代码:
private void SetCorners<T>(T position, int width, int height)
{
float halfWidth = width / 2 + position.X;
float halfHeight = height / 2 + position.Y;
UpperLeft = new Vector2(-halfWidth, -halfHeight);
UpperRight = new Vector2(halfWidth, -halfHeight);
LowerLeft = new Vector2(-halfWidth, halfHeight);
LowerRight = new Vector2(halfWidth, halfHeight);
}
其中 T 要么是Vector2
要么Vector3
来自Microsoft.Xna.Framework
。此代码不构建,因为T
不包含它们的定义。如何使此方法有效?