【发布时间】:2019-11-22 15:28:21
【问题描述】:
我正在编写一个车辆控制器,它应该能够处理多种不同的车辆类型,而不是使用继承,因此我可以将类的数量保持在最低限度。我想删除检查每个固定帧的常量类型,但我不知道该怎么做。
private void FixedUpdate()
{
if (VehicleSchema is VehicleSchema_AFV.Hovercraft)
{
UpdatePosition(transform.forward, false);
UpdateYawRotation(false);
AlignToTerrain(false, false);
VehicleSchema_AFV afv = (VehicleSchema_AFV)VehicleSchema;
UpdateTurretRotation(afv.TurretObj);
}
else if (VehicleSchema is VehicleSchema_AFV.Wheeledcraft)
{
UpdatePosition(transform.forward, false);
UpdateYawRotation(true);
AlignToTerrain(true, true);
VehicleSchema_AFV afv = (VehicleSchema_AFV)VehicleSchema;
UpdateTurretRotation(afv.TurretObj);
}
else if (VehicleSchema is VehicleSchema_AFV.Trackedcraft)
{
UpdatePosition(transform.forward, false);
UpdateYawRotation(false);
AlignToTerrain(true, false);
VehicleSchema_AFV afv = (VehicleSchema_AFV)VehicleSchema;
UpdateTurretRotation(afv.TurretObj);
}
else if (VehicleSchema is VehicleSchema_Mech)
{
UpdatePosition(transform.forward, false);
UpdateYawRotation(false);
AlignToTerrain(true, false);
VehicleSchema_Mech mech = (VehicleSchema_Mech)VehicleSchema;
UpdateTurretRotation(mech.TorsoObject);
}
else if (VehicleSchema is VehicleSchema_Aircraft.VTOL)
{
UpdatePosition(transform.up, true);
UpdateYawRotation(false);
UpdatePitchRotation();
UpdateRollRotation();
VehicleSchema_Aircraft.VTOL vtol = (VehicleSchema_Aircraft.VTOL)VehicleSchema;
UpdateTurretRotation(vtol.TurretObj);
}
}
【问题讨论】: