예제 #1
0
    private void Iniciar()
    {
        eventSystem       = FindObjectOfType <EventSystem>();
        tooltipController = FindObjectOfType <STController>();

        // Add a new tooltip prefab if one does not exist yet
        if (!tooltipController)
        {
            tooltipController = AddTooltipPrefabToScene();
        }
        if (!tooltipController)
        {
            Debug.LogWarning("Could not find the Tooltip prefab");
            Debug.LogWarning("Make sure you don't have any other prefabs named `SimpleTooltip`");
        }

        if (GetComponent <RectTransform>())
        {
            isUIObject = true;
        }

        // Always make sure there's a style loaded
        if (!simpleTooltipStyle)
        {
            simpleTooltipStyle = Resources.Load <SimpleTooltipStyle>("STDefault");
        }
    }
예제 #2
0
    private void Reset()
    {
        // Load the default style if none is specified
        if (!simpleTooltipStyle)
        {
            simpleTooltipStyle = Resources.Load <SimpleTooltipStyle>("STDefault");
        }

        // If UI, nothing else needs to be done
        if (GetComponent <RectTransform>())
        {
            return;
        }

        // If has a collider, nothing else needs to be done
        if (GetComponent <Collider>())
        {
            return;
        }

        // There were no colliders found when the component is added so we'll add a box collider by default
        // If you are making a 2D game you can change this to a BoxCollider2D for convenience
        // You can obviously still swap it manually in the editor but this should speed up development
        gameObject.AddComponent <BoxCollider>();
    }
예제 #3
0
    private void Awake()
    {
        eventSystem = FindObjectOfType <EventSystem>();

        if (GetComponent <RectTransform>())
        {
            isUIObject = true;
        }

        // Always make sure there's a style loaded
        if (!simpleTooltipStyle)
        {
            simpleTooltipStyle = Resources.Load <SimpleTooltipStyle>("STDefault");
        }
    }
예제 #4
0
    public void SetCustomStyledText(string text, SimpleTooltipStyle style, TextAlign align = TextAlign.Left)
    {
        // Update the panel sprite and color
        panel.sprite = style.slicedSprite;
        panel.color  = style.color;

        // Update the font asset, size and default color
        toolTipTextLeft.font   = style.fontAsset;
        toolTipTextLeft.color  = style.defaultColor;
        toolTipTextRight.font  = style.fontAsset;
        toolTipTextRight.color = style.defaultColor;

        // Convert all tags to TMPro markup
        var styles = style.fontStyles;

        for (int i = 0; i < styles.Length; i++)
        {
            string addTags = "</b></i></u></s>";
            addTags += "<color=#" + ColorToHex(styles[i].color) + ">";
            if (styles[i].bold)
            {
                addTags += "<b>";
            }
            if (styles[i].italic)
            {
                addTags += "<i>";
            }
            if (styles[i].underline)
            {
                addTags += "<u>";
            }
            if (styles[i].strikethrough)
            {
                addTags += "<s>";
            }
            text = text.Replace(styles[i].tag, addTags);
        }
        if (align == TextAlign.Left)
        {
            toolTipTextLeft.text = text;
        }
        if (align == TextAlign.Right)
        {
            toolTipTextRight.text = text;
        }
        ResetWidth();
        ResizeToMatchText();
    }