readme
This commit is contained in:
53
BITKit/Scripts/UX/UXMetaElement.cs
Normal file
53
BITKit/Scripts/UX/UXMetaElement.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public partial class UXMetaElement : Node3D, IMetaDisplayElement
|
||||
{
|
||||
[Export] private bool isEnabled=true;
|
||||
[Export] private Node3D proxy;
|
||||
[Export] protected string[] MetaEntries;
|
||||
private bool _registered;
|
||||
|
||||
string IMetaDisplayElement.Text
|
||||
{
|
||||
get
|
||||
{
|
||||
var node = proxy ?? this;
|
||||
return string.Join(MetaEntries?.Length>2 ? "\n" : ":", MetaEntries!
|
||||
.Where(x => string.IsNullOrEmpty(x) is false)
|
||||
.Where(x => node.HasMeta(x))
|
||||
.Select(x => node.GetMeta(x).AsString())
|
||||
.InsertOf<string>(0, node.Name)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 IMetaDisplayElement.Position => (proxy ?? this).GlobalPosition;
|
||||
// public override void _Ready()
|
||||
// {
|
||||
// if (!isEnabled) return;
|
||||
// UXMetaService.Register(this);
|
||||
// _registered = true;
|
||||
// }
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_registered == isEnabled) return;
|
||||
if (isEnabled)
|
||||
{
|
||||
UXMetaService.Register(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
UXMetaService.UnRegister(this);
|
||||
}
|
||||
_registered = isEnabled;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (isEnabled && _registered)
|
||||
UXMetaService.UnRegister(this);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user