Skip to content

Instantly share code, notes, and snippets.

@joonjoonjoon
Last active April 10, 2020 18:58
Show Gist options
  • Save joonjoonjoon/b9761229b826cfb31e60e67ac59e9b56 to your computer and use it in GitHub Desktop.
Save joonjoonjoon/b9761229b826cfb31e60e67ac59e9b56 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using UnityEngine;
public class ScriptOrder : Attribute
{
public int order;
public ScriptOrder(int order)
{
this.order = order;
}
}
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);
}
}
}
}
}
@belzecue
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment