更新Readme
和CPS验证场景
This commit is contained in:
@@ -8,6 +8,7 @@ namespace BITKit;
|
||||
/// </summary>
|
||||
public partial class CameraService:Camera3D
|
||||
{
|
||||
public static CameraService Singleton { get; private set; }
|
||||
/// <summary>
|
||||
/// 场景中所有的摄像头
|
||||
/// </summary>
|
||||
@@ -28,6 +29,12 @@ public partial class CameraService:Camera3D
|
||||
/// <param name="camera">摄像头</param>
|
||||
/// <returns></returns>
|
||||
public static bool UnRegister(IVirtualCamera camera) => _cameras.TryRemove(camera);
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理摄像头的位置
|
||||
/// </summary>
|
||||
|
@@ -39,11 +39,6 @@ public partial class FreeLookCamera : Node3D,IVirtualCamera
|
||||
eulur = Rotation;
|
||||
position = Position;
|
||||
CameraService.Register(this);
|
||||
|
||||
if(PathHelper.TryGetText(GetInstanceId().ToString(),out var json))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
@@ -39,4 +39,9 @@ public partial class GodotEntitiesService : Node,IEntitiesService
|
||||
}
|
||||
|
||||
public CancellationToken CancellationToken => _cancellationTokenSource.Token;
|
||||
|
||||
public IEntity[] Query<T>() where T : IEntityComponent
|
||||
{
|
||||
return _entities.Values.Where(x => x.TryGetComponent<T>(out _)).ToArray();
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@ namespace BITKit;
|
||||
/// </summary>
|
||||
public partial class SCADAService : Node
|
||||
{
|
||||
public const string _CurrentAngle="CurrentAngle";
|
||||
public const string _CurrentRotation="CurrentRotation";
|
||||
/// <summary>
|
||||
/// 在构造函数中注入依赖
|
||||
/// </summary>
|
||||
@@ -182,10 +184,10 @@ public partial class SCADAService : Node
|
||||
//最终角度 = 当前角度*角度权重 + 角度偏移 + 原始角度
|
||||
var euler = currentAngle * rotationComponent.Weight + rotationComponent.Offset + rotationComponent.OriginalEuler;
|
||||
//为Node3D.Rotation提交最后的角度计算结果
|
||||
rotationComponent.Rotation = Quaternion.FromEuler(euler).GetEuler().Normalized();
|
||||
rotationComponent.RotationDegrees = euler;
|
||||
|
||||
rotationComponent.SetMeta("CurrentAngle",currentAngle);
|
||||
rotationComponent.SetMeta("CurrentRotation",euler);
|
||||
rotationComponent.SetMeta(_CurrentAngle,(int)currentAngle);
|
||||
rotationComponent.SetMeta(_CurrentRotation,euler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
53
Artists/Scripts/UX/UXMetaElement.cs
Normal file
53
Artists/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);
|
||||
}
|
||||
}
|
61
Artists/Scripts/UX/UXMetaService.cs
Normal file
61
Artists/Scripts/UX/UXMetaService.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit;
|
||||
|
||||
public interface IMetaDisplayElement
|
||||
{
|
||||
string Text { get; }
|
||||
Vector3 Position { get; }
|
||||
}
|
||||
public partial class UXMetaService : Control
|
||||
{
|
||||
#region 静态方法
|
||||
private static readonly Queue<IMetaDisplayElement> AddQueue = new();
|
||||
private static readonly Queue<IMetaDisplayElement> RemoveQueue = new();
|
||||
private static readonly List<IMetaDisplayElement> Elements = new();
|
||||
public static void Register(IMetaDisplayElement element) => AddQueue.Enqueue(element);
|
||||
public static void UnRegister(IMetaDisplayElement element) => RemoveQueue.Enqueue(element);
|
||||
#endregion
|
||||
#region 实例方法
|
||||
private readonly Dictionary<IMetaDisplayElement, Label> _dictionary = new();
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 标签预制体
|
||||
/// </summary>
|
||||
[Export]
|
||||
private PackedScene labelTemplate;
|
||||
/// <summary>
|
||||
/// 主要处理过程
|
||||
/// </summary>
|
||||
/// <param name="delta"></param>
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
//相机服务未初始化时返回
|
||||
if(CameraService.Singleton is null)return;
|
||||
//处理添加队列
|
||||
while (AddQueue.TryDequeue(out var newElement))
|
||||
{
|
||||
if (!Elements.TryAdd(newElement)) continue;
|
||||
var instance = labelTemplate.Instantiate<Label>();
|
||||
_dictionary.Add(newElement,instance);
|
||||
AddChild(instance);
|
||||
}
|
||||
//处理每个Element的数据
|
||||
foreach (var element in Elements)
|
||||
{
|
||||
if (_dictionary.TryGetValue(element, out var label) is false) continue;
|
||||
var pos = CameraService.Singleton.UnprojectPosition(element.Position);
|
||||
label.Position = pos;
|
||||
label.Text = element.Text;
|
||||
}
|
||||
//处理移除队列
|
||||
while (RemoveQueue.TryDequeue(out var removeElement))
|
||||
{
|
||||
if (!_dictionary.TryGetValue(removeElement, out var label)) continue;
|
||||
if (!_dictionary.TryRemove(removeElement)) continue;
|
||||
Elements.Remove(removeElement);
|
||||
label.QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user