添加了标识更新
但是只有界面没有功能
This commit is contained in:
59
BITKit/Scripts/Builder/NodeBuilder.cs
Normal file
59
BITKit/Scripts/Builder/NodeBuilder.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Godot;
|
||||
using System;
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
namespace BITKit;
|
||||
public partial class NodeBuilder : Node
|
||||
{
|
||||
[Export] private bool clearOnStart = true;
|
||||
[Export] private bool clearTemplateOnly = true;
|
||||
[Export] private Control container;
|
||||
[ExportCategory("UX")]
|
||||
[Export] private Control emptyHints;
|
||||
[ExportCategory("Template")]
|
||||
[Export] private PackedScene template;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (clearOnStart)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public Node Build()
|
||||
{
|
||||
var instance = template.Instantiate();
|
||||
if (container is not null)
|
||||
{
|
||||
container.AddChild(instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddChild(instance);
|
||||
}
|
||||
emptyHints?.Hide();
|
||||
return instance;
|
||||
}
|
||||
public T Build<T>() where T : Node
|
||||
{
|
||||
var instance = Build() as T;
|
||||
return instance;
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
emptyHints?.Show();
|
||||
if (clearTemplateOnly)
|
||||
{
|
||||
foreach (var x in container is not null ? container.GetChildren() : GetChildren())
|
||||
{
|
||||
if(x.SceneFilePath == template.ResourcePath)
|
||||
x.QueueFree();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MathNode.ClearChild(container is not null ? container:this);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user