1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
#if UNITY_EDITOR
3
4
using System . IO ;
4
5
using UnityEditor ;
@@ -15,35 +16,23 @@ public ExecutionOrderAttribute( int executionOrder ) {
15
16
}
16
17
17
18
#if UNITY_EDITOR
18
- private const string PREFS_KEY = "_executionOrderUpdated" ;
19
19
private const string PB_TITLE = "Updating Execution Order" ;
20
20
private const string PB_MESSAGE = "Hold on to your butt, Cap'n!" ;
21
21
private const string ERR_MESSAGE = "Unable to locate and set execution order for {0}" ;
22
22
23
23
[ InitializeOnLoadMethod ]
24
24
private static void Execute ( ) {
25
- if ( EditorPrefs . GetBool ( PREFS_KEY , false ) ) {
26
- EditorPrefs . DeleteKey ( PREFS_KEY ) ;
27
- return ;
28
- }
29
-
30
25
var type = typeof ( ExecutionOrderAttribute ) ;
31
26
var assembly = type . Assembly ;
32
27
var types = assembly . GetTypes ( ) ;
28
+ var scripts = new Dictionary < MonoScript , ExecutionOrderAttribute > ( ) ;
33
29
34
30
var progress = 0f ;
35
31
var step = 1f / types . Length ;
36
32
37
33
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
-
45
34
var attributes = item . GetCustomAttributes ( type , false ) ;
46
- if ( attributes . Length == 0 ) continue ;
35
+ if ( attributes . Length != 1 ) continue ;
47
36
var attribute = attributes [ 0 ] as ExecutionOrderAttribute ;
48
37
49
38
var asset = "" ;
@@ -66,9 +55,25 @@ private static void Execute() {
66
55
}
67
56
68
57
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
+ }
72
77
}
73
78
}
74
79
0 commit comments