Unity Easy performant outline高亮插件中没有高亮闪烁的功能,如何去简单的添加一个闪烁的功能

这是一个Unity脚本,用于管理游戏对象的高亮效果。它包含`OutlinableManager`类,提供静态方法来开启、关闭高亮以及闪烁效果,使用了`DOTween`库进行颜色过渡动画,并能为没有`Outlinable`组件的游戏对象添加该组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*
 *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;
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值