Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit 2c2025d

Browse files
committed
Changed the way the execution order is enforced
1 parent af4510e commit 2c2025d

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

ExecutionOrderAttribute/Assets/ExecutionOrderAttribute/ExecutionOrderAttribute.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
#if UNITY_EDITOR
34
using System.IO;
45
using UnityEditor;
@@ -15,35 +16,23 @@ public ExecutionOrderAttribute( int executionOrder ) {
1516
}
1617

1718
#if UNITY_EDITOR
18-
private const string PREFS_KEY = "_executionOrderUpdated";
1919
private const string PB_TITLE = "Updating Execution Order";
2020
private const string PB_MESSAGE = "Hold on to your butt, Cap'n!";
2121
private const string ERR_MESSAGE = "Unable to locate and set execution order for {0}";
2222

2323
[InitializeOnLoadMethod]
2424
private static void Execute() {
25-
if ( EditorPrefs.GetBool( PREFS_KEY, false ) ) {
26-
EditorPrefs.DeleteKey( PREFS_KEY );
27-
return;
28-
}
29-
3025
var type = typeof( ExecutionOrderAttribute );
3126
var assembly = type.Assembly;
3227
var types = assembly.GetTypes();
28+
var scripts = new Dictionary<MonoScript, ExecutionOrderAttribute>();
3329

3430
var progress = 0f;
3531
var step = 1f / types.Length;
3632

3733
foreach ( var item in types ) {
38-
var cancelled = EditorUtility.DisplayCancelableProgressBar( PB_TITLE, PB_MESSAGE, progress );
39-
progress += step;
40-
41-
if ( cancelled ) {
42-
break;
43-
}
44-
4534
var attributes = item.GetCustomAttributes( type, false );
46-
if ( attributes.Length == 0 ) continue;
35+
if ( attributes.Length != 1 ) continue;
4736
var attribute = attributes[0] as ExecutionOrderAttribute;
4837

4938
var asset = "";
@@ -66,9 +55,25 @@ private static void Execute() {
6655
}
6756

6857
var script = AssetDatabase.LoadAssetAtPath<MonoScript>( AssetDatabase.GUIDToAssetPath( asset ) );
69-
if ( MonoImporter.GetExecutionOrder( script ) != attribute.ExecutionOrder ) {
70-
MonoImporter.SetExecutionOrder( script, attribute.ExecutionOrder );
71-
EditorPrefs.SetBool( PREFS_KEY, true );
58+
scripts.Add( script, attribute );
59+
}
60+
61+
var changed = false;
62+
foreach ( var item in scripts ) {
63+
if ( MonoImporter.GetExecutionOrder( item.Key ) != item.Value.ExecutionOrder ) {
64+
changed = true;
65+
break;
66+
}
67+
}
68+
69+
if ( changed ) {
70+
foreach ( var item in scripts ) {
71+
var cancelled = EditorUtility.DisplayCancelableProgressBar( PB_TITLE, PB_MESSAGE, progress );
72+
progress += step;
73+
74+
if ( MonoImporter.GetExecutionOrder( item.Key ) != item.Value.ExecutionOrder ) {
75+
MonoImporter.SetExecutionOrder( item.Key, item.Value.ExecutionOrder );
76+
}
7277
}
7378
}
7479

0 commit comments

Comments
 (0)