浏览代码

Added debug mode for boat testing

/main
Andre McGrail 4 年前
当前提交
fbc2ca79
共有 2 个文件被更改,包括 44 次插入21 次删除
  1. 64
      Assets/Scripts/Boat/Boat.cs
  2. 1
      Assets/Scripts/Editor/BoatControllerEditor.cs

64
Assets/Scripts/Boat/Boat.cs


private static readonly int LiveryPrimary = Shader.PropertyToID("_Color1");
private static readonly int LiveryTrim = Shader.PropertyToID("_Color2");
// debug
[SerializeField] internal bool debugControl = false;
if (debugControl)
{
Setup(1, true, RandomLivery());
}
_spawnPosition = transform.localToWorldMatrix;
TryGetComponent(out engine.RB);
}

private void Update()
{
UpdateLaps();
if (RaceManager.RaceStarted)
{
UpdateLaps();
if (RaceUi)
{
RaceUi.UpdatePlaceCounter(Place);
RaceUi.UpdateSpeed(engine.VelocityMag);
if (RaceUi)
{
RaceUi.UpdatePlaceCounter(Place);
RaceUi.UpdateSpeed(engine.VelocityMag);
}
}
}

{
if (!RaceManager.RaceStarted)
{
// race not started, make sure to keep boat fairly aligned.
var target = WaypointGroup.Instance.StartingPositions[_playerIndex];
Vector3 targetPosition = target.GetColumn(3);
Vector3 targetForward = target.GetColumn(2);
var t = transform;
var currentPosition = t.position;
var currentForward = t.forward;
if(WaypointGroup.Instance) AlignBoatWithStartingLine();
}
}
targetPosition.y = currentPosition.y;
engine.RB.AddForce((currentPosition - targetPosition) * 0.25f);
private void AlignBoatWithStartingLine()
{
// race not started, make sure to keep boat fairly aligned.
var target = WaypointGroup.Instance.StartingPositions[_playerIndex];
Vector3 targetPosition = target.GetColumn(3);
Vector3 targetForward = target.GetColumn(2);
var t = transform;
var currentPosition = t.position;
var currentForward = t.forward;
engine.RB.MoveRotation(Quaternion.LookRotation(Vector3.Slerp(currentForward, targetForward, 0.1f * Time.fixedDeltaTime)));
targetPosition.y = currentPosition.y;
engine.RB.AddForce((currentPosition - targetPosition) * 0.25f);
}
engine.RB.MoveRotation(Quaternion.LookRotation(Vector3.Slerp(currentForward, targetForward, 0.1f * Time.fixedDeltaTime)));
}
private void UpdateLaps()

[ContextMenu("Randomize")]
private void ColorizeInvoke()
{
Colorize(Color.black, Color.black, true);
Colorize(RandomLivery());
private void Colorize(Color primaryColor, Color trimColor, bool random = false)
private void Colorize(Color primaryColor, Color trimColor)
primaryColor = random ? ConstantData.GetRandomPaletteColor : primaryColor,
trimColor = random ? ConstantData.GetRandomPaletteColor : trimColor
primaryColor = primaryColor,
trimColor = trimColor
};
Colorize(livery);
}

engine.RB.position = resetPoint;
engine.RB.rotation = resetMatrix.rotation;
}
}
BoatLivery RandomLivery()
{
var livery = new BoatLivery
{
primaryColor = ConstantData.GetRandomPaletteColor,
trimColor = ConstantData.GetRandomPaletteColor
};
return livery;
}
}

1
Assets/Scripts/Editor/BoatControllerEditor.cs


}
EditorGUILayout.EndVertical();
EditorGUI.indentLevel--;
}
EditorGUILayout.EndFoldoutHeaderGroup();

正在加载...
取消
保存