Example #1
0
    private static bool HexIsAdjacent(GFHexGrid theGrid, Vector3 position, Vector3 reference)
    {
        bool isNeighbour = false;

        if (Mathf.Abs(reference.y - position.y) < 1.1f && Mathf.Abs(reference.x - position.x) < 0.1f)        //straight above or below
        {
            isNeighbour = true;
        }
        else
        {
            if (Mathf.RoundToInt(reference.x) % 2 == 0)            //two cases, depending on whether the x-coordinate is even or odd
            //neighbours are either strictly left or right of the switch or right/left and one unit below
            {
                if (Mathf.Abs(reference.x - position.x) < 1.1f && position.y - reference.y < 0.1f && position.y - reference.y > -1.1f)
                {
                    isNeighbour = true;
                }
            }
            else               //x-coordinate odd
                               //neighbours are either strictly left or right of the switch or right/left and one unit above
            {
                if (Mathf.Abs(reference.x - position.x) < 1.1f && reference.y - position.y < 0.1f && position.y - reference.y < 1.1f)
                {
                    isNeighbour = true;
                }
            }
        }
        return(isNeighbour);
    }
	private static bool HexIsAdjacent(GFHexGrid theGrid, Vector3 position, Vector3 reference){
		bool isNeighbour = false;
		if(Mathf.Abs(reference.y - position.y) < 1.1f && Mathf.Abs(reference.x - position.x) < 0.1f){//straight above or below
			isNeighbour = true;
		} else{
			if(Mathf.RoundToInt(reference.x) % 2 == 0){//two cases, depending on whether the x-coordinate is even or odd
				//neighbours are either strictly left or right of the switch or right/left and one unit below
				if(Mathf.Abs(reference.x - position.x) < 1.1f && position.y - reference.y < 0.1f && position.y - reference.y > -1.1f)
					isNeighbour = true;
			} else{//x-coordinate odd
				//neighbours are either strictly left or right of the switch or right/left and one unit above
				if(Mathf.Abs(reference.x - position.x) < 1.1f && reference.y - position.y < 0.1f && position.y - reference.y < 1.1f)
					isNeighbour = true;
			}
		}
		return isNeighbour;
	}
Example #3
0
 void OnEnable()
 {
     hg = target as GFHexGrid;
     showDrawSettings = EditorPrefs.HasKey("GFHexGridShowDraw") ? EditorPrefs.GetBool("GFHexGridShowDraw") : true;
 }
 void OnEnable()
 {
     hg = target as GFHexGrid;
     showDrawSettings = EditorPrefs.HasKey("GFHexGridShowDraw") ? EditorPrefs.GetBool("GFHexGridShowDraw") : true;
 }