Last active
March 15, 2017 23:23
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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