Пример #1
0
        /// <summary>
        ///   Take world coodinates and find the corresponding square. The
        ///   result is returned as an int array that contains that square's
        ///   position in the matrix.
        /// </summary>
        private static int[] GetSquare(Vector3 vec)
        {
            const CoordinateSystem system = CoordinateSystem.Grid;

            var cell    = _grid.NearestCell(vec, system);
            var shift   = .5f * Vector3.one;
            var square  = cell - shift;
            var indices = new int[2];

            for (var i = 0; i < 2; ++i)
            {
                // Remember, boxes don't have whole coordinates, that's why we
                // use a little shift to turn e.g. (3.5, 2.5, 1.5) into (3, 2,
                // 1).
                indices[i] = Mathf.RoundToInt(square[i]);
            }

            return(indices);
        }