Tanoda
LeapPanelGraphic.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.Collections.Generic;
10using UnityEngine;
11using UnityEngine.Rendering;
12
14
22 [DisallowMultipleComponent]
24
25 public override void RefreshSlicedMeshData(Vector2i resolution,
26 RectMargins meshMargins,
27 RectMargins uvMargins) {
28 List<Vector3> verts = new List<Vector3>();
29 List<Vector2> uvs = new List<Vector2>();
30 List<int> tris = new List<int>();
31
32 for (int vy = 0; vy < resolution.y; vy++) {
33 for (int vx = 0; vx < resolution.x; vx++) {
34 Vector2 vert;
35 vert.x = calculateVertAxis(vx, resolution.x, rect.width, meshMargins.left, meshMargins.right);
36 vert.y = calculateVertAxis(vy, resolution.y, rect.height, meshMargins.top, meshMargins.bottom);
37 verts.Add(vert + new Vector2(rect.x, rect.y));
38
39 Vector2 uv;
40 uv.x = calculateVertAxis(vx, resolution.x, 1, uvMargins.left, uvMargins.right);
41 uv.y = calculateVertAxis(vy, resolution.y, 1, uvMargins.top, uvMargins.bottom);
42 uvs.Add(uv);
43 }
44 }
45
46 for (int vy = 0; vy < resolution.y - 1; vy++) {
47 for (int vx = 0; vx < resolution.x - 1; vx++) {
48 int vertIndex = vy * resolution.x + vx;
49
50 tris.Add(vertIndex);
51 tris.Add(vertIndex + 1 + resolution.x);
52 tris.Add(vertIndex + 1);
53
54 tris.Add(vertIndex);
55 tris.Add(vertIndex + resolution.x);
56 tris.Add(vertIndex + 1 + resolution.x);
57 }
58 }
59
60 if (mesh == null) {
61 mesh = new Mesh();
62 }
63
64 mesh.name = "Panel Mesh";
65 mesh.hideFlags = HideFlags.HideAndDontSave;
66
67 mesh.Clear(keepVertexLayout: false);
68 mesh.SetVertices(verts);
69 mesh.SetTriangles(tris, 0);
70 mesh.SetUVs(uvChannel.Index(), uvs);
71 mesh.RecalculateBounds();
72
73 remappableChannels = UVChannelFlags.UV0;
74 }
75 }
76}
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 Graphic is a type of procedural mesh graphic that can generate flat 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.
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...