GridLayout.CellToWorld

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

GridLayout.CellToWorld

Объявление

public Vector3 CellToWorld(Vector3Int cellPosition);

Параметры

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

Возвращает

Vector3 Мировая позиция позиции ячейки.

Описание

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

// Snap the GameObject to parent GridLayout
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        GridLayout gridLayout = transform.parent.GetComponentInParent<GridLayout>();
        Vector3Int cellPosition = gridLayout.WorldToCell(transform.position);
        transform.position = gridLayout.CellToWorld(cellPosition);
    }
}

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