Merge pull request #42588 from aaronfranke/cs-instance-generic
Add generic support to PackedScene.Instance in C#
This commit is contained in:
commit
ffc7d0a2d6
2 changed files with 28 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
||||||
|
namespace Godot
|
||||||
|
{
|
||||||
|
public partial class PackedScene
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates the scene's node hierarchy, erroring on failure.
|
||||||
|
/// Triggers child scene instantiation(s). Triggers a
|
||||||
|
/// `Node.NotificationInstanced` notification on the root node.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type to cast to. Should be a descendant of Node.</typeparam>
|
||||||
|
public T Instance<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class
|
||||||
|
{
|
||||||
|
return (T)(object)Instance(editState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates the scene's node hierarchy, returning null on failure.
|
||||||
|
/// Triggers child scene instantiation(s). Triggers a
|
||||||
|
/// `Node.NotificationInstanced` notification on the root node.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type to cast to. Should be a descendant of Node.</typeparam>
|
||||||
|
public T InstanceOrNull<T>(PackedScene.GenEditState editState = (PackedScene.GenEditState)0) where T : class
|
||||||
|
{
|
||||||
|
return Instance(editState) as T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -30,6 +30,7 @@
|
||||||
<Compile Include="Core\DynamicObject.cs" />
|
<Compile Include="Core\DynamicObject.cs" />
|
||||||
<Compile Include="Core\Extensions\NodeExtensions.cs" />
|
<Compile Include="Core\Extensions\NodeExtensions.cs" />
|
||||||
<Compile Include="Core\Extensions\ObjectExtensions.cs" />
|
<Compile Include="Core\Extensions\ObjectExtensions.cs" />
|
||||||
|
<Compile Include="Core\Extensions\PackedSceneExtensions.cs" />
|
||||||
<Compile Include="Core\Extensions\ResourceLoaderExtensions.cs" />
|
<Compile Include="Core\Extensions\ResourceLoaderExtensions.cs" />
|
||||||
<Compile Include="Core\Extensions\SceneTreeExtensions.cs" />
|
<Compile Include="Core\Extensions\SceneTreeExtensions.cs" />
|
||||||
<Compile Include="Core\GD.cs" />
|
<Compile Include="Core\GD.cs" />
|
||||||
|
|
Loading…
Reference in a new issue