104 lines
2.2 KiB
C#
104 lines
2.2 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 Color m_OutlineColorNeutral = Color.yellow;
|
|
|
|
public Camera targetCamera;
|
|
|
|
public float scaleProgress = 1f;
|
|
|
|
public Material mat1;
|
|
public Material mat1_1;
|
|
public Material mat1_2;
|
|
public Material mat2;
|
|
public Material mat3;
|
|
|
|
public int layerTeamSelf = 16;
|
|
public int layerTeamEnemy = 17;
|
|
public int layerTeamNeutral = 18;
|
|
|
|
public int troopIdSelf = 0;
|
|
public int troopIdEnemy = 1;
|
|
public int troopIdNeutral = 2;
|
|
|
|
// Start is called before the first frame update
|
|
void OnEnable()
|
|
{
|
|
_instance = this;
|
|
}
|
|
|
|
private int _GetLayerByTroopId(int troopId)
|
|
{
|
|
if (troopId == troopIdSelf)
|
|
{
|
|
return layerTeamSelf;
|
|
}
|
|
else if (troopId == troopIdEnemy)
|
|
{
|
|
return layerTeamEnemy;
|
|
}
|
|
else if (troopId == troopIdNeutral)
|
|
{
|
|
return layerTeamNeutral;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public void AutoAddFromObj(GameObject obj, int troopId)
|
|
{
|
|
_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++)
|
|
{
|
|
_SetLayer(obj.transform.GetChild(i).gameObject, layer);
|
|
}
|
|
}
|
|
|
|
public void RemoveRenderer(Renderer r)
|
|
{
|
|
r.gameObject.layer = 0;
|
|
}
|
|
|
|
public void AddRenderer(Renderer r, int troopId)
|
|
{
|
|
r.gameObject.layer = _GetLayerByTroopId(troopId);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
|
|
Destroy(_instance.mat1);
|
|
Destroy(_instance.mat1_1);
|
|
Destroy(_instance.mat2);
|
|
Destroy(_instance.mat3);
|
|
|
|
_instance = null;
|
|
}
|
|
}
|