mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-02 08:50:18 -04:00
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)
69 lines
2.7 KiB
C#
69 lines
2.7 KiB
C#
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// The camera view being composed for a frame - position, rotation and field of view. The camera's
|
|
/// owner writes the base values (its transform and <see cref="CameraComponent.FieldOfView"/>), then
|
|
/// <see cref="ICameraModifier"/>s reshape them in order, then transient render effects
|
|
/// (<see cref="CameraEffectSystem"/>) apply on top. Read the composed result from
|
|
/// <see cref="CameraComponent.View"/>.
|
|
/// </summary>
|
|
public struct CameraView : IEquatable<CameraView>
|
|
{
|
|
/// <summary>Where the camera sits, in world space.</summary>
|
|
public Vector3 Position;
|
|
|
|
/// <summary>Which way the camera looks.</summary>
|
|
public Rotation Rotation;
|
|
|
|
/// <summary>Field of view, in degrees.</summary>
|
|
public float FieldOfView;
|
|
|
|
/// <summary>Near clip plane distance.</summary>
|
|
public float ZNear;
|
|
|
|
/// <summary>Far clip plane distance.</summary>
|
|
public float ZFar;
|
|
|
|
/// <summary>The view's position and rotation as a transform.</summary>
|
|
public readonly Transform Transform => new( Position, Rotation );
|
|
|
|
/// <summary>The ray looking out of the view - for aim traces from the composed camera.</summary>
|
|
public readonly Ray ForwardRay => new( Position, Rotation.Forward );
|
|
|
|
public readonly bool Equals( CameraView other ) =>
|
|
Position == other.Position &&
|
|
Rotation == other.Rotation &&
|
|
FieldOfView == other.FieldOfView &&
|
|
ZNear == other.ZNear &&
|
|
ZFar == other.ZFar;
|
|
|
|
public override readonly bool Equals( object obj ) => obj is CameraView other && Equals( other );
|
|
public override readonly int GetHashCode() => HashCode.Combine( Position, Rotation, FieldOfView, ZNear, ZFar );
|
|
|
|
public static bool operator ==( CameraView a, CameraView b ) => a.Equals( b );
|
|
public static bool operator !=( CameraView a, CameraView b ) => !a.Equals( b );
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reshapes a camera's view each frame - scope zoom, vehicle roll, aim-down-sights. Implement on any
|
|
/// component: when a camera composes its view it runs every modifier in <see cref="CameraOrder"/>,
|
|
/// then hands the final view to <see cref="PostCameraSetup"/> so things can be placed against it.
|
|
/// </summary>
|
|
public interface ICameraModifier
|
|
{
|
|
/// <summary>Lower runs first - a player's camera ~0, vehicles ~100, held weapons ~200.</summary>
|
|
public int CameraOrder => 0;
|
|
|
|
/// <summary>
|
|
/// Reshape the view. Runs once per camera per frame, in order, at the camera stage of the
|
|
/// tick - after Update and bone merging, before PreRender.
|
|
/// </summary>
|
|
public void ModifyCamera( CameraComponent camera, ref CameraView view ) { }
|
|
|
|
/// <summary>
|
|
/// The view is final, before render effects - place things against it (view models, attached
|
|
/// props). Don't modify the camera here.
|
|
/// </summary>
|
|
public void PostCameraSetup( CameraComponent camera, in CameraView view ) { }
|
|
}
|