GridLayout.LocalToCellInterpolated

切换到手册
public Vector3 LocalToCellInterpolated (Vector3 localPosition);

参数

localPosition要转换的本地位置。

返回

Vector3 本地位置的插值单元格位置。

描述

将本地位置转换为单元格位置。

返回插值单元格位置(浮点数),而不是精确的单元格位置。

// Move GameObject left by 1/4th of cell width of parent GridLayout
using UnityEngine;

public class ExampleClass : MonoBehaviour { void Start() { GridLayout gridLayout = transform.parent.GetComponent<GridLayout>(); Vector3 cellPosition = gridLayout.LocalToCellInterpolated(transform.localPosition); cellPosition += Vector3.left * 0.25f; transform.localPosition = gridLayout.CellToLocalInterpolated(cellPosition); } }