holopy3/Assets/Normal/Realtime/Utility/Editor/ExecutionOrderManager.cs

28 lines
1,000 B
C#
Raw Permalink Normal View History

2020-12-10 14:25:12 +00:00
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);
}
}
}
}
}
}