46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
|
|
namespace OECS;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Describes a single change that occurred in the ECS world.
|
||
|
|
/// </summary>
|
||
|
|
public readonly struct EntityChange : IEquatable<EntityChange>
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// The entity that was affected.
|
||
|
|
/// </summary>
|
||
|
|
public Entity Entity { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// The kind of change.
|
||
|
|
/// </summary>
|
||
|
|
public ChangeKind Kind { get; }
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// The component type involved, or null for entity-level changes
|
||
|
|
/// (<see cref="ChangeKind.EntityAdded"/> / <see cref="ChangeKind.EntityRemoved"/>).
|
||
|
|
/// </summary>
|
||
|
|
public Type? ComponentType { get; }
|
||
|
|
|
||
|
|
internal EntityChange(Entity entity, ChangeKind kind, Type? componentType = null)
|
||
|
|
{
|
||
|
|
Entity = entity;
|
||
|
|
Kind = kind;
|
||
|
|
ComponentType = componentType;
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool Equals(EntityChange other)
|
||
|
|
{
|
||
|
|
return Entity.Equals(other.Entity)
|
||
|
|
&& Kind == other.Kind
|
||
|
|
&& ComponentType == other.ComponentType;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override bool Equals(object? obj) => obj is EntityChange other && Equals(other);
|
||
|
|
|
||
|
|
public override int GetHashCode() => HashCode.Combine(Entity, Kind, ComponentType);
|
||
|
|
|
||
|
|
public override string ToString() => ComponentType == null
|
||
|
|
? $"{Kind} {Entity}"
|
||
|
|
: $"{Kind} {ComponentType.Name} on {Entity}";
|
||
|
|
}
|