Sprite padding, innerUV, outerUV的解释

发布时间 2023-07-28 23:31:43作者: yanghui01

1) Rect rect;

Sprite Mode为Single时: x, y总是为0; width, height为裁掉空白像素前的大小

2) Vector2 textureRectOffset;

左下角裁掉了多少空白像素

3) Rect textureRect;

x, y为Sprite左下角的坐标(图集左下角为原点); width, height为裁掉空白像素后的大小

4) Vector4 padding = UnityEngine.Sprites.DataUtility.GetPadding(sp);

上下左右裁掉的空白像素大小

5) Vector4 outerUV = UnityEngine.Sprites.DataUtility.GetOuterUV(sp);

左下角和右上角在图集上的uv值

6) Vector4 border;

9宫格4个区域的大小

7) Vector4 innerUV = UnityEngine.Sprites.DataUtility.GetInnerUV(sp);

innerUV.xy = outerUV.xy - paddingUV.xy + borderUV.xy

innerUV.zw = outerUV.zw + paddingUV.zw - borderUV.zw

8)Vector2 minSize = UnityEngine.Sprites.DataUtility.GetMinSize(sp);

minSize.x = border.x+border.z

minSize .y = border.y+border.w

9) Bounds bounds = sp.bounds;

center为裁掉空白像素前的中心的坐标(以pivot为原点),extends总是为长,宽的一半

center = (0.5 - pivot) * 裁掉空白像素前的大小 / 像素每世界空间单位

extends = 裁掉空白像素前的大小 * 0.5 / 像素每世界空间单位


图集示例

下面的图集大小为512x512

 

下面的图片中红色区域为outer对应的区域,绿色区域为inner对应的区域

1, 无9宫,无空白像素裁剪

 

rect: [(0, 0), size:(238x105), (238, 105)]
textureRectOffset: (0, 0)
textureRect: [(0, 338), size:(238x105), (238, 443)]
padding: (0, 0, 0, 0), paddingUV: (0, 0, 0, 0)
outerUV: (0, 0.6601563, 0.4648438, 0.8652344)
border: (0, 0, 0, 0), borderUV: (0, 0, 0, 0)
innerUV: (0, 0.6601563, 0.4648438, 0.8652344)
minSize: (0, 0)
bounds: center:(0, 0, 0), extends:(1.19, 0.525, 0.1), size:(2.38, 1.05, 0.2)
pivot: (119, 52.5)

 

2, 有9宫,无空白像素裁剪

 

rect: [(0, 0), size:(177x204), (177, 204)]
textureRectOffset: (0, 0)
textureRect: [(0, 0), size:(177x204), (177, 204)]
padding: (0, 0, 0, 0), paddingUV: (0, 0, 0, 0)
outerUV: (0, 0, 0.3457031, 0.3984375)
border: (35, 43, 38, 40), borderUV: (0.06835938, 0.08398438, 0.07421875, 0.078125)
innerUV: (0.06835938, 0.08398438, 0.2714844, 0.3203125)
minSize: (73, 83)
bounds: center:(0, 0, 0), extends:(0.885, 1.02, 0.1), size:(1.77, 2.04, 0.2)
pivot: (88.5, 102)

 

3, 无9宫,有空白像素裁剪

 

rect: [(0, 0), size:(128x128), (128, 128)]
textureRectOffset: (25.07612, 7.07612)
textureRect: [(0.07612038, 206.0761), size:(77.89713x113.8478), (77.97325, 319.9239)]
padding: (25.07612, 7.07612, 25.02675, 7.076118), paddingUV: (0.0489768, 0.01382055, 0.04888037, 0.01382054)
outerUV: (0.0001486726, 0.4024924, 0.1522915, 0.6248513)
border: (0, 0, 0, 0), borderUV: (0, 0, 0, 0)
innerUV: (-0.04882813, 0.3886719, 0.2011719, 0.6386719)
minSize: (0, 0)
bounds: center:(0, 0, 0), extends:(0.64, 0.64, 0.1), size:(1.28, 1.28, 0.2)
pivot: (64, 64)

 

4, 有9宫,有空白像素裁剪

 

rect: [(0, 0), size:(200x190), (200, 190)]
textureRectOffset: (12.07612, 14.07612)
textureRect: [(179.0761, 183.0761), size:(165.8477x152.8477), (344.9239, 335.9239)]
padding: (12.07612, 14.07612, 22.07613, 23.07613), paddingUV: (0.02358617, 0.02749242, 0.04311743, 0.04507056)
outerUV: (0.3497581, 0.3575706, 0.6736795, 0.6561013)
border: (50, 53, 52, 51), borderUV: (0.09765625, 0.1035156, 0.1015625, 0.09960938)
innerUV: (0.4238281, 0.4335938, 0.6152344, 0.6015625)
minSize: (102, 104)
bounds: center:(0, 0, 0), extends:(1, 0.95, 0.1), size:(2, 1.9, 0.2)
pivot: (100, 95)