Exemple #1
0
        /// <summary>
        /// Manually calculate cell center. This allows for multithreading.
        /// This should do the same as Grid.GetCellCenter.
        /// </summary>
        /// <param name="inCoordinate">Coordinate to get center for.</param>
        /// <returns>3D position of the center of the cell.</returns>
        public Vector3 GetCenterOfCell(Vector3Int inCoordinate)
        {
            Vector3 center = new Vector3();

            switch (CellLayout)
            {
            case CellLayout.Rectangle:
                center.x = inCoordinate.x * CellSize.x + CellSize.x / 2;
                center.y = inCoordinate.y * CellSize.y + CellSize.y / 2;
                break;

            case CellLayout.Hexagon:
                center.x  = inCoordinate.x * CellSize.x;
                center.x += Mathf.Abs(inCoordinate.y) % 2 == 1 ? CellSize.x / 2 : 0;
                center.y  = inCoordinate.y * CellSize.y * 0.75f;
                break;

            case CellLayout.Isometric:
            case CellLayout.IsometricZAsY:
                center.x = (inCoordinate.x - inCoordinate.y) * CellSize.x / 2;
                center.y = (1 + inCoordinate.y + inCoordinate.x) * CellSize.y / 2;
                break;

            default:
                Debug.LogError($"The grid layout {CellLayout.ToString()} is not supported.");
                break;
            }

            return(GridLocalToWorldMatrix.MultiplyPoint3x4(center));
        }
Exemple #2
0
 /// <summary>
 /// Converts the local grid position to a world position using the grid's matrix.
 /// </summary>
 /// <param name="localPosition">Local position in the grid.</param>
 /// <returns>World position.</returns>
 public Vector3 ConvertToWorldPosition(Vector2 localPosition)
 {
     return(GridLocalToWorldMatrix.MultiplyPoint3x4(localPosition));
 }