示例#1
0
 public static void ReParent(this Godot.Node child, Godot.Node newParent)
 {
     // NOTE: Currently it seems to do it so that it fires _EnterTree and _Ready again when its reparented...
     // maybe we don't want that?
     child.GetParent().RemoveChild(child);
     newParent.AddChild(child);
 }
示例#2
0
    // Ready function, called once at the beginning of the scene when all children are ready
    public override void _Ready()
    {
        // Assign the buttons' container node
        sceneButtonsContainer = GetNode("SceneControlsPanel/SceneButtonsContainer");

        // When this node is ready, immediately disable the button for the currently selected scene
        // NOTE: THE currentScene VARIABLE IS USED AS THE INDEX THAT CORRESPONDS TO THE ORDER OF THE BUTTONS AS CHILDRENS OF THE HBOXCONTAINER
        sceneButtonsContainer.GetChild <Button>(GlobalControl.currentScene).Disabled = true;
    }
示例#3
0
        public static void SetupWayfarer(this Godot.Node self)
        {
            self.SetupAttributes();

            //if (self is WayfarerNode) // we'll come back to this at some point
            {
                // further stuff that only concerns the WayfarerNodes
            }
            // what else? if nothing else, we should just directly call SetupAttributes
        }
示例#4
0
    public static T FindFirstNodeOf <T>(this Godot.Node node) where T : Godot.Node
    {
        foreach (Godot.Node child in node.GetChildren())
        {
            if (child is T)
            {
                return((T)child);
            }
        }

        return(null);
    }
示例#5
0
    public void ChangeScene(string path)
    {
        if (currentScene != null)
        {
            currentScene.QueueFree();
        }
        PackedScene scenePath = (PackedScene)ResourceLoader.Load(path);

        Godot.Node newScene = scenePath.Instance();
        currentScene = newScene;
        AddChild(newScene);
    }
示例#6
0
        public static T GetParentOfType <T>(this Godot.Node node) where T : Godot.Node
        {
            Godot.Node parentCandidate = node.GetParent();

            while (parentCandidate != null && parentCandidate != node.GetTree().GetRoot())
            {
                if (parentCandidate is T match)
                {
                    return(match as T);
                }

                parentCandidate = parentCandidate.GetParent();
            }

            return(null);
        }
示例#7
0
        public static Godot.Node[] GetChildrenRecursive(this Godot.Node parent)
        {
            List <Godot.Node> result = new List <Godot.Node>();

            foreach (Godot.Node node in parent.GetChildren())
            {
                result.Add(node);

                if (node.GetChildCount() > 0)
                {
                    foreach (Godot.Node child in GetChildrenRecursive(node))
                    {
                        result.Add(child);
                    }
                }
            }

            return(result.ToArray());
        }
示例#8
0
    public static Array <T> FindAllNodesOf <T>(this Godot.Node node) where T : Godot.Node
    {
        var matching = new Array <T>();

        foreach (Godot.Node child in node.GetChildren())
        {
            if (child is T)
            {
                matching.Add((T)child);
            }

            Array <T> kids = child.FindAllNodesOf <T>();
            foreach (T kid in kids)
            {
                matching.Add(kid);
            }
        }

        return(matching);
    }
示例#9
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);
            }
        }
    }
示例#10
0
 private void OnReefBodyEntered(Godot.Node body)
 {
     if (body.IsInGroup("commands"))
     {
     }
 }
示例#11
0
 public void OnPlayerShipBodyEntered(Godot.Node body)
 {
     this.EmitSignal("Hit");
 }
示例#12
0
 public static T GetChild <T>(this Godot.Node self, int idx) where T : Godot.Node
 {
     return(self.GetChild(idx) as T);
 }
示例#13
0
 public static T FindNode <T>(this Godot.Node self, string mask, bool recursive = true, bool owned = true) where T : Godot.Node
 {
     return(self.FindNode(mask, recursive, owned) as T);
 }
示例#14
0
 public static T GetNode <T>(this Godot.Node self, NodePath path) where T : Godot.Node
 {
     return(self.GetNode(path) as T);
 }
示例#15
0
 private static void GetAllNodes(Godot.Node parent)
 {
     // ? do we need this
 }