using System;
using UnityEngine;

[ExecuteInEditMode]
[RequireComponent(typeof(Renderer))]
public class SortingLayer : MonoBehaviour
{
	private void Awake()
	{
		this.LayerName = this.layerName;
		this.OrderInLayer = this.orderInLayer;
	}

	private void OnValidate()
	{
		this.LayerName = this.layerName;
		this.OrderInLayer = this.orderInLayer;
	}

	public string LayerName
	{
		get
		{
			return this.layerName;
		}
		set
		{
			this.layerName = value;
			foreach (Renderer renderer in base.GetComponents<Renderer>())
			{
				renderer.sortingLayerName = this.layerName;
			}
		}
	}

	public int OrderInLayer
	{
		get
		{
			return this.orderInLayer;
		}
		set
		{
			this.orderInLayer = value;
			foreach (Renderer renderer in base.GetComponents<Renderer>())
			{
				renderer.sortingOrder = this.orderInLayer;
			}
		}
	}

	[SerializeField]
	[SortingLayer]
	private string layerName = "Default";

	[SerializeField]
	private int orderInLayer;

	private Renderer _renderer;
}
