1+ using System ;
12using System . Diagnostics . CodeAnalysis ;
23using Ceres . Annotations ;
34using Ceres . Graph . Flow . Annotations ;
45using Chris . Serialization ;
56using UnityEngine ;
7+ using Random = UnityEngine . Random ;
68using UObject = UnityEngine . Object ;
79
810namespace Ceres . Graph . Flow . Utilities
@@ -100,6 +102,12 @@ public static GameObject Flow_FindGameObjectWithTag(string tag)
100102 return GameObject . FindWithTag ( tag ) ;
101103 }
102104
105+ /// <summary>
106+ /// Retrieves a reference to a component of specified type, by providing the component type as a method parameter.
107+ /// </summary>
108+ /// <param name="gameObject"></param>
109+ /// <param name="type"></param>
110+ /// <returns></returns>
103111 [ ExecutableFunction ( IsScriptMethod = true , IsSelfTarget = true ) , CeresLabel ( "GetComponent" ) ]
104112 public static Component Flow_GameObjectGetComponent ( GameObject gameObject ,
105113 [ ResolveReturn ] SerializedType < Component > type )
@@ -113,6 +121,31 @@ public static Component Flow_GameObjectGetComponentInChildren(GameObject gameObj
113121 {
114122 return gameObject . GetComponentInChildren ( type ) ;
115123 }
124+
125+ /// <summary>
126+ /// Adds a component of the specified type to the GameObject.
127+ /// </summary>
128+ /// <param name="gameObject"></param>
129+ /// <param name="type"></param>
130+ /// <returns></returns>
131+ [ ExecutableFunction ( IsScriptMethod = true , IsSelfTarget = true ) , CeresLabel ( "AddComponent" ) ]
132+ public static Component Flow_GameObjectAddComponent ( GameObject gameObject ,
133+ [ ResolveReturn ] SerializedType < Component > type )
134+ {
135+ return gameObject . AddComponent ( type ) ;
136+ }
137+
138+ [ ExecutableFunction ( IsScriptMethod = true , IsSelfTarget = true ) , CeresLabel ( "GetOrAddComponent" ) ]
139+ public static Component Flow_GameObjectGetOrAddComponent ( GameObject gameObject ,
140+ [ ResolveReturn ] SerializedType < Component > type )
141+ {
142+ Type t = type ;
143+ if ( gameObject . TryGetComponent ( t , out Component component ) )
144+ {
145+ return component ;
146+ }
147+ return gameObject . AddComponent ( type ) ;
148+ }
116149
117150 #endregion GameObject
118151
0 commit comments