From 9e780796ea6ba5ca1d83ed7d20bea9bd49cb3ca8 Mon Sep 17 00:00:00 2001 From: Andrew Macdonald Date: Fri, 3 Feb 2017 15:37:35 -0500 Subject: [PATCH] Fixed EgoComponents not being added to child GameObjects --- Ego.cs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Ego.cs b/Ego.cs index 98cd653..4998a34 100644 --- a/Ego.cs +++ b/Ego.cs @@ -4,13 +4,29 @@ public static class Ego { public static EgoComponent AddGameObject( GameObject gameObject ) { - var egoComponent = gameObject.GetComponent(); - if( egoComponent == null ){ egoComponent = gameObject.AddComponent(); } - egoComponent.CreateMask(); + var egoComponent = AddGameObjectToChildren( gameObject.transform ); EgoEvents.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(); + if( egoComponent == null ) + { + egoComponent = transform.gameObject.AddComponent(); + } + + egoComponent.CreateMask(); + + return egoComponent; + } + public static C AddComponent( EgoComponent egoComponent ) where C : Component { C component = null;