added base helpers and a simple test.
This commit is contained in:
46
GodotHelper/src/MyNodeExtensions.cs
Normal file
46
GodotHelper/src/MyNodeExtensions.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace GodotHelpers;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
|
||||
public static class MyNodeExtensions
|
||||
{
|
||||
public static void FreeDeferred(this Node node) => node.CallDeferred(GodotObject.MethodName.Free);
|
||||
/// <summary>
|
||||
/// Checks if given Property exists on <c>Base</c>
|
||||
/// </summary>
|
||||
/// <param name="Base">Current <c>GodotObject</c></param>
|
||||
/// <param name="PropertyName">Property Name</param>
|
||||
/// <returns><c>bool</c> true if given property exists on Base</returns>
|
||||
public static bool HasProperty(this GodotObject Base, string PropertyName)
|
||||
{
|
||||
/*
|
||||
Returns the object's property list as an Godot.Collections.Array of dictionaries.
|
||||
Each Godot.Collections.Dictionary contains the following entries:
|
||||
- name is the property's name, as a string;
|
||||
- class_name is an empty StringName, unless the property is Variant.Type.Object and it inherits from a class;
|
||||
- type is the property's type, as an int (see Variant.Type);
|
||||
- hint is how the property is meant to be edited (see PropertyHint);
|
||||
- hint_string depends on the hint (see PropertyHint);
|
||||
- usage is a combination of PropertyUsageFlags.
|
||||
*/
|
||||
foreach (var Property in Base.GetPropertyListEx())
|
||||
{
|
||||
if (Property.Name == PropertyName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public static (Node node, Resource resource, NodePath remaining) GetNodeAndResourceEx(this Node self, NodePath path)
|
||||
{
|
||||
var result = self.GetNodeAndResource(path);
|
||||
return ((Node)result[0], (Resource)result[1], (NodePath)result[2]);
|
||||
}
|
||||
public static void QueueFreeChildren(this Node node) => node.GetChildren().ToList().ForEach(item => item.QueueFree());
|
||||
public static void QueueFreeChildren(this Node node, Func<Node, bool> predicate) => node.GetChildren().Where(predicate).ToList().ForEach(item => item.QueueFree());
|
||||
}
|
||||
Reference in New Issue
Block a user