Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/OutlineGlowRenderer.cs
2026-02-21 16:45:37 +08:00

153 lines
2.7 KiB
C#

using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("Chickenlord/Outline Glow Renderer")]
public class OutlineGlowRenderer : MonoBehaviour
{
public bool DrawOutline = true;
public bool IncludeChildMeshes;
public GameObject glowObject;
public Color OutlineColor = Color.cyan;
public int ObjectBlurSteps = 2;
public float ObjectBlurSpread = 0.6f;
public float ObjectOutlineStrength = 3f;
private bool ICMT;
private int myID = -1;
private int previousLayer;
public int childCounter;
public float renderDistance = -1f;
private List<int> childLayers;
private void Update()
{
if (myID == -1)
{
OutlineGlowEffectScript instance = OutlineGlowEffectScript.Instance;
if (instance != null)
{
myID = instance.AddRenderer(this);
}
}
}
private void OnEnable()
{
if (glowObject == null)
{
glowObject = base.gameObject;
}
if (myID == -1)
{
try
{
myID = OutlineGlowEffectScript.Instance.AddRenderer(this);
return;
}
catch
{
return;
}
}
Debug.LogWarning("OutlineGlowRenderer enabled, although id is already/still assigned. Shouldn't happen.");
}
private void OnDisable()
{
if (myID != -1)
{
OutlineGlowEffectScript.Instance.RemoveRenderer(myID);
myID = -1;
childLayers = null;
}
}
public void UpdateDistance()
{
if (!(renderDistance < 0f) && !(Camera.current == null))
{
Vector3 position = Camera.current.transform.position;
float sqrMagnitude = (base.gameObject.transform.position - position).sqrMagnitude;
DrawOutline = sqrMagnitude < renderDistance;
}
}
public void SetLayer(int layer)
{
previousLayer = base.gameObject.layer;
ICMT = IncludeChildMeshes;
if (!DrawOutline || !base.enabled)
{
return;
}
if (ICMT)
{
if (childLayers == null)
{
childLayers = new List<int>();
}
else
{
childLayers.Clear();
}
SetLayerRecursive(base.transform, layer);
}
else
{
glowObject.layer = layer;
}
}
public void ResetLayer()
{
childCounter = 0;
glowObject.layer = previousLayer;
if (ICMT)
{
ResetLayerRecursive(base.transform);
}
}
private void SetLayerRecursive(Transform trans, int layer)
{
if (childLayers != null)
{
childLayers.Add(trans.gameObject.layer);
trans.gameObject.layer = layer;
for (int i = 0; i < trans.childCount; i++)
{
SetLayerRecursive(trans.GetChild(i), layer);
}
}
}
private void ResetLayerRecursive(Transform trans)
{
if (childLayers != null)
{
trans.gameObject.layer = childLayers[childCounter];
childCounter++;
for (int i = 0; i < trans.childCount; i++)
{
ResetLayerRecursive(trans.GetChild(i));
}
}
}
public void TurnOff()
{
ObjectOutlineStrength = 0f;
}
}