9using System.Collections.Generic;
21 [DisallowMultipleComponent]
26 [Header(
"Outline Thickness")]
28 [Tooltip(
"Check this option to override the thickness of the sprite's borders with "
29 +
"a custom thickness. This will stretch the sprite's borders to match the "
30 +
"custom thickness.")]
32 private bool _overrideSpriteBorders =
false;
40 return _overrideSpriteBorders;
44 [Tooltip(
"The local-space thickness of the panel edges that are constructed. If the"
45 +
"source data for the panel is a Sprite, this value is overridden to reflect "
46 +
"the sprite's nine-slicing.")]
49 private Vector2 _thickness =
new Vector2(0.01F, 0.01F);
74 resolution.
x = Mathf.Max(resolution.
x, 4);
75 resolution.
y = Mathf.Max(resolution.
y, 4);
81 meshMargins =
new RectMargins(_thickness.x, _thickness.y, _thickness.x, _thickness.y);
84 float xRatio = _thickness.x /
rect.width;
85 float yRatio = _thickness.y /
rect.height;
86 xRatio = Mathf.Clamp(xRatio, 0F, 0.5F);
87 yRatio = Mathf.Clamp(yRatio, 0F, 0.5F);
88 uvMargins =
new RectMargins(left: xRatio, right: xRatio,
89 top: yRatio, bottom: yRatio);
92 List<Vector3> verts =
new List<Vector3>();
93 List<Vector2> uvs =
new List<Vector2>();
94 List<int> tris =
new List<int>();
96 for (
int vy = 0; vy < resolution.
y; vy++) {
97 for (
int vx = 0; vx < resolution.
x; vx++) {
99 if ((vy > 1 && vy < resolution.
y - 2) && (vx > 1 && vx < resolution.
x - 2))
continue;
104 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
113 int indicesSkippedPerRow = resolution.
x - 4;
114 int indicesSkipped = 0;
115 for (
int vy = 0; vy < resolution.
y; vy++) {
116 for (
int vx = 0; vx < resolution.
x; vx++) {
118 if (vx == resolution.
x - 1 || vy == resolution.
y - 1) {
121 if ((vx == 1 && (vy > 0 && vy < resolution.
y - 2)) || (vy == 1 && (vx > 0 && vx < resolution.
x - 2))) {
124 if ((vx > 1 && vx < resolution.
x - 2) && (vy > 1 && vy < resolution.
y - 2)) {
129 int vertIndex = vy * resolution.
x + vx - indicesSkipped;
133 if (vy == 0 || (vy == 1 && vx < 2) || (vy == resolution.
y - 3 && vx > resolution.
x - 3) || (vy == resolution.
y - 2)) {
137 down = resolution.
x - indicesSkippedPerRow;
142 tris.Add(vertIndex + right + down);
143 tris.Add(vertIndex + right);
146 tris.Add(vertIndex + down);
147 tris.Add(vertIndex + right + down);
155 mesh.name =
"Panel Outline Mesh";
156 mesh.hideFlags = HideFlags.HideAndDontSave;
158 mesh.Clear(keepVertexLayout:
false);
159 mesh.SetVertices(verts);
160 mesh.SetTriangles(tris, 0);
162 mesh.RecalculateBounds();
Mesh mesh
Returns the mesh that represents this graphic. It can have any topology, any number of uv channels,...
UVChannelFlags remappableChannels
Returns an enum mask that represents the union of all channels that are allowed to be remapped for th...
The Panel Outline Graphic acts just like a Panel Graphic, but only produces quads for the outermost e...
override void OnValidate()
bool overrideSpriteBorders
Gets whether the Panel Outline Graphic is overriding the borders of its sprite data source....
override void RefreshSlicedMeshData(Vector2i resolution, RectMargins meshMargins, RectMargins uvMargins)
Set the mesh property equal to the correct mesh given the Sliced Graphic's current settings.
Vector2 thickness
Gets the thickness of the panel edges.
The base class for LeapPanelGraphic, LeapBoxGraphic, and similar generators.
float calculateVertAxis(int vertIdx, int vertCount, float size, float border0, float border1, bool alwaysRespectBorder=false)
Given a vertex index from an edge, the total vertCount and size along the current dimension,...
override void RefreshMeshData()
When this method is called, the mesh property and the remappableChannels property must be assigned to...
Rect rect
Returns the current local-space rect of this panel. If there is a RectTransform attached to this pane...
UVChannelFlags uvChannel
Returns which uv channel is being used for this panel. It will always match the uv channel being used...
bool nineSliced
Gets or sets whether or not this panel is currently using nine slicing.
float bottom
Margin width from the bottom edge.
float top
Margin width from the top edge.
float right
Margin width from the right edge.
float left
Margin width from the left edge.