コード例 #1
0
ファイル: LeanTooltip.cs プロジェクト: kamild160/Quiz
        protected virtual void Update()
        {
            if (cachedRectTransformSet == false)
            {
                cachedRectTransform    = GetComponent <RectTransform>();
                cachedRectTransformSet = true;
            }

            var finalData  = default(LeanTooltipData);
            var finalPoint = default(Vector2);

            switch (activation)
            {
            case ActivationType.HoverOrPress:
            {
                if (HoverShow == true)
                {
                    finalData  = HoverData;
                    finalPoint = HoverPointer.position;
                }
            }
            break;

            case ActivationType.Hover:
            {
                if (HoverShow == true && PressShow == false)
                {
                    finalData  = HoverData;
                    finalPoint = HoverPointer.position;
                }
            }
            break;

            case ActivationType.Press:
            {
                if (PressShow == true && HoverShow == true && HoverData == PressData)
                {
                    finalData  = PressData;
                    finalPoint = PressPointer.position;
                }
            }
            break;
            }

            if (tooltip != finalData)
            {
                currentDelay = 0.0f;
                tooltip      = finalData;
                shown        = false;

                Hide();
            }

            if (tooltip != null)
            {
                currentDelay += Time.unscaledDeltaTime;

                if (currentDelay >= showDelay)
                {
                    if (shown == false)
                    {
                        Show();
                    }

                    cachedRectTransform.position = finalPoint;
                }
            }

            if (boundary != BoundaryType.None)
            {
                cachedRectTransform.GetWorldCorners(corners);

                var min = Vector2.Min(corners[0], Vector2.Min(corners[1], Vector2.Min(corners[2], corners[3])));
                var max = Vector2.Max(corners[0], Vector2.Max(corners[1], Vector2.Max(corners[2], corners[3])));

                if (boundary == BoundaryType.Pivot)
                {
                    var pivot = cachedRectTransform.pivot;

                    if (min.x < 0.0f)
                    {
                        pivot.x = 0.0f;
                    }
                    else if (max.x > Screen.width)
                    {
                        pivot.x = 1.0f;
                    }
                    if (min.y < 0.0f)
                    {
                        pivot.y = 0.0f;
                    }
                    else if (max.y > Screen.height)
                    {
                        pivot.y = 1.0f;
                    }

                    cachedRectTransform.pivot = pivot;
                }

                if (boundary == BoundaryType.Position)
                {
                    var position = cachedRectTransform.position;

                    if (min.x < 0.0f)
                    {
                        position.x -= min.x;
                    }
                    else if (max.x > Screen.width)
                    {
                        position.x -= max.x - Screen.width;
                    }
                    if (min.y < 0.0f)
                    {
                        position.y -= min.y;
                    }
                    else if (max.y > Screen.height)
                    {
                        position.y -= max.y - Screen.height;
                    }

                    cachedRectTransform.position = position;
                }
            }
        }
コード例 #2
0
        protected virtual void Update()
        {
            if (cachedRectTransformSet == false)
            {
                cachedRectTransform    = GetComponent <RectTransform>();
                cachedRectTransformSet = true;
            }

            var finalData = CurrentShow == true ? CurrentData : null;

            if (tooltip != finalData)
            {
                currentDelay = 0.0f;
                tooltip      = finalData;
                shown        = false;

                Hide();
            }

            if (tooltip != null)
            {
                currentDelay += Time.unscaledDeltaTime;

                if (currentDelay >= showDelay)
                {
                    if (shown == false)
                    {
                        Show();
                    }

                    if (CurrentPointer != null)
                    {
                        cachedRectTransform.position = CurrentPointer.position;
                    }
                }
            }

            if (boundary != BoundaryType.None)
            {
                cachedRectTransform.GetWorldCorners(corners);

                var min = Vector2.Min(corners[0], Vector2.Min(corners[1], Vector2.Min(corners[2], corners[3])));
                var max = Vector2.Max(corners[0], Vector2.Max(corners[1], Vector2.Max(corners[2], corners[3])));

                if (boundary == BoundaryType.Pivot)
                {
                    var pivot = cachedRectTransform.pivot;

                    if (min.x < 0.0f)
                    {
                        pivot.x = 0.0f;
                    }
                    else if (max.x > Screen.width)
                    {
                        pivot.x = 1.0f;
                    }
                    if (min.y < 0.0f)
                    {
                        pivot.y = 0.0f;
                    }
                    else if (max.y > Screen.height)
                    {
                        pivot.y = 1.0f;
                    }

                    cachedRectTransform.pivot = pivot;
                }

                if (boundary == BoundaryType.Position)
                {
                    var position = cachedRectTransform.position;

                    if (min.x < 0.0f)
                    {
                        position.x -= min.x;
                    }
                    else if (max.x > Screen.width)
                    {
                        position.x -= max.x - Screen.width;
                    }
                    if (min.y < 0.0f)
                    {
                        position.y -= min.y;
                    }
                    else if (max.y > Screen.height)
                    {
                        position.y -= max.y - Screen.height;
                    }

                    cachedRectTransform.position = position;
                }
            }
        }