Last active
April 10, 2020 18:58
-
-
Save joonjoonjoon/b9761229b826cfb31e60e67ac59e9b56 to your computer and use it in GitHub Desktop.
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; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ScriptOrder : Attribute | |
{ | |
public int order; | |
public ScriptOrder(int order) | |
{ | |
this.order = order; | |
} | |
} |
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; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
[InitializeOnLoad] | |
public class ScriptOrderManager | |
{ | |
static ScriptOrderManager() | |
{ | |
foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts()) | |
{ | |
if (monoScript.GetClass() != null) | |
{ | |
foreach (var a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(ScriptOrder))) | |
{ | |
var currentOrder = MonoImporter.GetExecutionOrder(monoScript); | |
var newOrder = ((ScriptOrder)a).order; | |
if (currentOrder != newOrder) | |
MonoImporter.SetExecutionOrder(monoScript, newOrder); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[DefaultExecutionOrder(100)]
https://forum.unity.com/threads/undocumented-but-public-defaultexecutionorder-attribute.530618/