161 lines
3.5 KiB
C#
161 lines
3.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
//[ExecuteAlways]
|
|
public class OutLineRender : OutLineVariable
|
|
{
|
|
public Color OutLineColor=Color.blue;
|
|
[Range(0,2)]public float OutLineStrength=1;
|
|
|
|
private Renderer[] rdArray;
|
|
|
|
private bool changeValue = false;
|
|
|
|
private OutLinePam _outLinePam=new OutLinePam();
|
|
void OnEnable()
|
|
{
|
|
rdArray= GetComponentsInChildren<Renderer>();
|
|
_outLinePam.renders = rdArray;
|
|
_outLinePam.color = OutLineColor;
|
|
_outLinePam.strength = OutLineStrength;
|
|
|
|
if (OutLine.outLinePam.Contains(_outLinePam) == false)
|
|
{
|
|
|
|
OutLine.outLinePam.Add(_outLinePam);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
//[ExecuteAlways]
|
|
void Update()
|
|
{
|
|
if (_outLinePam.color != OutLineColor || _outLinePam.strength != OutLineStrength)
|
|
{
|
|
_outLinePam.color = OutLineColor;
|
|
_outLinePam.strength = OutLineStrength;
|
|
}
|
|
|
|
}
|
|
//更新物体及子物体的渲染
|
|
public void UpdateOutLine()
|
|
{
|
|
|
|
rdArray= GetComponentsInChildren<Renderer>();
|
|
_outLinePam.renders = rdArray;
|
|
}
|
|
|
|
// private void OnValidate()
|
|
// {
|
|
// if (Application.IsPlaying(this)==false || enabled==true)
|
|
// {
|
|
// Debug.Log("OnValidate");
|
|
// _outLinePam.renders = rdArray;
|
|
// _outLinePam.color = OutLineColor;
|
|
// _outLinePam.strength = OutLineStrength;
|
|
// if (RunInEditor)
|
|
// {
|
|
// if (OutLine.outLinePam.Contains(_outLinePam) == false)
|
|
// {
|
|
// _outLinePam.renders = rdArray;
|
|
// OutLine.outLinePam.Add(_outLinePam);
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// if (OutLine.outLinePam.Contains(_outLinePam))
|
|
// {
|
|
// OutLine.outLinePam.Remove(_outLinePam);
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// }
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (OutLine.outLinePam.Contains(_outLinePam))
|
|
{
|
|
OutLine.outLinePam.Remove(_outLinePam);
|
|
}
|
|
}
|
|
|
|
///闪光
|
|
public void HightOutLine() {
|
|
|
|
_sequence = OutLineAnim();
|
|
_sequence.Play().SetLoops(-1);
|
|
|
|
}
|
|
public Sequence _sequence;
|
|
///动画器
|
|
Sequence OutLineAnim() {
|
|
|
|
Sequence seq = DOTween.Sequence();
|
|
OutLineStrength = 0;
|
|
var v = DOTween.To(
|
|
|
|
() => OutLineStrength, //起始值
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
OutLineStrength=2f; //变化值
|
|
|
|
},
|
|
|
|
OutLineStrength, //终点值
|
|
|
|
0.25f) //持续时间
|
|
|
|
.SetEase(Ease.Linear) //缓动类型
|
|
|
|
.SetUpdate(true);
|
|
seq.Insert(0,v);
|
|
v = DOTween.To(
|
|
|
|
() => OutLineStrength, //起始值
|
|
|
|
x =>
|
|
|
|
{
|
|
|
|
OutLineStrength = 0; //变化值
|
|
|
|
},
|
|
|
|
OutLineStrength, //终点值
|
|
|
|
0.25f) //持续时间
|
|
|
|
.SetEase(Ease.Linear) //缓动类型
|
|
|
|
.SetUpdate(true);
|
|
seq.Insert(0.3f, v);
|
|
|
|
return seq;
|
|
}
|
|
|
|
///取消闪光
|
|
public void NoHightOutLine()
|
|
{
|
|
|
|
if (_sequence!=null)
|
|
{
|
|
_sequence.Kill();
|
|
}
|
|
OutLineStrength = 0;
|
|
|
|
}
|
|
|
|
}
|