36 lines
867 B
C#
36 lines
867 B
C#
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace UVC.Edit
|
|
{
|
|
[RequireComponent(typeof(Renderer))]
|
|
public class OutlineEffect : MonoBehaviour
|
|
{
|
|
[SerializeField] private Material _outlineMaterial;
|
|
private Renderer _renderer;
|
|
private bool _isOutlined = false;
|
|
|
|
void Awake()
|
|
{
|
|
_renderer = GetComponent<Renderer>();
|
|
}
|
|
|
|
public void SetOutline(bool visible)
|
|
{
|
|
if (_isOutlined == visible) return;
|
|
|
|
_isOutlined = visible;
|
|
var materials = _renderer.sharedMaterials.ToList();
|
|
if (_isOutlined)
|
|
{
|
|
materials.Add(_outlineMaterial);
|
|
}
|
|
else
|
|
{
|
|
materials.Remove(_outlineMaterial);
|
|
}
|
|
_renderer.materials = materials.ToArray();
|
|
}
|
|
}
|
|
}
|