@@ -34,6 +34,16 @@ public class Entity
3434 /// </summary>
3535 public List < Component . Component > Components { get ; } = [ ] ;
3636
37+ /// <summary>
38+ /// Get All Children of Entity
39+ /// </summary>
40+ public List < Entity > Children { get ; } = [ ] ;
41+
42+ /// <summary>
43+ /// Parent of Entity
44+ /// </summary>
45+ public Entity ? Parent { get ; set ; }
46+
3747 /// <summary>
3848 /// Get All Components of one Type
3949 /// </summary>
@@ -58,6 +68,21 @@ public List<T> GetComponentsAs<T>()
5868 public T ? GetSceneAs < T > ( )
5969 where T : Scene => ( T ? ) Scene ;
6070
71+ /// <summary>
72+ /// Add Child Entity
73+ /// </summary>
74+ /// <typeparam name="T"></typeparam>
75+ /// <param name="entity"></param>
76+ /// <returns></returns>
77+ public T AddChild < T > ( T entity )
78+ where T : Entity
79+ {
80+ Children . Add ( entity ) ;
81+ entity . Parent = this ;
82+ entity . Scene = Scene ;
83+ return entity ;
84+ }
85+
6186 /// <summary>
6287 /// Add Component and return it
6388 /// </summary>
@@ -72,6 +97,17 @@ public T AddComponent<T>(T component)
7297 return component ;
7398 }
7499
100+ /// <summary>
101+ /// Remove Child
102+ /// </summary>
103+ /// <param name="entity">Child</param>
104+ public void RemoveChild ( Entity entity )
105+ {
106+ entity . Parent = null ;
107+ entity . Scene = null ;
108+ Children . Remove ( entity ) ;
109+ }
110+
75111 /// <summary>
76112 /// Remove Component
77113 /// </summary>
@@ -89,6 +125,9 @@ public virtual void Load()
89125 {
90126 foreach ( var component in Components )
91127 component . Load ( ) ;
128+
129+ foreach ( var child in Children )
130+ child . Load ( ) ;
92131 }
93132
94133 /// <summary>
@@ -98,6 +137,9 @@ public virtual void Unload()
98137 {
99138 foreach ( var component in Components )
100139 component . Unload ( ) ;
140+
141+ foreach ( var child in Children )
142+ child . Unload ( ) ;
101143 }
102144
103145 /// <summary>
@@ -108,6 +150,9 @@ public virtual void Update(float delta)
108150 {
109151 foreach ( var component in Components )
110152 component . Update ( delta ) ;
153+
154+ foreach ( var child in Children )
155+ child . Update ( delta ) ;
111156 }
112157
113158 /// <summary>
@@ -117,5 +162,8 @@ public virtual void Draw()
117162 {
118163 foreach ( var component in Components )
119164 component . Draw ( ) ;
165+
166+ foreach ( var child in Children )
167+ child . Draw ( ) ;
120168 }
121169}
0 commit comments