2026-07-18 19:42:59 +08:00
|
|
|
using MessagePack;
|
|
|
|
|
|
|
|
|
|
namespace OECS;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A convenience base struct for relationship components.
|
|
|
|
|
///
|
|
|
|
|
/// The type parameters <typeparamref name="TSelf"/> and <typeparamref name="TTarget"/>
|
|
|
|
|
/// are phantom types that differentiate relationship kinds at the type level,
|
|
|
|
|
/// enabling type-safe queries and reverse lookups.
|
|
|
|
|
///
|
|
|
|
|
/// <example>
|
|
|
|
|
/// <code>
|
|
|
|
|
/// // Define a "ChildOf" relationship between a child and a parent entity.
|
|
|
|
|
/// world.AddComponent(child, new Relationship<ChildOf, Parent>
|
|
|
|
|
/// {
|
|
|
|
|
/// Target = parent
|
|
|
|
|
/// });
|
|
|
|
|
///
|
|
|
|
|
/// // Later, find all children of a parent.
|
|
|
|
|
/// var children = world.GetSources<Relationship<ChildOf, Parent>>(parent);
|
|
|
|
|
/// </code>
|
|
|
|
|
/// </example>
|
|
|
|
|
/// </summary>
|
|
|
|
|
[MessagePackObject]
|
|
|
|
|
public struct Relationship<TSelf, TTarget> : IRelationship
|
2026-07-18 22:05:29 +08:00
|
|
|
where TSelf : struct where TTarget : struct
|
2026-07-18 19:42:59 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The entity that this relationship points to.
|
|
|
|
|
/// </summary>
|
2026-07-20 22:59:27 +08:00
|
|
|
[Key(0)]
|
2026-07-18 19:42:59 +08:00
|
|
|
public Entity Target { get; set; }
|
|
|
|
|
}
|