We advise against using this. It may be changed or removed in a future update.
Hammer will be replaced with an in-scene mesh editor
Hammer Gizmos
You can create interactive Gizmos in Hammer for your game's map entities.
This gives you a great way to visualize what your entities will do before baking your map.
public partial class DoorEntity
public static void DrawGizmos( EditorContext context )
{
var model = context.Target.GetProperty( "model" ).GetValue<string>();
var distance = context.Target.GetProperty( "distance" ).GetValue<int>();
var angle = MathF.Abs( MathF.Sin( RealTime.Now ) ) * distance;
Gizmo.Draw.Color = Color.White.WithAlpha( 0.6f );
Gizmo.Draw.Model( model, new Transform( default, Rotation.FromYaw( angle ) ) );
}
}
Interactive Gizmos
As well as displaying your entities' properties, you can also set them directly from interacting with gizmos.
public static void DrawGizmos( EditorContext context )
{
var radiusProp = context.Target.GetProperty( "Radius" );
var radius = radiusProp.As.Float;
using ( Gizmo.Scope() )
{
var cameraDelta = Gizmo.Transform.Position - Gizmo.Camera.Position;
Gizmo.Transform = Gizmo.Transform.WithRotation( Rotation.LookAt( cameraDelta ) );
Gizmo.Hitbox.Circle( 0, Vector3.Forward, radius + 5, radius );
Gizmo.Draw.Color = Gizmo.Colors.Left.WithAlpha( Gizmo.IsHovered ? 1 : 0.3f );
Gizmo.Draw.LineThickness = 4;
Gizmo.Draw.IgnoreDepth = true;
Gizmo.Draw.LineCircle( 0, radius + 4, sections: 64 );
if ( Gizmo.IsPressed )
{
var pos = Gizmo.GetPositionOnPlane( 0, Gizmo.Transform.NormalToLocal( cameraDelta.Normal ), Gizmo.CurrentRay ) ?? 0;
radius = pos.Length;
radiusProp.SetValue( radius );
}
}
}
EditorContext
EditorContext provides a way for your game code to know details about what's going on in the map editor.
Selection
public static void DrawGizmos( EditorContext context )
{
if ( context.IsSelected )
return;
}
Finding Targets
Many entities target other entities by name, you can use FindTarget for this.
[Property( "target" ), Title( "Target Entity" )]
public EntityTarget TargetEntity { get; set; }
public static void DrawGizmos( EditorContext context )
{
var targetProp = context.Target.GetProperty( "target" );
var targetName = targetProp.GetValue<string>();
var targetObject = context.FindTarget( targetName );
if ( targetObject != null )
{
var local = Gizmo.Transform.ToLocal( targetObject.Transform );
var arrowSize = local.Position.Normal * 20.0f;
Gizmo.Draw.Color = Color.Random;
Gizmo.Draw.LineThickness = 2;
Gizmo.Draw.Line( 0, local.Position );
Gizmo.Draw.SolidCone( local.Position - arrowSize, arrowSize, 10.0f );
}
}