private void fitGraphicToCell(LeapMeshGraphic meshGraphic, int row, int col, MeshDisplayParams?meshParams) { // Invert row order (origin at top-left instead of Unity default bottom-left). row = _numRows - 1 - row; Vector2 cellMin = new Vector2(col * _colWidth / rectTransform.rect.width, row * _rowWidth / rectTransform.rect.height); Vector2 cellMax = new Vector2((col + 1) * _colWidth / rectTransform.rect.width, (row + 1) * _rowWidth / rectTransform.rect.height); var graphicRect = ensureGraphicHasRect(meshGraphic); graphicRect.anchorMin = cellMin; graphicRect.anchorMax = cellMax; graphicRect.anchoredPosition = Vector2.zero; graphicRect.sizeDelta = Vector2.zero; float boundsWidth = meshGraphic.mesh.bounds.size.CompMax(); float cellWidth = (cellMax - cellMin).CompMin(); float targetScale = cellWidth / boundsWidth * 0.20f; Quaternion rotation = Quaternion.identity; if (meshParams.HasValue) { targetScale *= meshParams.Value.scale; rotation = Quaternion.Euler(meshParams.Value.rotation); } graphicRect.localScale = Vector3.one * targetScale; graphicRect.localRotation = rotation; }
protected override void Awake() { _name = "Button"; base.Awake(); physicsObject = transform.Find("Physics").gameObject; rimObject = transform.Find("Rim").gameObject; // also get our graphics so we can do hover animations faceModel = physicsObject.GetComponentInChildren <LeapMeshGraphic>(); rimModel = rimObject.GetComponent <LeapMeshGraphic>(); faceModelCollider = faceModel.GetComponent <MeshCollider>(); rimModelCollider = rimModel.GetComponent <MeshCollider>(); faceMesh = new Mesh(); faceMesh.MarkDynamic(); rimMesh = new Mesh(); rimMesh.MarkDynamic(); }
private void layoutAttributeGraphic(LeapMeshGraphic attributeGraphic, int row, int col, MeshDisplayParams?meshParams = null) { fitGraphicToCell(attributeGraphic, row + 1, col + 1, meshParams); }
private void layoutColSpeciesGraphic(LeapMeshGraphic colSpeciesGraphic, int col, MeshDisplayParams?meshParams = null) { fitGraphicToCell(colSpeciesGraphic, 0, col + 1, meshParams); }
private void layoutRowSpeciesGraphic(LeapMeshGraphic rowSpeciesGraphic, int row, MeshDisplayParams?meshParams = null) { fitGraphicToCell(rowSpeciesGraphic, row + 1, 0, meshParams); }