Skip to content

Commit

Permalink
some factoring on bodypart
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Aug 21, 2023
1 parent 169fff0 commit a4b0132
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Assets/Scripts/SS3D/Systems/Health/Bodypart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public virtual void Init(BodyPart parentBodyPart, List<BodyPart> childBodyParts,

/// <summary>
/// The body part is not destroyed, it's simply detached from the entity.
/// Spawn a detached body part from the entity, and destroy this one with all childs.
/// Spawn a detached body part from the entity, and destroy this one.
/// This spawns an item based on this body part. Upon being detached, some specific treatments are needed for some bodyparts.
/// Implementation should handle instantiating _bodyPartItem, removing the bodypart game object and doing whatever else is necessary.
/// </summary>
Expand All @@ -128,14 +128,7 @@ protected virtual void DetachBodyPart()
*/
GameObject go = Instantiate(_bodyPartItem, Position, Rotation);
InstanceFinder.ServerManager.Spawn(go, null);

var containers = GetComponentsInChildren<AttachedContainer>();
foreach (var container in containers)
{
container.Container.Dump();
}
gameObject.Dispose(true);

Dispose();
}

/// <summary>
Expand All @@ -145,13 +138,21 @@ protected virtual void DetachBodyPart()
/// </summary>
/// <exception cref="NotImplementedException"></exception>
[Server]
public void DestroyBodyPart()
protected virtual void DestroyBodyPart()
{
// destroy this body part with all childs on the entity, detach all childs.
for (int i = _childBodyParts.Count - 1; i >= 0; i--)
{
_childBodyParts[i].RemoveBodyPart();
}
Dispose();
}

/// <summary>
/// Method to call at the end of Destroy and/or Detach
/// </summary>
protected void Dispose()
{
_parentBodyPart?._childBodyParts.Remove(this);
_parentBodyPart = null;
var containers = GetComponentsInChildren<AttachedContainer>();
Expand Down

0 comments on commit a4b0132

Please sign in to comment.