NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/AOT/PostProcess/PostOutline/OutlineManager.cs

104 lines
2.2 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using UnityEngine;
[ExecuteInEditMode]
public class OutlineManager : MonoBehaviour
{
private static OutlineManager _instance;
public static OutlineManager instance
{
get
{
return _instance;
}
}
2023-08-22 19:08:45 +08:00
public bool m_EnableOutline = true;
public float m_SampleDistance = 0.01f;
public Color m_OutlineColor = Color.white;
public Color m_OutlineColorEnemy = Color.red;
2025-06-30 18:39:34 +08:00
public Color m_OutlineColorNeutral = Color.yellow;
2023-08-22 19:08:45 +08:00
public Camera targetCamera;
public float scaleProgress = 1f;
public Material mat1;
public Material mat1_1;
2025-06-30 18:39:34 +08:00
public Material mat1_2;
public Material mat2;
public Material mat3;
public int layerTeamSelf = 16;
public int layerTeamEnemy = 17;
2025-06-30 18:39:34 +08:00
public int layerTeamNeutral = 18;
public int troopIdSelf = 0;
public int troopIdEnemy = 1;
public int troopIdNeutral = 2;
2023-08-22 19:08:45 +08:00
// Start is called before the first frame update
void OnEnable()
{
_instance = this;
2023-08-22 19:08:45 +08:00
}
2025-06-30 18:39:34 +08:00
private int _GetLayerByTroopId(int troopId)
{
if (troopId == troopIdSelf)
{
return layerTeamSelf;
}
else if (troopId == troopIdEnemy)
{
return layerTeamEnemy;
}
else if (troopId == troopIdNeutral)
{
return layerTeamNeutral;
}
return 0;
}
2023-08-22 19:08:45 +08:00
2025-06-30 18:39:34 +08:00
public void AutoAddFromObj(GameObject obj, int troopId)
2023-08-22 19:08:45 +08:00
{
2025-06-30 18:39:34 +08:00
_SetLayer(obj, _GetLayerByTroopId(troopId));
}
private void _SetLayer(GameObject obj, int layer)
{
if (obj == null) return;
obj.layer = layer;
for (int i = 0; i < obj.transform.childCount; i++)
2023-08-22 19:08:45 +08:00
{
_SetLayer(obj.transform.GetChild(i).gameObject, layer);
2023-08-22 19:08:45 +08:00
}
}
2025-06-30 18:39:34 +08:00
public void RemoveRenderer(Renderer r)
2023-08-22 19:08:45 +08:00
{
r.gameObject.layer = 0;
2023-08-22 19:08:45 +08:00
}
2025-06-30 18:39:34 +08:00
public void AddRenderer(Renderer r, int troopId)
2023-08-22 19:08:45 +08:00
{
2025-06-30 18:39:34 +08:00
r.gameObject.layer = _GetLayerByTroopId(troopId);
2023-08-22 19:08:45 +08:00
}
private void OnDestroy()
{
2024-10-08 16:22:47 +08:00
Destroy(_instance.mat1);
Destroy(_instance.mat1_1);
Destroy(_instance.mat2);
Destroy(_instance.mat3);
_instance = null;
}
2023-08-22 19:08:45 +08:00
}