using UnityEngine;
[ExecuteInEditMode]//编辑模式下执行
public class BlockAlign : MonoBehaviour
{
public bool IsHideInHierarchy = false;
public const int SpacingUnit = 50; //间距单位长度
void Start()
{
//在分层列表中隐藏
if (IsHideInHierarchy)
{
gameObject.hideFlags = HideFlags.HideInHierarchy;
}
}
void Update()
{
transform.localPosition = new Vector3(rounding(transform.localPosition.x, SpacingUnit), rounding(transform.localPosition.y, SpacingUnit));//对齐到网格
}
//取整
int rounding(float val, int div)
{
return Mathf.RoundToInt(val / div) * div;
}
}
BlockAlign.cs
最新推荐文章于 2024-03-09 17:21:05 发布