private void DrawGizmos() { if (!Application.isPlaying) //don't draw unless we're playing { return; } var frame = Mathf.Max(body.CurrentSnapshotFrame - _frameDelay, 0); if (!TimePhysics.IsFrameValid(frame)) { return; } if (frame % body.SnapshotInterval == 0) //if we are on a snapshot { var index = frame % TimePhysics.NumSnapshots; var snapShot = body.Snapshots[index]; for (int hitboxIndex = 0; hitboxIndex < body.Transforms.Length; hitboxIndex++) { DrawMarkerGizmo( snapShot.LocalToWorld[hitboxIndex], _hitboxMarkersDebug[hitboxIndex], _hitboxColor); } var proxSnapshot = body.Snapshots[index].ProximityBounds; Gizmos.color = _proximityColor; Gizmos.matrix = Matrix4x4.identity; Gizmos.DrawWireCube(proxSnapshot.center, proxSnapshot.size); } else // lerp { int index1, index2; var lerpVal = body.LerpFrame(frame, out index1, out index2); var snapShot1 = body.Snapshots[index1]; var snapShot2 = body.Snapshots[index2]; for (int hitboxIndex = 0; hitboxIndex < body.Transforms.Length; hitboxIndex++) { DrawMarkerGizmo( MatrixUtils.LerpMatrixTR( ref snapShot1.LocalToWorld[hitboxIndex], ref snapShot2.LocalToWorld[hitboxIndex], lerpVal, body.Transforms[hitboxIndex].lossyScale), _hitboxMarkersDebug[hitboxIndex], _hitboxColor); } var proxSnapshot1 = body.Snapshots[index1].ProximityBounds; var proxSnapshot2 = body.Snapshots[index2].ProximityBounds; var lerpBounds = MatrixUtils.LerpBounds(ref proxSnapshot1, ref proxSnapshot2, lerpVal); Gizmos.color = _proximityColor; Gizmos.matrix = Matrix4x4.identity; Gizmos.DrawWireCube(lerpBounds.center, lerpBounds.size); } }
private void OnDisable() { TimePhysics.UnregisterHitboxBody(this); }
private void OnEnable() { TimePhysics.RegisterHitboxBody(this); _startFrame = TimePhysics.WorldFrame; }
private void FixedUpdate() => TimePhysics.TakeSnapshot();