Пример #1
0
 public void Reset()
 {
     startTime         = default(float);
     lastModifiedTime  = default(float);
     tooltipUI         = default(TooltipUI);
     persistent        = default(bool);
     duration          = default(float);
     becameVisible     = default(Action);
     placement         = default(ITooltipPlacement);
     orientationWeight = default(float);
     transitionOffset  = default(Vector3);
     transitionTime    = default(float);
 }
Пример #2
0
        IEnumerator AnimateHide(ITooltip tooltip, TooltipUI tooltipUI)
        {
            var target    = GetTooltipTarget(tooltip);
            var startTime = Time.realtimeSinceStartup;

            while (Time.realtimeSinceStartup - startTime < k_TransitionDuration)
            {
                UpdateVisuals(tooltip, tooltipUI, target,
                              1 - (Time.realtimeSinceStartup - startTime) / k_TransitionDuration);
                yield return(null);
            }

            ObjectUtils.Destroy(tooltipUI.gameObject);
        }
Пример #3
0
        Vector3 GetTooltipOffset(TooltipUI tooltipUI, ITooltipPlacement placement, Vector3 transitionOffset)
        {
            if (tooltipUI == null)
            {
                return(Vector3.zero);
            }

            var offset = Vector3.zero;

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

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

            // The rectTransform expansion is handled in the Tooltip dynamically, based on alignment & text length
            var rectTransform = tooltipUI.rectTransform;
            var rect          = rectTransform.rect;
            var halfWidth     = rect.width * 0.5f;

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

            offset += transitionOffset;

            return(offset);
        }
Пример #4
0
        Vector3 GetTooltipOffset(TooltipUI tooltipUI, ITooltipPlacement placement, Vector3 transitionOffset)
        {
            if (tooltipUI == null)
            {
                return(Vector3.zero);
            }

            var offset = Vector3.zero;

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

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

            if (placement != null)
            {
                tooltipUI.rectTransform.GetWorldCorners(k_Corners);
                var halfWidth = (k_Corners[0] - k_Corners[2]).magnitude * 0.5f;
                offset *= halfWidth;
            }
            else
            {
                offset = Vector3.back * k_Offset * this.GetViewerScale();
            }

            offset += transitionOffset;

            return(offset);
        }
Пример #5
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);
            }
        }
Пример #6
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);
            }
        }