GridLayout.CellToLocalInterpolated

Unity · Версия 2020.3 LTS · Scripting · GridLayout

GridLayout.CellToLocalInterpolated

Объявление

public Vector3 CellToLocalInterpolated(Vector3 cellPosition);

Параметры

cellPosition Интерполированная позиция ячейки для преобразования.

Возвращает

Vector3 Локальное положение ячейки.

Описание

Преобразует интерполированную позицию ячейки из чисел с плавающей запятой в локальное пространство позиций.

Возвращает локальную позицию в числах с плавающей запятой.

// Snap the GameObject to parent GridLayout center of cell
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        GridLayout gridLayout = transform.parent.GetComponent<GridLayout>();
        Vector3Int cellPosition = gridLayout.LocalToCell(transform.localPosition);
        transform.localPosition = gridLayout.CellToLocalInterpolated(cellPosition + new Vector3(.5f, .5f, .5f));
    }
}

Обновлено 17 ноября 2026 г.