void DrawLabel(FrogLabel label, Canvas canvas) { if (!label.commonName.Equals(string.Empty)) { label.commonName = " (" + label.commonName + ")"; } string labelText = "<i>" + label.sciName + "</i>" + label.commonName; canvas.enabled = true; canvas.GetComponent <RectTransform>().sizeDelta = new Vector2(canvas.GetComponent <RectTransform>().sizeDelta.x *labelText.Length, canvas.GetComponent <RectTransform>().sizeDelta.y); Text textField = canvas.GetComponentInChildren <Text>(); textField.GetComponent <RectTransform>().sizeDelta = new Vector2(textField.GetComponent <RectTransform>().sizeDelta.x *labelText.Length, textField.GetComponent <RectTransform>().sizeDelta.y); textField.text = labelText; }
Canvas CreateCanvas(FrogLabel label) { Vector3 organPosition = label.organ.transform.position; Vector3 labelPosition = new Vector3(organPosition.x, organPosition.y + labelHeight, organPosition.z); Transform parentTransform = label.organ.transform; GameObject canvasObject = Instantiate(canvasPrefab, labelPosition, Quaternion.identity, parentTransform); Canvas canvas = canvasObject.GetComponent <Canvas>(); float organScale = label.organ.transform.lossyScale.magnitude; float canvasScaleMod = labelScaleMod / organScale; Vector3 canvasScale = canvas.transform.localScale; canvas.transform.localScale = new Vector3(canvasScale.x * canvasScaleMod, canvasScale.y * canvasScaleMod, canvasScale.z * canvasScaleMod); canvas.enabled = false; return(canvas); }