[Technical accumulation] The SQL language in Mysql is equivalent to using generic functions to save type information [Technical] [6]

1. What is the Outline component?

The Outline component is a special effects component in Unity UGUI, used to add stroke effects to UI elements. By setting the color, width, and blur of the stroke, you can make UI elements more visually prominent.

2. How the Outline component works

The Outline component achieves the stroke effect by drawing multiple identical UI elements around UI elements and setting different colors and sizes. The width and blur of the stroke can be controlled by adjusting parameters.

3. Common properties of the Outline component

  • Effect Color : The color of the stroke.
  • Effect Distance : The distance of the stroke, which can be set to a positive or negative value.
  • Use Graphic Alpha : Whether to use the transparency of UI elements as the transparency of the stroke.
  • Blur : The degree of blur of the stroke.
  • Outline : The width of the stroke.

4. Common functions of the Outline component

  • ModifyMesh : Modify the mesh of UI elements and use it to draw stroke effects.

5. Complete example code

Example 1: Add a red stroke to a button

using UnityEngine;
using UnityEngine.UI;

public class Example1 : MonoBehaviour
{
    public Button button;
    public Outline outline;

    void Start()
    {
        outline.effectColor = Color.red;
        outline.effectDistance = new Vector2(2, -2);
        outline.useGraphicAlpha = true;
        outline.blur = 0;
        outline.outline = 5;
    }
}

Steps:

  1. Create a button and mount the Example1 script to the button.
  2. Drag the button's Outline component onto the outline variable of the Example1 script.
  3. In the Start function, set the attributes of the outline, including effectColor, effectDistance, useGraphicAlpha, blur and outline.

Precautions:

  • You can adjust the stroke's color, distance, transparency, blur, and width as needed.

Example 2: Add a blue stroke to text

using UnityEngine;
using UnityEngine.UI;

public class Example2 : MonoBehaviour
{
    public Text text;
    public Outline outline;

    void Start()
    {
        outline.effectColor = Color.blue;
        outline.effectDistance = new Vector2(1, -1);
        outline.useGraphicAlpha = true;
        outline.blur = 0;
        outline.outline = 3;
    }
}

Steps:

  1. Create a text object and mount the Example2 script to the text object.
  2. Drag the Outline component of the text object onto the outline variable of the Example2 script.
  3. In the Start function, set the attributes of the outline, including effectColor, effectDistance, useGraphicAlpha, blur and outline.

Precautions:

  • You can adjust the stroke's color, distance, transparency, blur, and width as needed.

Example 3: Add a green stroke to an image

using UnityEngine;
using UnityEngine.UI;

public class Example3 : MonoBehaviour
{
    public Image image;
    public Outline outline;

    void Start()
    {
        outline.effectColor = Color.green;
        outline.effectDistance = new Vector2(3, -3);
        outline.useGraphicAlpha = true;
        outline.blur = 0;
        outline.outline = 7;
    }
}

Steps:

  1. Create a picture object and mount the Example3 script to the picture object.
  2. Drag the Outline component of the picture object onto the outline variable of the Example3 script.
  3. In the Start function, set the attributes of the outline, including effectColor, effectDistance, useGraphicAlpha, blur and outline.

Precautions:

  • You can adjust the stroke's color, distance, transparency, blur, and width as needed.

Example 4: Add a yellow stroke to the slider

using UnityEngine;
using UnityEngine.UI;

public class Example4 : MonoBehaviour
{
    public Slider slider;
    public Outline outline;

    void Start()
    {
        outline.effectColor = Color.yellow;
        outline.effectDistance = new Vector2(2, -2);
        outline.useGraphicAlpha = true;
        outline.blur = 0;
        outline.outline = 5;
    }
}

Steps:

  1. Create a slider object and mount the Example4 script to the slider object.
  2. Drag the Outline component of the slider object onto the outline variable of the Example4 script.
  3. In the Start function, set the attributes of the outline, including effectColor, effectDistance, useGraphicAlpha, blur and outline.

Precautions:

  • You can adjust the stroke's color, distance, transparency, blur, and width as needed.

Example 5: Add a purple stroke to the input box

using UnityEngine;
using UnityEngine.UI;

public class Example5 : MonoBehaviour
{
    public InputField inputField;
    public Outline outline;

    void Start()
    {
        outline.effectColor = Color.magenta;
        outline.effectDistance = new Vector2(1, -1);
        outline.useGraphicAlpha = true;
        outline.blur = 0;
        outline.outline = 3;
    }
}

Steps:

  1. Create an input box object and mount the Example5 script to the input box object.
  2. Drag the Outline component of the input box object onto the outline variable of the Example5 script.
  3. In the Start function, set the attributes of the outline, including effectColor, effectDistance, useGraphicAlpha, blur and outline.

Precautions:

  • You can adjust the stroke's color, distance, transparency, blur, and width as needed.

Guess you like

Origin blog.csdn.net/udisi658996666/article/details/132673141