Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Fixed improperly destroying GameObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
andoowhy committed Feb 1, 2017
1 parent a1da7c5 commit 0dd59d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Constraints/EgoConstraint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ protected bool CanUpdate( EgoComponent egoComponent )
/// <param name="egoComponent"></param>
public void CreateBundles( EgoComponent egoComponent )
{
if( egoComponent == null ) { return; }

// Only Create Bundles from the youngest EgoConstraint
if( childConstraint != null )
{
Expand Down Expand Up @@ -98,6 +100,8 @@ public void CreateBundles( EgoComponent egoComponent )

public void RemoveBundles( EgoComponent egoComponent )
{
if( egoComponent == null ) { return; }

RemoveChildBundles( this, egoComponent );
RemoveParentBundles( this, egoComponent );
rootBundles.Remove( egoComponent );
Expand Down
18 changes: 8 additions & 10 deletions Ego.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ public static C AddComponent<C>( EgoComponent egoComponent ) where C : Component

public static void DestroyGameObject( EgoComponent egoComponent )
{
EgoEvents<DestroyedGameObject>.AddEvent( new DestroyedGameObject( egoComponent.gameObject, egoComponent ) );
var gameObject = egoComponent.gameObject;
EgoEvents<DestroyedGameObject>.AddEvent( new DestroyedGameObject( gameObject, egoComponent ) );
EgoCleanUp.Destroy( egoComponent.gameObject );
}

public static bool DestroyComponent<C>( EgoComponent egoComponent ) where C : Component
{
C component = null;
if( egoComponent.TryGetComponents<C>( out component ) )
{
var e = new DestroyedComponent<C>( component, egoComponent );
EgoEvents<DestroyedComponent<C>>.AddEvent( e );
EgoCleanUp<C>.Destroy( egoComponent, component );

return true;
}
if( !egoComponent.TryGetComponents<C>( out component ) ){ return false; }

return false;
var e = new DestroyedComponent<C>( component, egoComponent );
EgoEvents<DestroyedComponent<C>>.AddEvent( e );
EgoCleanUp<C>.Destroy( egoComponent, component );
return true;
}

public static void SetParent( EgoComponent parent, EgoComponent child )
Expand Down
8 changes: 2 additions & 6 deletions System/EgoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ public EgoSystem()
{
constraint = new EC();
constraint.SetSystem( this );
EgoEvents<AddedGameObject>.AddHandler( Handle );
EgoEvents<AddedGameObject>.AddHandler( e => constraint.CreateBundles( e.egoComponent ) );
EgoEvents<DestroyedGameObject>.AddHandler( e => constraint.RemoveBundles( e.egoComponent ) );
}

public override void CreateBundles( EgoComponent egoComponent )
{
constraint.CreateBundles( egoComponent );
}

protected void Handle( AddedGameObject e )
{
constraint.CreateBundles( e.egoComponent );
}
}

0 comments on commit 0dd59d2

Please sign in to comment.