diff --git a/Artists/Scripts/Camera/CameraService.cs b/Artists/Scripts/Camera/CameraService.cs index d16c42e..8c3d107 100644 --- a/Artists/Scripts/Camera/CameraService.cs +++ b/Artists/Scripts/Camera/CameraService.cs @@ -8,6 +8,7 @@ namespace BITKit; /// public partial class CameraService:Camera3D { + public static CameraService Singleton { get; private set; } /// /// 场景中所有的摄像头 /// @@ -28,6 +29,12 @@ public partial class CameraService:Camera3D /// 摄像头 /// public static bool UnRegister(IVirtualCamera camera) => _cameras.TryRemove(camera); + + public override void _Ready() + { + Singleton = this; + } + /// /// 处理摄像头的位置 /// diff --git a/Artists/Scripts/Camera/FreeLookCamera.cs b/Artists/Scripts/Camera/FreeLookCamera.cs index 062fe81..2e9ea50 100644 --- a/Artists/Scripts/Camera/FreeLookCamera.cs +++ b/Artists/Scripts/Camera/FreeLookCamera.cs @@ -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) diff --git a/Artists/Scripts/ECS/GodotEntitiesService.cs b/Artists/Scripts/ECS/GodotEntitiesService.cs index 3875542..63bad7b 100644 --- a/Artists/Scripts/ECS/GodotEntitiesService.cs +++ b/Artists/Scripts/ECS/GodotEntitiesService.cs @@ -39,4 +39,9 @@ public partial class GodotEntitiesService : Node,IEntitiesService } public CancellationToken CancellationToken => _cancellationTokenSource.Token; + + public IEntity[] Query() where T : IEntityComponent + { + return _entities.Values.Where(x => x.TryGetComponent(out _)).ToArray(); + } } diff --git a/Artists/Scripts/Factory/SCADAService.cs b/Artists/Scripts/Factory/SCADAService.cs index 169a56c..494434d 100644 --- a/Artists/Scripts/Factory/SCADAService.cs +++ b/Artists/Scripts/Factory/SCADAService.cs @@ -16,6 +16,8 @@ namespace BITKit; /// public partial class SCADAService : Node { + public const string _CurrentAngle="CurrentAngle"; + public const string _CurrentRotation="CurrentRotation"; /// /// 在构造函数中注入依赖 /// @@ -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); } } } diff --git a/Artists/Scripts/UX/UXMetaElement.cs b/Artists/Scripts/UX/UXMetaElement.cs new file mode 100644 index 0000000..7765a26 --- /dev/null +++ b/Artists/Scripts/UX/UXMetaElement.cs @@ -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(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); + } +} \ No newline at end of file diff --git a/Artists/Scripts/UX/UXMetaService.cs b/Artists/Scripts/UX/UXMetaService.cs new file mode 100644 index 0000000..4eea496 --- /dev/null +++ b/Artists/Scripts/UX/UXMetaService.cs @@ -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 AddQueue = new(); + private static readonly Queue RemoveQueue = new(); + private static readonly List 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 _dictionary = new(); + #endregion + /// + /// 标签预制体 + /// + [Export] + private PackedScene labelTemplate; + /// + /// 主要处理过程 + /// + /// + 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