-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.cs
28 lines (23 loc) · 1.01 KB
/
Entity.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
namespace MelonECS
{
public readonly struct Entity : IEquatable<Entity>
{
public readonly int Index;
public readonly int Generation;
public readonly World World;
public Entity(World world, int index, int generation)
{
Index = index;
Generation = generation;
World = world;
}
public override bool Equals(object obj) => obj is Entity entity && Equals(entity);
public bool Equals(Entity other) => Index == other.Index && Generation == other.Generation && World == other.World;
public override int GetHashCode() => Index * 31 + Generation;
public static bool operator ==(Entity a, Entity b) => a.Index == b.Index && a.Generation == b.Generation;
public static bool operator !=(Entity a, Entity b) => a.Index != b.Index || a.Generation != b.Generation;
public override string ToString() => $"Entity[{Index}|{Generation}]";
public static Entity Invalid => default;
}
}