FiE-Game/Assets/Scripts/FieSortingOrder.cs
2023-07-25 00:52:50 +05:00

60 lines
949 B
C#

using UnityEngine;
[ExecuteInEditMode]
[RequireComponent(typeof(Renderer))]
public class FieSortingOrder : MonoBehaviour
{
[SerializeField]
private string layerName = "Default";
[SerializeField]
private int orderInLayer;
private Renderer _renderer;
public string LayerName
{
get
{
return layerName;
}
set
{
layerName = value;
Renderer[] components = GetComponents<Renderer>();
foreach (Renderer renderer in components)
{
renderer.sortingLayerName = layerName;
}
}
}
public int OrderInLayer
{
get
{
return orderInLayer;
}
set
{
orderInLayer = value;
Renderer[] components = GetComponents<Renderer>();
foreach (Renderer renderer in components)
{
renderer.sortingOrder = orderInLayer;
}
}
}
private void Awake()
{
LayerName = layerName;
OrderInLayer = orderInLayer;
}
private void OnValidate()
{
LayerName = layerName;
OrderInLayer = orderInLayer;
}
}