86 lines
1.7 KiB
C#
86 lines
1.7 KiB
C#
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
public class OutlineManager : MonoBehaviour
|
|
{
|
|
|
|
private static OutlineManager _instance;
|
|
|
|
public static OutlineManager instance
|
|
{
|
|
get
|
|
{
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
public bool m_EnableOutline = true;
|
|
|
|
public float m_SampleDistance = 0.01f;
|
|
|
|
public Color m_OutlineColor = Color.white;
|
|
|
|
public Color m_OutlineColorEnemy = Color.red;
|
|
|
|
public Camera targetCamera;
|
|
|
|
public float scaleProgress = 1f;
|
|
|
|
public Material mat1;
|
|
public Material mat1_1;
|
|
public Material mat2;
|
|
public Material mat3;
|
|
|
|
public int layerTeamSelf = 16;
|
|
public int layerTeamEnemy = 17;
|
|
|
|
// Start is called before the first frame update
|
|
void OnEnable()
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
public void AutoAddFromObj(GameObject obj, bool isEnemy)
|
|
{
|
|
_SetLayer(obj, isEnemy ? layerTeamEnemy : layerTeamSelf);
|
|
}
|
|
|
|
private void _SetLayer(GameObject obj, int layer)
|
|
{
|
|
if (obj == null) return;
|
|
obj.layer = layer;
|
|
for (int i = 0; i < obj.transform.childCount; i++)
|
|
{
|
|
_SetLayer(obj.transform.GetChild(i).gameObject, layer);
|
|
}
|
|
}
|
|
|
|
public void RemoveRenderer(Renderer r, bool isEnemy)
|
|
{
|
|
r.gameObject.layer = 0;
|
|
}
|
|
|
|
public void AddRenderer(Renderer r, bool isEnemy)
|
|
{
|
|
if (isEnemy)
|
|
{
|
|
r.gameObject.layer = layerTeamEnemy;
|
|
}
|
|
else
|
|
{
|
|
r.gameObject.layer = layerTeamSelf;
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
|
|
Destroy(_instance.mat1);
|
|
Destroy(_instance.mat1_1);
|
|
Destroy(_instance.mat2);
|
|
Destroy(_instance.mat3);
|
|
|
|
_instance = null;
|
|
}
|
|
}
|