mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2024-11-27 07:47:59 +01:00
61 lines
965 B
C#
61 lines
965 B
C#
using UnityEngine;
|
|
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(Renderer))]
|
|
public class FieSortingOrder : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
[SortingLayer]
|
|
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;
|
|
}
|
|
}
|