Unity simply implements model stroke Outline

final effect

Before
insert image description here
stroke After stroke
insert image description here

accomplish

Go to AssetStore, search for the free plugin Quick Outline and import it.
store link

Add Outline script to the object that needs to be stroked and enable it. Turning off the stroke can be done by disabling or removing the Outline script.

Outline script parameter
insert image description here
OutlineMode: stroke type, you can set the stroke to show all, not show the occluded part, only show the occluded part, etc.
OutlineColor: The stroke color.
OutlineWidth: Stroke width.

For details, please refer to the QuickOutline scene.
insert image description here

Example

The following is the function written in the project to display the stroke of the selected object.
Here is the use of properties for encapsulation. Build is my custom class which can be replaced with GameObject or custom class.

    private Build currentBuild;
    public Build CurrentBuild
    {
    
    
        get
        {
    
    
            return currentBuild;
        }
        set
        {
    
    
        	//如果选中为空,则隐藏当前描边
            if (!value)
            {
    
    
                HideOutline(currentBuild);
                currentBuild = value;
                return;
            }
			
			//如果选中的还是当前目标,则返回
            if(value == currentBuild)
            {
    
    
                return;
            }
            else
            {
    
    
            	//选中其他对象,关闭之前物体的描边并显示当前选中物体描边
                if(currentBuild)
                    HideOutline(currentBuild);
                ShowOutline(value);
                currentBuild = value;
            }
        }
    }
	
	//关闭描边
	void HideOutline(Build build)
    {
    
    
        build.GetComponent<Outline>().enabled = false;
    }

	//显示描边
    void ShowOutline(Build build)
    {
    
    
        if (build.GetComponent<Outline>())
        {
    
    
            build.GetComponent<Outline>().enabled = true;
        }
        else
        {
    
    
            build.gameObject.AddComponent<Outline>();
        }
    }

Guess you like

Origin blog.csdn.net/qq_39162826/article/details/121611907