93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
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)
|
|
// {
|
|
// WDebug.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);
|
|
}
|
|
}
|
|
|
|
|
|
}
|