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

55 lines
862 B
C#
Raw Normal View History

2024-05-04 08:26:16 +00:00
using Godot;
using System.Text;
using System.Collections.Generic;
namespace Rokojori
{
public class HierarchyName
{
2025-01-03 12:09:23 +00:00
public static string Of( Node node, string seperator = " ▸ " )
2024-05-04 08:26:16 +00:00
{
if ( node == null )
{
return "null";
}
var list = new List<string>();
var it = node;
while ( it != null )
{
2025-01-03 12:09:23 +00:00
var n = it.Name;
if ( RegexUtility.Matching( n, @"@\d+$" ) )
{
it = null;
}
else
{
list.Add( it.Name );
it = it.GetParent();
}
2024-05-04 08:26:16 +00:00
}
list.Reverse();
var sb = new StringBuilder();
for ( int i = 0; i < list.Count; i++)
{
if ( i != 0 )
{
sb.Append( seperator );
}
sb.Append( list[ i ] );
}
return sb.ToString();
}
}
}