IMO,这里最简单的答案:
private Vector3 position;
public Vector3 Position {
get {return position;}
set {position = value;} // with @Mehrdad's optimisation
}
public float X {
get {return position.X;}
set {position.X = value;}
}
public float Y {
get {return position.Y;}
set {position.Y = value;}
}
public float Z {
get {return position.Z;}
set {position.Z = value;}
}
现在你可以改变了obj.X
,如果你只需要改变一个维度,或者改变就可以改变一切。obj.Y
obj.Z
obj.Position
如果您需要名称position
来实现接口,请明确执行:
Vector3 IWhateverInterface.position {
get {return position;}
set {position = value;}
}