Files
GhostEngine/Ghost.Entities/Template/QueryItem.cs
Misaki 1724072f7e Add component editors and UI controls
Added the `HierarchyEditor` and `LocalToWorldEditor` classes to implement custom component editing functionality.
Added the `Vector3Field` control for 3D vector manipulation and its corresponding XAML definition.
Added the `ComponentDataView` and `ComponentObject` classes to manage component data display and access.
Added the `CustomEditorAttribute` to mark classes as custom editors for specific components.

Changed the `IInspectable` interface to use properties for `Icon`, `HeaderContent`, and `InspectorContent`.
Changed the `PropertyField` class to enhance UI control binding capabilities.
Changed the `EditorWorldManager` to improve world data loading and deserialization processes.
Changed the `EntityNode` and `WorldNode` classes to update entity construction and component querying.
Changed the `StaticResource` class to include new binding flags for component properties.
Changed the `InspectorService` to remove old contract references and adopt new interfaces.
Changed the `QueryEnumerable` and related files to update generic constraints for improved type safety.
Changed the `QueryItem` class to reflect new generic constraints and enhance deconstruction.
Changed the `World.Query` methods to utilize the updated generic constraints.

Updated the `SerializationTest` to align with new entity creation and management practices.
2025-06-20 20:19:14 +09:00

284 lines
12 KiB
C#

using Ghost.Entities.Components;
using Ghost.Entities.Query;
namespace Ghost.Entities;
public readonly struct QueryItem<T0>
where T0 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
internal QueryItem(Entity entity, ComponentPool<T0> pool0)
{
_entity = entity;
_pool0 = pool0;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3, T4>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
private readonly ComponentPool<T4> _pool4;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3, T4, T5>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
private readonly ComponentPool<T4> _pool4;
private readonly ComponentPool<T5> _pool5;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
private readonly ComponentPool<T4> _pool4;
private readonly ComponentPool<T5> _pool5;
private readonly ComponentPool<T6> _pool6;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
_pool6 = pool6;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
public ref T6 Component6 => ref _pool6.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6, T7>
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData where T7 : unmanaged, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
private readonly ComponentPool<T4> _pool4;
private readonly ComponentPool<T5> _pool5;
private readonly ComponentPool<T6> _pool6;
private readonly ComponentPool<T7> _pool7;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, ComponentPool<T7> pool7)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
_pool6 = pool6;
_pool7 = pool7;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
public ref T6 Component6 => ref _pool6.GetRef(_entity);
public ref T7 Component7 => ref _pool7.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6, out Ref<T7> c7)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));c7 = new (ref _pool7.GetRef(_entity));
}
}