9using System.Collections.Generic;
25 [DisallowMultipleComponent]
31 private float _thickness = 0.01f;
37 get {
return new Vector3(
_size.x,
_size.y, _thickness); }
38 private set {
_size =
new Vector2(value.x, value.y); _thickness = value.z; }
44 List<Vector3> verts =
new List<Vector3>();
45 List<Vector2> uvs =
new List<Vector2>();
46 List<Vector3> normals =
new List<Vector3>();
47 List<int> tris =
new List<int>();
50 for (
int vy = 0; vy < resolution.
y; vy++) {
51 for (
int vx = 0; vx < resolution.
x; vx++) {
55 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
56 normals.Add(Vector3.forward);
65 int backVertsCount = verts.Count;
68 float depth = -
size.z;
69 for (
int vy = 0; vy < resolution.
y; vy++) {
70 for (
int vx = 0; vx < resolution.
x; vx++) {
71 Vector3 vert = Vector3.zero;
74 verts.Add(vert +
new Vector3(
rect.x,
rect.y, depth));
75 normals.Add(Vector3.back);
85 for (
int vy = 0; vy < resolution.
y - 1; vy++) {
86 for (
int vx = 0; vx < resolution.
x - 1; vx++) {
87 int vertIndex = vy * resolution.
x + vx;
90 tris.Add(vertIndex + 1);
91 tris.Add(vertIndex + 1 + resolution.
x);
94 tris.Add(vertIndex + 1 + resolution.
x);
95 tris.Add(vertIndex + resolution.
x);
100 for (
int vy = 0; vy < resolution.
y - 1; vy++) {
101 for (
int vx = 0; vx < resolution.
x - 1; vx++) {
102 int vertIndex = backVertsCount + (vy * resolution.
x + vx);
105 tris.Add(vertIndex + 1 + resolution.
x);
106 tris.Add(vertIndex + 1);
109 tris.Add(vertIndex + resolution.
x);
110 tris.Add(vertIndex + 1 + resolution.
x);
116 int backVertIdx = verts.Count, frontVertIdx = verts.Count;
119 for (
int vy = 0; vy < resolution.
y; vy++) {
123 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
124 normals.Add(Vector3.left);
133 for (
int vy = 0; vy < resolution.
y; vy++) {
134 Vector3 vert = Vector3.zero;
137 verts.Add(vert +
new Vector3(
rect.x,
rect.y, depth));
138 normals.Add(Vector3.left);
145 for (
int vy = 0; vy < resolution.
y - 1; vy++) {
146 addQuad(tris, frontVertIdx + vy, backVertIdx + vy, backVertIdx + vy + 1, frontVertIdx + vy + 1);
150 ex = resolution.
x - 1;
151 backVertIdx = verts.Count;
152 frontVertIdx = verts.Count;
153 for (
int vy = 0; vy < resolution.
y; vy++) {
157 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
158 normals.Add(Vector3.right);
167 for (
int vy = 0; vy < resolution.
y; vy++) {
168 Vector3 vert = Vector3.zero;
171 verts.Add(vert +
new Vector3(
rect.x,
rect.y, depth));
172 normals.Add(Vector3.right);
179 for (
int vy = 0; vy < resolution.
y - 1; vy++) {
180 addQuad(tris, frontVertIdx + vy + 1, backVertIdx + vy + 1, backVertIdx + vy, frontVertIdx + vy);
184 ey = resolution.
y - 1;
185 backVertIdx = verts.Count;
186 frontVertIdx = verts.Count;
187 for (
int vx = 0; vx < resolution.
x; vx++) {
191 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
192 normals.Add(Vector3.up);
201 for (
int vx = 0; vx < resolution.
x; vx++) {
202 Vector3 vert = Vector3.zero;
205 verts.Add(vert +
new Vector3(
rect.x,
rect.y, depth));
206 normals.Add(Vector3.up);
213 for (
int vx = 0; vx < resolution.
x - 1; vx++) {
214 addQuad(tris, frontVertIdx + vx, backVertIdx + vx, backVertIdx + vx + 1, frontVertIdx + vx + 1);
219 backVertIdx = verts.Count;
220 frontVertIdx = verts.Count;
221 for (
int vx = 0; vx < resolution.
x; vx++) {
225 verts.Add(vert +
new Vector2(
rect.x,
rect.y));
226 normals.Add(Vector3.down);
235 for (
int vx = 0; vx < resolution.
x; vx++) {
236 Vector3 vert = Vector3.zero;
239 verts.Add(vert +
new Vector3(
rect.x,
rect.y, depth));
240 normals.Add(Vector3.down);
247 for (
int vx = 0; vx < resolution.
x - 1; vx++) {
248 addQuad(tris, frontVertIdx + vx + 1, backVertIdx + vx + 1, backVertIdx + vx, frontVertIdx + vx);
255 mesh.name =
"Box Mesh";
256 mesh.hideFlags = HideFlags.HideAndDontSave;
258 mesh.Clear(keepVertexLayout:
false);
259 mesh.SetVertices(verts);
260 mesh.SetNormals(normals);
261 mesh.SetTriangles(tris, 0);
263 mesh.RecalculateBounds();
268 private void addQuad(List<int> tris,
int idx0,
int idx1,
int idx2,
int idx3) {
The Box Graphic is a type of procedural mesh graphic that can generate thick panels with a number of ...
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.
Vector3 size
Gets the dimensions of the box graphic in local space.
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 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,...
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...
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.