Exemplo n.º 1
0
    public static void FindSubnodes(this Godot.Node node)
    {
        foreach (PropertyInfo prop in node.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
        {
            SubnodeAttribute Subnode = (SubnodeAttribute)Attribute.GetCustomAttribute(prop, typeof(SubnodeAttribute));
            if (Subnode != null)
            {
                string nodePath = Subnode.NodePath == null ? prop.Name : Subnode.NodePath;
                var    subnode  = node.GetNode(nodePath);
                prop.SetValue(node, subnode);
            }
        }

        foreach (FieldInfo field in node.GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
        {
            SubnodeAttribute Subnode = (SubnodeAttribute)Attribute.GetCustomAttribute(field, typeof(SubnodeAttribute));
            if (Subnode != null)
            {
                string nodePath = Subnode.NodePath == null ? field.Name : Subnode.NodePath;
                var    subnode  = node.GetNode(nodePath);
                field.SetValue(node, subnode);
            }
        }
    }
Exemplo n.º 2
0
 public static T GetNode <T>(this Godot.Node self, NodePath path) where T : Godot.Node
 {
     return(self.GetNode(path) as T);
 }