Deduplication pass (44 extractions): - New SmoothedLook: shared smoothed yaw/pitch look tick + view seeding (FirstPersonController, FreeCamController) - New CharacterTeleport: disable-CC-around-teleport idiom (rescue, owner position apply, free-cam sync) - New GeometryUtil: RescaleToUnitScale + TransformBounds (concealment meter/volume, skinned collider baker) - Paint family: canonical map read/write shared between Net and Persistence, snapshot decode, backend stroke dispatch, RebuildBackend, ResolveSeed, chunked RPC send/gate/copy, CamoKnobs/HeightKnobs aggregates, SanitizeFileKey, NewMaskTexture, AdoptAlbedo, FindSlider - Player/modes: GameMode SetPlayerControl/SetPainting/SetOrbitInputEnabled, InputUtil.GameplayKeyPressed, NearestClimbHit, ComputeXRay delegates to ComputeResolutionFreeze, FingerIK TryInPlaneAngle - Match/misc: UnhookSessionCallbacks, SendEmptyNamedMessage, SwapScenes, RunSessionOpAsync, CovarianceEigen, CollectClusterPoints, MatchHud GUIStyle cache, HsvColorPicker rehook, VoxelCenter Documentation pass: remove 6 triplicated doc blocks and 2 restating inline comments left after the previous reduction. Behavior-neutral; hot-path rasterizer loops intentionally untouched. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// Mouse-look yaw/pitch accumulator with optional SmoothDampAngle smoothing, shared by the
|
|
/// first-person and freecam rigs. <see cref="Tick"/> accumulates a scaled mouse delta into the
|
|
/// target angles and advances the smoothed display angles; <see cref="SyncTo"/> seeds everything
|
|
/// from an existing rotation so going live produces no visible jump.
|
|
/// </summary>
|
|
public struct SmoothedLook
|
|
{
|
|
float _yaw; // look target (raw input accumulates here)
|
|
float _pitch;
|
|
float _displayYaw; // smoothed value actually applied to the transform
|
|
float _displayPitch;
|
|
float _yawSmoothRef;
|
|
float _pitchSmoothRef;
|
|
|
|
/// <summary>Smoothed yaw shown this frame (drives the body's facing in first person).</summary>
|
|
public float DisplayYaw => _displayYaw;
|
|
|
|
/// <summary>Rotation composed from the smoothed display angles.</summary>
|
|
public Quaternion Rotation => Quaternion.Euler(_displayPitch, _displayYaw, 0f);
|
|
|
|
/// <summary>Accumulates one frame of look input and advances the smoothed display angles.</summary>
|
|
public void Tick(Vector2 scaledDelta, float hSens, float vSens, bool invertY, float maxPitch, float smoothTime)
|
|
{
|
|
_yaw += scaledDelta.x * hSens;
|
|
float vs = vSens * (invertY ? 1f : -1f);
|
|
_pitch = Mathf.Clamp(_pitch + scaledDelta.y * vs, -maxPitch, maxPitch);
|
|
|
|
if (smoothTime > 0f)
|
|
{
|
|
// SmoothDampAngle is frame-rate-independent and wraps yaw correctly.
|
|
_displayYaw = Mathf.SmoothDampAngle(_displayYaw, _yaw, ref _yawSmoothRef, smoothTime);
|
|
_displayPitch = Mathf.SmoothDampAngle(_displayPitch, _pitch, ref _pitchSmoothRef, smoothTime);
|
|
}
|
|
else
|
|
{
|
|
_displayYaw = _yaw;
|
|
_displayPitch = _pitch;
|
|
}
|
|
}
|
|
|
|
/// <summary>Seeds the look angles from an existing rotation, then snaps the smoothed state to them.</summary>
|
|
public void SyncTo(Quaternion rotation, float maxPitch)
|
|
{
|
|
Vector3 e = rotation.eulerAngles;
|
|
_yaw = e.y;
|
|
float p = e.x > 180f ? e.x - 360f : e.x;
|
|
_pitch = Mathf.Clamp(p, -maxPitch, maxPitch);
|
|
Snap();
|
|
}
|
|
|
|
/// <summary>Snaps the smoothed state to the current targets so entering never lags/jumps to catch up.</summary>
|
|
public void Snap()
|
|
{
|
|
_displayYaw = _yaw;
|
|
_displayPitch = _pitch;
|
|
_yawSmoothRef = 0f;
|
|
_pitchSmoothRef = 0f;
|
|
}
|
|
}
|