GridLayout.LocalToCellInterpolated

Switch to Manual
public Vector3 LocalToCellInterpolated (Vector3 localPosition);

Parameters

localPosition要转换的本地位置。

Returns

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

Description

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

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

// 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); } }