public override void OnInspectorGUI() { base.OnInspectorGUI(); if (!Application.isPlaying) { if (GUILayout.Button("刷新")) { SortingOrderHelper obj = (SortingOrderHelper)target; obj.orderList = new List <SortingOrderItem>(); if (obj != null) { //记录所有层级 Renderer[] renderers = obj.GetComponentsInChildren <Renderer>(); foreach (var renderer in renderers) { SortingOrderItem item = new SortingOrderItem(); item.renderer = renderer; item.value = renderer.sortingOrder; obj.orderList.Add(item); } } } } }
//刷新一个obj上面的层级控制器 public static void RefreshSoringOrderHelper(GameObject obj, int layerID, int baseOrder) { if (obj == null) { LogError("Refresh sorting order helper failed."); return; } SortingOrderHelper helper = obj.GetComponent <SortingOrderHelper>(); if (helper != null) { helper.RefreshOrder(layerID, baseOrder); } }