protected virtual void RefreshLocalContent() { // Set the scale of the pivot contentParent.transform.localScale = Vector3.one * contentScale; label.transform.localScale = Vector3.one * 0.005f; // Set the content using a text mesh by default // This function can be overridden for tooltips that use Unity UI TextMesh text = label.GetComponent <TextMesh>(); if (text != null && !string.IsNullOrEmpty(toolTipText)) { text.fontSize = fontSize; text.text = toolTipText.Trim(); text.lineSpacing = 1; text.anchor = TextAnchor.MiddleCenter; // Get the world scale of the text // Convert that to local scale using the content parent Vector3 localScale = text.transform.localScale; localContentSize.x = localScale.x + backgroundPadding.x; localContentSize.y = localScale.y + backgroundPadding.y; } // Now that we have the size of our content, get our pivots ToolTipUtility.GetAttachPointPositions(ref localAttachPointPositions, localContentSize); localAttachPoint = ToolTipUtility.FindClosestAttachPointToAnchor(anchor.transform, contentParent.transform, localAttachPointPositions, PivotType); }
protected virtual void Update() { // Enable / disable our line if it exists if (toolTipLine != null) { toolTipLine.enabled = showConnector; if (!(toolTipLine is ParabolaConstrainedLineDataProvider)) { toolTipLine.FirstPoint = AnchorPosition; } toolTipLine.LastPoint = AttachPointPosition; } if (IsOn) { contentParent.SetActive(true); localAttachPoint = ToolTipUtility.FindClosestAttachPointToAnchor(anchor.transform, contentParent.transform, localAttachPointPositions, PivotType); } else { contentParent.SetActive(false); } RefreshLocalContent(); }
protected virtual void RefreshLocalContent() { // Set the scale of the pivot contentParent.transform.localScale = Vector3.one * contentScale; label.transform.localScale = Vector3.one * 0.005f; // Set the content using a text mesh by default // This function can be overridden for tooltips that use Unity UI // Has content changed? int currentTextLength = toolTipText.Length; int currentTextHash = toolTipText.GetHashCode(); // If it has, update the content if (currentTextLength != prevTextLength || currentTextHash != prevTextHash) { prevTextHash = currentTextHash; prevTextLength = currentTextLength; if (cachedLabelText == null) { cachedLabelText = label.GetComponent <TextMesh>(); } if (cachedLabelText != null && !string.IsNullOrEmpty(toolTipText)) { cachedLabelText.fontSize = fontSize; cachedLabelText.text = toolTipText.Trim(); cachedLabelText.lineSpacing = 1; cachedLabelText.anchor = TextAnchor.MiddleCenter; // Get the world scale of the text // Convert that to local scale using the content parent Vector3 localScale = GetTextMeshLocalScale(cachedLabelText); localContentSize.x = localScale.x + backgroundPadding.x; localContentSize.y = localScale.y + backgroundPadding.y; } // Now that we have the size of our content, get our pivots ToolTipUtility.GetAttachPointPositions(ref localAttachPointPositions, localContentSize); localAttachPoint = ToolTipUtility.FindClosestAttachPointToAnchor(anchor.transform, contentParent.transform, localAttachPointPositions, PivotType); foreach (IToolTipBackground background in backgrounds) { background.OnContentChange(localContentSize, LocalContentOffset, contentParent.transform); } } foreach (IToolTipBackground background in backgrounds) { background.IsVisible = showBackground; } foreach (IToolTipHighlight highlight in highlights) { highlight.ShowHighlight = ShowHighlight; } }