/*
*FileName: OutlinableManager.cs
*Author: MinTao
*Date: 2022/03/10 16:23:33
*UnityVersion: 2020.3.0f1c1
*Description: 高亮管理脚本
*/
using DG.Tweening;
using EPOOutline;
using UnityEngine;
public static class OutlinableManager
{
public static Color defColor = Color.yellow;
private static Outlinable GetOutlinable(GameObject obj)
{
if (obj == null)
{
return null;
}
Outlinable outlinable = obj.GetComponent<Outlinable>();
if (outlinable == null)
{
outlinable = obj.AddComponent<Outlinable>();
outlinable.AddAllChildRenderersToRenderingList();
}
return outlinable;
}
public static void OutlinableOn(this GameObject model)
{
model.OutlinableOn(defColor);
}
public static void OutlinableOn(this GameObject model, Color color)
{
Outlinable outlinable = GetOutlinable(model);
if (outlinable != null)
{
outlinable.enabled = true;
outlinable.OutlineParameters.Color = color;
}
}
public static void OutlinableOff(this GameObject model)
{
Outlinable outlinable = GetOutlinable(model);
if (outlinable != null)
{
outlinable.enabled = false;
}
}
public static void FlashingOn(this GameObject model, Color color, float duration, int loop = -1)
{
model.FlashingOn(defColor, color, duration, loop);
}
public static void FlashingOn(this GameObject model, Color benginColor, Color endColor, float duration,
int loop = -1)
{
Outlinable outlinable = GetOutlinable(model);
if (outlinable != null)
{
outlinable.enabled = true;
outlinable.OutlineParameters.Color = benginColor;
var tweener = DOTween.To(() => outlinable.OutlineParameters.Color,
x => outlinable.OutlineParameters.Color = x, endColor, duration);
tweener.SetLoops(loop, LoopType.Yoyo);
tweener.SetOptions(false).SetTarget(outlinable.OutlineParameters);
}
}
public static void FlashingOff(this GameObject model)
{
Outlinable outlinable = GetOutlinable(model);
if (outlinable != null)
{
DOTween.Kill(outlinable, false);
outlinable.enabled = false;
}
}
}
Unity Easy performant outline高亮插件中没有高亮闪烁的功能,如何去简单的添加一个闪烁的功能
于 2022-03-17 14:06:30 首次发布