123456789101112131415161718192021222324252627282930313233343536373839404142 |
- //==========================================================
- //
- // Copyright (c) Guangzhou Shixiang Technology Co.,Ltd.
- // All rights reserved.
- //
- //==========================================================
- using System;
- using UnityEditor;
- namespace GxrSdk.Editor
- {
- /// <summary>
- /// 脚本自定义次序管理类
- /// 该脚本在场景启动或更新时执行,以便确定自定义脚本的执行次序
- /// </summary>
- [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);
- }
- }
- }
- }
- }
- }
- }
|