Created
January 22, 2022 10:17
-
-
Save No3371/a96fb5f1ea36e7a87f684f519df924e5 to your computer and use it in GitHub Desktop.
Reorder GameObjects to enable batching for UGUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class UIReorderer : MonoBehaviour | |
| { | |
| [Tooltip("The gameobjects get reordered accoring to this. Disable this cause no side effect.")] | |
| public GameObject[] order; | |
| [Tooltip("These are always lower then order[].")] | |
| public GameObject[] baseInsert; | |
| public bool destroyOnReordered; | |
| void Start () | |
| { | |
| for (var i = 0; i < order.Length; i++) | |
| { | |
| if (order[i] == null) continue; | |
| order[i].transform.SetParent(this.transform, true); | |
| order[i].transform.SetAsLastSibling(); | |
| } | |
| for (var i = 0; i < baseInsert.Length; i++) | |
| { | |
| if (baseInsert[i] == null) continue; | |
| baseInsert[i].transform.SetParent(this.transform, true); | |
| baseInsert[i].transform.SetAsFirstSibling(); | |
| } | |
| if (Application.isPlaying && destroyOnReordered) Destroy(this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment