diff --git a/engine/Sandbox.Engine/Scene/Components/Game/Hitbox.cs b/engine/Sandbox.Engine/Scene/Components/Game/Hitbox.cs index 9fdf95b7..b7facdf5 100644 --- a/engine/Sandbox.Engine/Scene/Components/Game/Hitbox.cs +++ b/engine/Sandbox.Engine/Scene/Components/Game/Hitbox.cs @@ -23,7 +23,7 @@ internal Hitbox( GameObject gameObject, BoneCollection.Bone bone, ITagSet tagSet public BoneCollection.Bone Bone { get; private set; } public ITagSet Tags { get; private set; } public PhysicsBody Body { get; set; } - internal BBox Bounds { get; set; } + public BBox Bounds { get; set; } public void Dispose() { diff --git a/engine/Sandbox.Engine/Scene/Components/Game/ModelHitboxes.cs b/engine/Sandbox.Engine/Scene/Components/Game/ModelHitboxes.cs index f0abeae3..6845a317 100644 --- a/engine/Sandbox.Engine/Scene/Components/Game/ModelHitboxes.cs +++ b/engine/Sandbox.Engine/Scene/Components/Game/ModelHitboxes.cs @@ -12,8 +12,6 @@ public sealed class ModelHitboxes : Component, Component.ExecuteInEditor { HitboxSystem system; - SkinnedModelRenderer _renderer; - /// /// The target SkinnedModelRenderer that holds the model/skeleton you want to /// take the hitboxes from. @@ -21,33 +19,31 @@ public sealed class ModelHitboxes : Component, Component.ExecuteInEditor [Property] public SkinnedModelRenderer Renderer { - get => _renderer; + get; set { - if ( _renderer == value ) return; + if ( field == value ) return; Clear(); - _renderer = value; + field = value; AddFrom( Renderer ); } } - GameObject _target; - /// /// The target GameObject to report in trace hits. If this is unset we'll defaault to the gameobject on which this component is. /// [Property] public GameObject Target { - get => _target; + get; set { - if ( _target == value ) return; + if ( field == value ) return; - _target = value; + field = value; Rebuild(); } @@ -73,10 +69,16 @@ protected override void OnDestroy() Clear(); } + /// + /// Invoked when the hitboxes have been rebuilt. + /// + public Action HitboxesRebuilt; + public void Rebuild() { Clear(); AddFrom( Renderer ); + HitboxesRebuilt?.Invoke(); } void Clear() @@ -165,11 +167,58 @@ public void UpdatePositions() internal readonly List Hitboxes = new(); + /// + /// Adds a hitbox to the models hitbox list + /// + /// public void AddHitbox( Hitbox hitbox ) { Hitboxes.Add( hitbox ); } + /// + /// Removes a hitbox from the models hitbox list. + /// + /// + public void RemoveHitbox( Hitbox hitbox ) + { + Hitboxes.Remove( hitbox ); + } + + /// + /// Returns every hitbox on this model. + /// + /// + public IReadOnlyList GetHitboxes() => Hitboxes; + + /// + /// Retrieves the hitbox associated with the bone index. + /// + /// The bone index to retrieve. + /// null if no matching hitbox is found. + public Hitbox GetHitbox( int boneIndex ) => Hitboxes.FirstOrDefault( x => x.Bone.Index == boneIndex ); + + /// + /// Retrieves the hitbox associated with the specified bone. + /// + /// The bone for which to find the corresponding hitbox. + /// null if no matching hitbox is found. + public Hitbox GetHitbox( BoneCollection.Bone bone ) => Hitboxes.FirstOrDefault( x => x.Bone == bone ); + + /// + /// Retrieves the hitbox associated with the specified bone name. + /// + /// The name of the bone for which to retrieve the hitbox. + /// null if no matching hitbox is found. + public Hitbox GetHitbox( string boneName ) => Hitboxes.FirstOrDefault( x => x.Bone.Name == boneName ); + + /// + /// Retrieves the hitbox associated with the specified physics body. + /// + /// The physics body for which to find the corresponding hitbox. + /// null if no matching hitbox is found. + public Hitbox GetHitbox( PhysicsBody physicsBody ) => Hitboxes.FirstOrDefault( x => x.Body == physicsBody ); + /// /// The gameobject tags have changed, update collision tags on the target objects /// diff --git a/engine/Sandbox.Engine/Scene/Components/Render/ModelRenderer.cs b/engine/Sandbox.Engine/Scene/Components/Render/ModelRenderer.cs index d4bb0b7d..6f851fdd 100644 --- a/engine/Sandbox.Engine/Scene/Components/Render/ModelRenderer.cs +++ b/engine/Sandbox.Engine/Scene/Components/Render/ModelRenderer.cs @@ -196,7 +196,10 @@ internal void OnModelReloaded() OnModelChanged(); } - internal Action ModelChanged; + /// + /// Invoked when has been changed. + /// + public Action ModelChanged; internal void OnModelChanged() {