Files
sbox-public/engine/Sandbox.Engine/Scene/Components/Light/PointLight.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

56 lines
1.3 KiB
C#

namespace Sandbox;
/// <summary>
/// Emits light in all directions from a point in space.
/// </summary>
[Expose]
[Title( "Point Light" )]
[Category( "Light" )]
[Icon( "light_mode" )]
[EditorHandle( "materials/gizmo/pointlight.png" )]
[Alias( "PointLightComponent" )]
public class PointLight : Light
{
[Property, MakeDirty] public float Radius { get; set; } = 400;
[Property, MakeDirty, Range( 0, 10 )] public float Attenuation { get; set; } = 1.0f;
// [Property, MakeDirty] public Texture Cookie { get; set; }
protected override SceneLight CreateSceneObject()
{
return new SceneLight( Scene.SceneWorld, WorldPosition, Radius, LightColor );
}
protected override void OnAwake()
{
Tags.Add( "light_point" );
base.OnAwake();
}
protected override void UpdateSceneObject( SceneLight o )
{
base.UpdateSceneObject( o );
o.Radius = Radius;
o.QuadraticAttenuation = Attenuation;
// o.LightCookie = Cookie;
}
protected override void DrawGizmos()
{
using var scope = Gizmo.Scope( $"light-{GetHashCode()}" );
if ( Gizmo.IsSelected )
{
Gizmo.Draw.Color = LightColor.WithAlpha( 0.9f );
Gizmo.Draw.LineSphere( new Sphere( Vector3.Zero, Radius ), 12 );
}
if ( Gizmo.IsHovered && Gizmo.Settings.Selection )
{
Gizmo.Draw.Color = LightColor.WithAlpha( 0.4f );
Gizmo.Draw.LineSphere( new Sphere( Vector3.Zero, Radius ), 12 );
}
}
}