holopy3/Assets/Normal/Realtime/Utility/Editor/ExecutionOrderManager.cs
2020-12-10 15:25:12 +01:00

27 lines
1,000 B
C#

using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
namespace Normal.Utility {
[InitializeOnLoad]
public class ExecutionOrderManager {
static ExecutionOrderManager() {
ConfigureExecutionOrder();
}
static void ConfigureExecutionOrder() {
foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts()) {
if (monoScript.GetClass() != null) {
foreach (ExecutionOrder attribute in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(ExecutionOrder))) {
var currentExecutionOrder = MonoImporter.GetExecutionOrder(monoScript);
var desiredExecutionOrder = attribute.order;
if (currentExecutionOrder != desiredExecutionOrder)
MonoImporter.SetExecutionOrder(monoScript, desiredExecutionOrder);
}
}
}
}
}
}