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

Commit

Permalink
Fixed EgoComponents not being added to child GameObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
andoowhy committed Feb 3, 2017
1 parent 0dd59d2 commit 9e78079
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions Ego.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ public static class Ego
{
public static EgoComponent AddGameObject( GameObject gameObject )
{
var egoComponent = gameObject.GetComponent<EgoComponent>();
if( egoComponent == null ){ egoComponent = gameObject.AddComponent<EgoComponent>(); }
egoComponent.CreateMask();
var egoComponent = AddGameObjectToChildren( gameObject.transform );
EgoEvents<AddedGameObject>.AddEvent( new AddedGameObject( gameObject, egoComponent ) );
return egoComponent;
}

private static EgoComponent AddGameObjectToChildren( Transform transform )
{
for (int i = 0; i < transform.childCount; i++)
{
AddGameObjectToChildren( transform.GetChild( i ) );
}

var egoComponent = transform.GetComponent<EgoComponent>();
if( egoComponent == null )
{
egoComponent = transform.gameObject.AddComponent<EgoComponent>();
}

egoComponent.CreateMask();

return egoComponent;
}

public static C AddComponent<C>( EgoComponent egoComponent ) where C : Component
{
C component = null;
Expand Down

0 comments on commit 9e78079

Please sign in to comment.