Here is my test code (Contains is not returning true when it should be):
HashSet<TilePosition> test = new HashSet<TilePosition>(new TilePositionCompare());
test.Add(new TilePosition(10,10));
if (test.Contains(new TilePosition(10,10)))
Debug.Log("We should see this");
My Compare Class: using System.Collections.Generic;
public class TilePositionCompare : IEqualityComparer<TilePosition>
{
public bool Equals(TilePosition tileA, TilePosition tileB)
{
return tileA.PosX == tileB.PosX && tileA.PosY == tileB.PosY;
}
public int GetHashCode(TilePosition tile)
{
return tile.GetHashCode();
}
}
Here is the class I want to compare:
using System.Collections;
public class TilePosition
{
int posX;
int posY;
public TilePosition (int posX, int posY)
{
this.posX = posX;
this.posY = posY;
}
}
I'm not sure where I am going wrong. I've followed some tutorials that appear to do the same thing.