private static void GetHeightLevels(SimpleSlopeDirection simpleSlopeDirection, SlopeData slopeData, out int bottomLevel, out int upperLevel) { switch (simpleSlopeDirection) { case SimpleSlopeDirection.UNDEFINED: bottomLevel = 0; upperLevel = 0; Debug.LogError("The simple slope direction is undefined. You may want to use the double slope directions instead"); break; case SimpleSlopeDirection.LEFT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_1r); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_4l); break; case SimpleSlopeDirection.TOP_LEFT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_2dr); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_5tl); break; case SimpleSlopeDirection.TOP_RIGHT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_3dl); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_0tr); break; case SimpleSlopeDirection.RIGHT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_4l); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_1r); break; case SimpleSlopeDirection.DOWN_RIGHT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_5tl); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_2dr); break; case SimpleSlopeDirection.DOWN_LEFT: bottomLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_0tr); upperLevel = GeographicTile.GetValueOfHeight(slopeData.heightSide_3dl); break; default: bottomLevel = 0; upperLevel = 0; Debug.LogError("The simple slope direction is undefined. You may want to use the double slope directions instead"); break; } }
private static float GetInterpolationValue(SimpleSlopeDirection simpleSlopeDirection, FractionalHex positionRelativeToHex) { float lerpValue; switch (simpleSlopeDirection) { case SimpleSlopeDirection.UNDEFINED: lerpValue = 0; Debug.LogError("The simple slope direction is undefined. You may want to use the double slope directions instead"); break; case SimpleSlopeDirection.LEFT: lerpValue = (float)(-positionRelativeToHex.q + positionRelativeToHex.s); break; case SimpleSlopeDirection.TOP_LEFT: lerpValue = (float)(-positionRelativeToHex.q + positionRelativeToHex.r); break; case SimpleSlopeDirection.TOP_RIGHT: lerpValue = (float)(positionRelativeToHex.r - positionRelativeToHex.s); break; case SimpleSlopeDirection.RIGHT: lerpValue = (float)(positionRelativeToHex.q - positionRelativeToHex.s); break; case SimpleSlopeDirection.DOWN_RIGHT: lerpValue = (float)(positionRelativeToHex.q - positionRelativeToHex.r); break; case SimpleSlopeDirection.DOWN_LEFT: lerpValue = (float)(-positionRelativeToHex.r + positionRelativeToHex.s); break; default: lerpValue = 0; Debug.LogError("The simple slope direction is undefined. You may want to use the double slope directions instead"); break; } lerpValue = Mathf.Clamp01(lerpValue); return(lerpValue); }
private static void GetTheDirectionAndTypeOfSlope(SlopeData slopeData, out bool isSimpleSlope, out SimpleSlopeDirection simpleSlopeDirection, out DoubleSlopeDirection doubleSlopeDirection) { doubleSlopeDirection = DoubleSlopeDirection.UDEFINDED; simpleSlopeDirection = SimpleSlopeDirection.UNDEFINED; var topRight_h = slopeData.heightSide_0tr; var right_h = slopeData.heightSide_1r; var downRight_h = slopeData.heightSide_2dr; var downLeft_h = slopeData.heightSide_3dl; var left_h = slopeData.heightSide_4l; var topLeft_h = slopeData.heightSide_5tl; bool simple_TopRight = topRight_h != right_h && topRight_h != left_h && left_h == downRight_h && left_h == downLeft_h && right_h == topLeft_h; bool simple_Right = right_h != topRight_h && right_h != left_h && left_h == downLeft_h && left_h == topLeft_h && topRight_h == downRight_h; bool simple_DownRight = downRight_h != right_h && downRight_h != left_h && left_h == topRight_h && left_h == topLeft_h && right_h == downLeft_h; bool simple_DownLeft = downLeft_h != left_h && downLeft_h != right_h && right_h == topRight_h && right_h == topLeft_h && left_h == downRight_h; bool simple_Left = left_h != downLeft_h && left_h != right_h && right_h == topRight_h && right_h == downRight_h && downLeft_h == topLeft_h; bool simple_TopLeft = topLeft_h != left_h && topLeft_h != right_h && right_h == downLeft_h && right_h == downRight_h && left_h == topRight_h; bool double_TopRight = topRight_h == right_h && right_h != downRight_h && right_h != left_h && left_h == downLeft_h && downRight_h == topLeft_h; bool double_DownRight = right_h == downRight_h && right_h != downLeft_h && right_h != left_h && left_h == topLeft_h && downLeft_h == topRight_h; bool double_Down = downRight_h == downLeft_h && downRight_h != right_h && downRight_h != topLeft_h && right_h == left_h && topLeft_h == topRight_h; bool double_DownLeft = downLeft_h == left_h && downLeft_h != downRight_h && downLeft_h != right_h && right_h == topRight_h && downRight_h == topLeft_h; bool double_TopLeft = left_h == topLeft_h && left_h != downLeft_h && left_h != right_h && right_h == downRight_h && downLeft_h == topRight_h; bool double_Top = topLeft_h == topRight_h && topLeft_h != right_h && topLeft_h != downLeft_h && downLeft_h == downRight_h && right_h == left_h; if (simple_TopRight) { simpleSlopeDirection = SimpleSlopeDirection.TOP_RIGHT; isSimpleSlope = true; return; } else if (simple_Right) { simpleSlopeDirection = SimpleSlopeDirection.RIGHT; isSimpleSlope = true; return; } else if (simple_DownRight) { simpleSlopeDirection = SimpleSlopeDirection.DOWN_RIGHT; isSimpleSlope = true; return; } else if (simple_DownLeft) { simpleSlopeDirection = SimpleSlopeDirection.DOWN_LEFT; isSimpleSlope = true; return; } else if (simple_Left) { simpleSlopeDirection = SimpleSlopeDirection.LEFT; isSimpleSlope = true; return; } else if (simple_TopLeft) { simpleSlopeDirection = SimpleSlopeDirection.TOP_LEFT; isSimpleSlope = true; return; } else if (double_TopRight) { doubleSlopeDirection = DoubleSlopeDirection.TOP_RIGHT; isSimpleSlope = false; return; } else if (double_DownRight) { doubleSlopeDirection = DoubleSlopeDirection.DOWN_RIGHT; isSimpleSlope = false; return; } else if (double_Down) { doubleSlopeDirection = DoubleSlopeDirection.DOWN; isSimpleSlope = false; return; } else if (double_DownLeft) { doubleSlopeDirection = DoubleSlopeDirection.DOWN_LEFT; isSimpleSlope = false; return; } else if (double_TopLeft) { doubleSlopeDirection = DoubleSlopeDirection.TOP_LEFT; isSimpleSlope = false; return; } else if (double_Top) { doubleSlopeDirection = DoubleSlopeDirection.TOP; isSimpleSlope = false; return; } else { throw new System.Exception($"The slope tile doest't have a valid format! it's values are; \n" + $"Top right:{ topRight_h}\nRight:{right_h}\nDown right:{downRight_h}\nDown left:{downLeft_h}\nLeft:{left_h}\nTop left:{topLeft_h}"); } }