123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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;
- }
|