Exemplo n.º 1
0
        protected virtual void Update()
        {
            // Cache our pivot / anchor / attach point positions
            pivotPosition       = pivot.transform.position;
            anchorPosition      = anchor.transform.position;
            attachPointPosition = contentParent.transform.TransformPoint(localAttachPoint) + attachPointOffset;

            // 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();
        }
Exemplo n.º 2
0
        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 or fontSize changed?
            int currentTextLength = toolTipText.Length;
            int currentTextHash   = toolTipText.GetHashCode();
            int currentFontSize   = fontSize;

            // If it has, update the content
            if (currentTextLength != prevTextLength || currentTextHash != prevTextHash || currentFontSize != prevFontSize)
            {
                prevTextHash   = currentTextHash;
                prevTextLength = currentTextLength;
                prevFontSize   = currentFontSize;

                if (cachedLabelText == null)
                {
                    cachedLabelText = label.GetComponent <TextMeshPro>();
                }

                if (cachedLabelText != null && !string.IsNullOrEmpty(toolTipText))
                {
                    cachedLabelText.fontSize = fontSize;
                    cachedLabelText.text     = toolTipText.Trim();
                    // Force text mesh to use center alignment
                    cachedLabelText.alignment = TextAlignmentOptions.CenterGeoAligned;
                    // Update text so we get an accurate scale
                    cachedLabelText.ForceMeshUpdate();
                    // Get the world scale of the text
                    // Convert that to local scale using the content parent
                    Vector3 localScale = Vector3.Scale(cachedLabelText.transform.lossyScale / contentScale, cachedLabelText.textBounds.size);
                    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;
            }
        }