Skip to content

Instantly share code, notes, and snippets.

@arun02139
Last active March 15, 2017 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun02139/2f178c934bc80642496bc1c6e1d81beb to your computer and use it in GitHub Desktop.
Save arun02139/2f178c934bc80642496bc1c6e1d81beb to your computer and use it in GitHub Desktop.
This struct is losing it's values; it should be serialized (private member marked [Serializable] in MyHexagon.cs)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// NOTE: this struct is assumed to be column ordered, i.e. compatable with even-q and odd-q offset coordinate layouts
public struct OffsetCoordinate
{
public int col { get { return _col; } }
public int row { get { return _row; } }
int _col;
int _row;
public OffsetCoordinate(int c, int r)
{
_col = c;
_row = r;
}
public static OffsetCoordinate operator +(OffsetCoordinate a, OffsetCoordinate b)
{
return new OffsetCoordinate(a.col + b.col, a.row + b.row);
}
public static bool operator ==(OffsetCoordinate a, OffsetCoordinate b)
{
return a.Equals(b);
}
public static bool operator !=(OffsetCoordinate a, OffsetCoordinate b)
{
return !a.Equals(b);
}
// LINK: http://stackoverflow.com/questions/2542693/overriding-equals-method-in-structs
public override bool Equals(object obj)
{
if (!(obj is OffsetCoordinate))
return false;
OffsetCoordinate c = (OffsetCoordinate) obj;
return col == c.col && row == c.row;
}
public override int GetHashCode()
{
return col ^ row;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment