Files
sbox-public/engine/Sandbox.Engine/Scene/Components/Camera/CameraComponent.Effects.cs
Garry Newman ca96c2a945 Make Inventory, BaseWeapon, AmmoResource, Screenshake first party (#5245)
https://sbox.game/dev/doc/gameplay/inventory-weapons/

Added

InventoryComponent - a slot based inventory, hotbar or shared bucket slots, with a starting loadout
BaseInventoryItem - base class for inventory items, with hooks to veto switching, holstering and dropping
BaseWeapon - a GMod style base weapon - fire modes, magazines and reserve ammo, reloading, dry fire, ballistics, spread, crosshair and HUD
BaseWeaponModel - view/world model base with muzzle flash, brass ejection, tracers and animation hooks
Ammo types are resources (.ammo) - weapons share reserve pools by type, clamped to a max reserve
BaseWeapon.ShootBullets / ShootBullet - bullet tracing with damage, impulse and hitbox tags
Weapon hold types editor
Animgraph enum parameters can be set by option name - Renderer.Set( "holdtype", "pistol" )
NpcUsage on BaseWeapon - engagement range and burst behaviour so NPCs can use any weapon
ICameraModifier - cameras compose their view through an ordered modifier chain, read the result from CameraComponent.View
CameraEffectSystem - screen shake, directional punches and tilts, with world epicenter falloff - camera.AddShake / AddPunch / AddTilt
EnvShake component - shakes the view, rumbles controllers, kicks physics
TracerEffect - an animated tracer line, ITargetedEffect for effects that fly at a target
SceneAnchor - a world position that can follow an object or bone
SkinnedModelRenderer.GetClosestBone( worldPosition )
Vector3.WithAimCone can take a custom Random for reproducible spread
Improve/Fix

PlayerController searches parents for IPressable when pressing
PlayerController camera runs through the modifier chain - IEvents.PostCameraSetup is obsolete
SoundPlayer preview uses shortcuts - Space toggles playback, Ctrl+Space restarts
Fixed Radius( 0 ) traces missing everything
Fixed NRE in AssetPreviewWidget
Removed

Removed CameraComponent.ISceneCameraSetup (obsolete since October, nothing uses)
2026-07-04 12:46:59 +01:00

63 lines
2.6 KiB
C#

namespace Sandbox;
public sealed partial class CameraComponent
{
//
// The front door for camera effects - forwards into the scene's CameraEffectSystem, which owns
// the effects. Use the system directly for world-epicenter shakes, custom effects and Scale.
//
/// <summary>
/// Add a custom camera effect (a <see cref="CameraEffectSystem.BaseEffect"/> subclass), targeted
/// at this camera.
/// </summary>
public T AddEffect<T>( T effect ) where T : CameraEffectSystem.BaseEffect
{
if ( effect is null )
return null;
effect.Camera = this;
return CameraEffectSystem.Get( Scene )?.Add( effect );
}
/// <summary>
/// Shake this camera - the classic screen shake (Half-Life's env_shake). Every
/// 1/<paramref name="frequency"/> seconds a new random offset within <paramref name="amplitude"/>
/// world units, settling to nothing over <paramref name="duration"/>. A duration of zero shakes
/// until <see cref="CameraEffectSystem.BaseEffect.Stop"/>.
/// </summary>
public CameraEffectSystem.BaseEffect AddShake( float amplitude, float frequency, float duration )
{
return CameraEffectSystem.Get( Scene )?.AddShake( this, amplitude, frequency, duration );
}
/// <summary>
/// Punch this camera along a camera-local direction, oscillating and dying out -
/// <see cref="Vector3.Up"/> bounces the view upward, <paramref name="frequency"/> is how many
/// oscillations before it lapses.
/// </summary>
public CameraEffectSystem.BaseEffect AddPunch( Vector3 direction, float amplitude, float frequency = 1f, float duration = 0.3f, float fovAmplitude = 0f )
{
return CameraEffectSystem.Get( Scene )?.AddPunch( this, direction, amplitude, frequency, duration, fovAmplitude );
}
/// <summary>
/// Punch this camera's view angles - it kicks to <paramref name="angles"/> and bounces back,
/// oscillating <paramref name="frequency"/> times before it lapses. Melee swings, landings,
/// launches. Render-only - the player's aim never moves.
/// </summary>
public CameraEffectSystem.BaseEffect AddPunch( Angles angles, float frequency = 1f, float duration = 0.3f, float fovAmplitude = 0f )
{
return CameraEffectSystem.Get( Scene )?.AddPunch( this, angles, frequency, duration, fovAmplitude );
}
/// <summary>
/// Tilt this camera by <paramref name="angle"/>, eased in over <paramref name="easeTime"/> and
/// back out before <paramref name="duration"/> ends.
/// </summary>
public CameraEffectSystem.BaseEffect AddTilt( Angles angle, float duration, float easeTime = 0.2f )
{
return CameraEffectSystem.Get( Scene )?.AddTilt( this, angle, duration, easeTime );
}
}