public NodeData(UINodeInfo info, AABB bounds) { this.Item1 = info; this.Item2 = bounds; }
private void GenInfo() { rectTransform = assetObject.GetComponent <RectTransform>(); MaskableGraphic ui = assetObject.GetComponent <MaskableGraphic>(); nodeInfo = new UINodeInfo(ui != null, assetObject.GetComponent <Canvas>() != null, assetObject.name); nodeInfo.Depth = depth; nodeInfo.IsInMask = assetObject.GetComponent <Mask>() != null ? 0 : -1; nodeInfo.IsInMask2D = assetObject.GetComponent <RectMask2D>() != null?nodeInfo.GetHashCode() : -1; if (ui != null) { nodeInfo.MaterialInstanceID = ui.material.GetInstanceID(); nodeInfo.TextureID = ui.mainTexture.GetInstanceID(); } Matrix4x4 localToWorldMatrix = assetObject.transform.localToWorldMatrix; Text t = assetObject.GetComponent <Text>(); if (t != null) { if (t.text.Equals("")) { for (int i = 0; i < 4; i++) { nodeInfo.Corners[i] = localToWorldMatrix.MultiplyPoint(Vector2.zero); } } else { Rect rect = t.GetPixelAdjustedRect(); float halfWidth = t.preferredWidth / 2; float halfHeight = t.preferredHeight / 2; Vector2 pos_1 = Vector2.zero; int idx = (int)t.alignment; if (idx % 3 == 0) { pos_1.x = -rect.width / 2 + halfWidth; } else if (idx % 3 == 2) { pos_1.x = rect.width / 2 - halfWidth; } if (idx / 3 == 0) { pos_1.y = rect.height / 2 - halfHeight; } else if (idx / 3 == 2) { pos_1.y = -rect.height / 2 + halfHeight; } Vector2[] pos = new Vector2[4]; pos[0] = new Vector2(pos_1.x - halfWidth, pos_1.y - halfHeight); pos[1] = new Vector2(pos_1.x - halfWidth, pos_1.y + halfHeight); pos[2] = new Vector2(pos_1.x + halfWidth, pos_1.y + halfHeight); pos[3] = new Vector2(pos_1.x + halfWidth, pos_1.y - halfHeight); if (rectTransform.pivot.x < 0.000001) { for (int i = 0; i < 4; ++i) { pos[i] = new Vector2(pos[i].x + rect.size.x / 2, pos[i].y); } } else if (Mathf.Abs(rectTransform.pivot.x - 1) < 0.000001) { for (int i = 0; i < 4; ++i) { pos[i] = new Vector2(pos[i].x - rect.size.x / 2, pos[i].y); } } if (rectTransform.pivot.y < 0.000001) { for (int i = 0; i < 4; ++i) { pos[i] = new Vector2(pos[i].x, pos[i].y + rect.size.y / 2); } } else if (Mathf.Abs(rectTransform.pivot.y - 1) < 0.000001) { for (int i = 0; i < 4; ++i) { pos[i] = new Vector2(pos[i].x, pos[i].y - rect.size.y / 2); } } for (int i = 0; i < 4; i++) { nodeInfo.Corners[i] = localToWorldMatrix.MultiplyPoint(pos[i]); } } } else { rectTransform.GetWorldCorners(nodeInfo.Corners); } }