Example #1
0
        void UpdateVisuals(ITooltip tooltip, TooltipUI tooltipUI, Transform target, float lerp)
        {
            var tooltipTransform = tooltipUI.transform;

            var tooltipText = tooltipUI.text;

            if (tooltipText)
            {
                tooltipText.text = tooltip.tooltipText;
            }

            var viewerScale = getViewerScale();

            tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale;

            var placement = tooltip as ITooltipPlacement;

            // Adjust for alignment
            var offset = Vector3.zero;

            if (placement != null)
            {
                switch (placement.tooltipAlignment)
                {
                case TextAlignment.Right:
                    offset = Vector3.left;
                    break;

                case TextAlignment.Left:
                    offset = Vector3.right;
                    break;
                }
            }

            var rectTransform = tooltipUI.GetComponent <RectTransform>();
            var rect          = rectTransform.rect;
            var halfWidth     = rect.width * 0.5f;
            var halfHeight    = rect.height * 0.5f;

            if (placement != null)
            {
                offset *= halfWidth * rectTransform.lossyScale.x;
            }
            else
            {
                offset = Vector3.back * k_Offset;
            }

            MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, Quaternion.identity);

            if (placement != null)
            {
                var source   = placement.tooltipSource;
                var toSource = tooltipTransform.InverseTransformPoint(source.position);

                // Position spheres: one at source, one on the closest edge of the tooltip
                var spheres = tooltipUI.spheres;
                spheres[0].position = source.position;

                var attachedSphere = spheres[1];
                var boxSlope       = halfHeight / halfWidth;
                var toSourceSlope  = Mathf.Abs(toSource.y / toSource.x);

                halfHeight *= Mathf.Sign(toSource.y);
                halfWidth  *= Mathf.Sign(toSource.x);
                attachedSphere.localPosition = toSourceSlope > boxSlope
                                        ? new Vector3(0, halfHeight)
                                        : new Vector3(halfWidth, 0);

                // Align dotted line
                var attachedSpherePosition = attachedSphere.position;
                toSource = source.position - attachedSpherePosition;
                var midPoint   = attachedSpherePosition + toSource * 0.5f;
                var dottedLine = tooltipUI.dottedLine;
                var length     = toSource.magnitude;
                var uvRect     = dottedLine.uvRect;
                var worldScale = 1 / viewerScale;
                uvRect.width      = length * k_UVScale * worldScale;
                uvRect.xMin      += k_UVScrollSpeed * Time.unscaledDeltaTime;
                dottedLine.uvRect = uvRect;

                var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>();
                dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x);
                dottedLineTransform.position = midPoint;
                dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward);
            }
        }
Example #2
0
        void UpdateVisuals(ITooltip tooltip, TooltipUI tooltipUI, Transform target, float lerp)
        {
            var tooltipTransform = tooltipUI.transform;

            lerp = MathUtilsExt.SmoothInOutLerpFloat(lerp);             // shape the lerp for better presentation

            var tooltipText = tooltipUI.text;

            if (tooltipText)
            {
                tooltipText.text  = tooltip.tooltipText;
                tooltipText.color = Color.Lerp(Color.clear, Color.white, lerp);
            }

            var viewerScale = this.GetViewerScale();

            tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale;

            TooltipData toolTipData;

            m_Tooltips.TryGetValue(tooltip, out toolTipData);
            var highlightMaterial = toolTipData != null ? toolTipData.customHighlightMaterial : m_HighlightMaterial;

            tooltipUI.highlight.material = highlightMaterial;

            m_TooltipBackgroundMaterial.SetColor("_Color", Color.Lerp(UnityBrandColorScheme.darker, m_OriginalBackgroundColor, lerp));

            var placement = tooltip as ITooltipPlacement;

            // Adjust for alignment
            var offset = Vector3.zero;

            if (placement != null)
            {
                switch (placement.tooltipAlignment)
                {
                case TextAlignment.Right:
                    offset = Vector3.left;
                    break;

                case TextAlignment.Left:
                    offset = Vector3.right;
                    break;
                }
            }

            var rectTransform = tooltipUI.GetComponent <RectTransform>();
            var rect          = rectTransform.rect;
            var halfWidth     = rect.width * 0.5f;
            var halfHeight    = rect.height * 0.5f;

            if (placement != null)
            {
                offset *= halfWidth * rectTransform.lossyScale.x;
            }
            else
            {
                offset = Vector3.back * k_Offset * this.GetViewerScale();
            }

            MathUtilsExt.SetTransformOffset(target, tooltipTransform, offset * lerp, Quaternion.identity);

            if (placement != null)
            {
                var source   = placement.tooltipSource;
                var toSource = tooltipTransform.InverseTransformPoint(source.position);

                // Position spheres: one at source, one on the closest edge of the tooltip
                var spheres = tooltipUI.spheres;
                spheres[0].position = source.position;

                var attachedSphere = spheres[1];
                var boxSlope       = halfHeight / halfWidth;
                var toSourceSlope  = Mathf.Abs(toSource.y / toSource.x);

                halfHeight *= Mathf.Sign(toSource.y);
                halfWidth  *= Mathf.Sign(toSource.x);
                attachedSphere.localPosition = toSourceSlope > boxSlope
                                        ? new Vector3(0, halfHeight)
                                        : new Vector3(halfWidth, 0);

                // Align dotted line
                var attachedSpherePosition = attachedSphere.position;
                toSource = source.position - attachedSpherePosition;
                var midPoint   = attachedSpherePosition + toSource * 0.5f;
                var dottedLine = tooltipUI.dottedLine;
                var length     = toSource.magnitude;
                var uvRect     = dottedLine.uvRect;
                var worldScale = 1 / viewerScale;
                uvRect.width      = length * k_UVScale * worldScale;
                uvRect.xMin      += k_UVScrollSpeed * Time.deltaTime;
                dottedLine.uvRect = uvRect;

                var dottedLineTransform = dottedLine.transform.parent.GetComponent <RectTransform>();
                dottedLineTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, length / tooltipTransform.lossyScale.x);
                dottedLineTransform.position = midPoint;
                dottedLineTransform.rotation = Quaternion.LookRotation(toSource, -tooltipTransform.forward);
            }
        }