Two small extension classes for Sandbox game objects. Directory_Extensions adds FindbyName to search a GameObjectDirectory for an exact-name GameObject. GameObject_Extensions adds GetChild to return a direct child GameObject by name.
using Sandbox;
public static class Directory_Extensions
{
public static GameObject FindbyName(this GameObjectDirectory d, string n)
{
foreach (var go in d.FindByName(n))
{
if (go.Name == n)
return go;
}
return null;
}
}
public static class GameObject_Extensions
{
public static GameObject GetChild (this GameObject go, string n)
{
foreach (var c in go.Children)
{
if (c.Name == n)
return c;
}
return null;
}
}