rj-action-library/Runtime/Godot/Unique.cs

37 lines
621 B
C#
Raw Normal View History

2024-05-04 08:26:16 +00:00
using System.Collections;
using System.Collections.Generic;
using Godot;
namespace Rokojori
{
public class Unique<N> where N:Node
{
private static N _singleton;
2024-07-26 09:26:24 +00:00
public static N Get( Node n = null )
2024-05-04 08:26:16 +00:00
{
if ( _singleton != null )
{
return _singleton;
}
2024-07-26 09:26:24 +00:00
var rootWindow = n == null ? Root.Window() : n.Owner;
2024-08-04 09:08:12 +00:00
// RJLog.Log( "ROOT", rootWindow );
2024-07-26 09:26:24 +00:00
if ( rootWindow == null )
{
return null;
}
_singleton = Nodes.GetAnyChild<N>( rootWindow );
2024-08-04 09:08:12 +00:00
// RJLog.Log( "_singleton", _singleton );
2024-05-04 08:26:16 +00:00
return _singleton;
}
2024-07-26 09:26:24 +00:00
2024-05-04 08:26:16 +00:00
}
}