//========================================================== // // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd. // All rights reserved. // //========================================================== using System; using UnityEditor; namespace GxrSdk.Editor { /// /// 脚本自定义次序管理类 /// 该脚本在场景启动或更新时执行,以便确定自定义脚本的执行次序 /// [InitializeOnLoad] public class GxrScriptCustomOrderManager { static GxrScriptCustomOrderManager() { MonoScript[] allScripts = MonoImporter.GetAllRuntimeMonoScripts(); foreach (var script in allScripts) { Type type = script.GetClass(); if (type != null) { Attribute[] attributes = Attribute.GetCustomAttributes(type, typeof(GxrScriptCustomOrder)); foreach (var attribute in attributes) { int oldOrder = MonoImporter.GetExecutionOrder(script); int newOrder = ((GxrScriptCustomOrder)attribute).Order; if (oldOrder != newOrder) { MonoImporter.SetExecutionOrder(script, newOrder); } } } } } } }