예제 #1
0
        IEnumerator AnimateHide(ITooltip tooltip, TooltipData data)
        {
            var target    = data.GetTooltipTarget(tooltip);
            var startTime = Time.realtimeSinceStartup;

            while (Time.realtimeSinceStartup - startTime < k_TransitionDuration)
            {
                if (!target)
                {
                    break;
                }

                UpdateVisuals(tooltip, data, 1 - (Time.realtimeSinceStartup - startTime) / k_TransitionDuration);
                yield return(null);
            }

            RecycleTooltip(data);
        }
예제 #2
0
        void UpdateVisuals(ITooltip tooltip, TooltipData tooltipData, float lerp)
        {
            var target            = tooltipData.GetTooltipTarget(tooltip);
            var tooltipUI         = tooltipData.tooltipUI;
            var placement         = tooltipData.placement;
            var orientationWeight = tooltipData.orientationWeight;
            var tooltipTransform  = tooltipUI.transform;

            lerp = MathUtilsExt.SmoothInOutLerpFloat(lerp); // shape the lerp for better presentation
            var transitionLerp = MathUtilsExt.SmoothInOutLerpFloat(1.0f - Mathf.Clamp01((Time.time - tooltipData.transitionTime) / k_ChangeTransitionDuration));

            var viewerScale = this.GetViewerScale();

            tooltipTransform.localScale = m_TooltipScale * lerp * viewerScale;

            // Adjust for alignment
            var offset = GetTooltipOffset(tooltipUI, placement, tooltipData.transitionOffset * transitionLerp);

            // The rectTransform expansion is handled in the Tooltip dynamically, based on alignment & text length
            var rotationOffset = Quaternion.identity;
            var camTransform   = CameraUtils.GetMainCamera().transform;

            if (Vector3.Dot(camTransform.forward, target.forward) < 0)
            {
                rotationOffset *= k_FlipYRotation;
            }

            if (Vector3.Dot(camTransform.up, target.up) + orientationWeight < 0)
            {
                rotationOffset *= k_FlipZRotation;
                tooltipData.orientationWeight = -k_TextOrientationWeight;
            }
            else
            {
                tooltipData.orientationWeight = k_TextOrientationWeight;
            }

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

            if (placement != null)
            {
                //TODO: Figure out why rect gives us different height/width than GetWorldCorners
                tooltipUI.rectTransform.GetWorldCorners(k_Corners);
                var bottomLeft = k_Corners[0];
                var halfWidth  = (bottomLeft - k_Corners[2]).magnitude * 0.5f;
                var halfHeight = (bottomLeft - k_Corners[1]).magnitude * 0.5f;

                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);

                var parentScale = attachedSphere.parent.lossyScale;
                halfHeight *= Mathf.Sign(toSource.y) / parentScale.x;
                halfWidth  *= Mathf.Sign(toSource.x) / parentScale.y;
                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);
            }
        }