66using UnityEditor ;
77using UnityEngine ;
88
9- namespace Entitas . Migration . Unity . Editor {
10-
11- public class MigrationWindow : EditorWindow {
12-
9+ namespace Entitas . Migration . Unity . Editor
10+ {
11+ public class MigrationWindow : EditorWindow
12+ {
1313 [ MenuItem ( "Tools/Entitas/Migrate..." , false , 1000 ) ]
14- public static void OpenMigrate ( ) {
15- EditorLayout
16- . GetWindow < MigrationWindow > ( "Entitas Migration - " + CheckForUpdates . GetLocalVersion ( ) , new Vector2 ( 415f , 564 ) )
17- . Show ( ) ;
14+ public static void OpenMigrate ( )
15+ {
16+ var window = GetWindow < MigrationWindow > ( true , "Entitas Migration - " + CheckForUpdates . GetLocalVersion ( ) ) ;
17+ window . minSize = new Vector2 ( 415f , 564 ) ;
18+ window . Show ( ) ;
1819 }
1920
2021 Texture2D _headerTexture ;
2122 IMigration [ ] _migrations ;
2223 bool [ ] _showMigration ;
2324 Vector2 _scrollViewPosition ;
2425
25- void OnEnable ( ) {
26+ void OnEnable ( )
27+ {
2628 _headerTexture = EditorLayout . LoadTexture ( "l:EntitasHeader" ) ;
2729 _migrations = getMigrations ( ) ;
2830 _showMigration = new bool [ _migrations . Length ] ;
2931 _showMigration [ 0 ] = true ;
3032 }
3133
32- static IMigration [ ] getMigrations ( ) {
34+ static IMigration [ ] getMigrations ( )
35+ {
3336 return AppDomain . CurrentDomain
3437 . GetInstancesOf < IMigration > ( )
3538 . OrderByDescending ( instance => instance . GetType ( ) . FullName )
3639 . ToArray ( ) ;
3740 }
3841
39- void OnGUI ( ) {
42+ void OnGUI ( )
43+ {
4044 _scrollViewPosition = EditorGUILayout . BeginScrollView ( _scrollViewPosition ) ;
4145 {
4246 EditorLayout . DrawTexture ( _headerTexture ) ;
4347
4448 var descriptionStyle = new GUIStyle ( GUI . skin . label ) ;
4549 descriptionStyle . wordWrap = true ;
46- for ( int i = 0 ; i < _migrations . Length ; i ++ ) {
50+ for ( int i = 0 ; i < _migrations . Length ; i ++ )
51+ {
4752 var migration = _migrations [ i ] ;
4853 _showMigration [ i ] = EditorLayout . DrawSectionHeaderToggle ( migration . version , _showMigration [ i ] ) ;
49- if ( _showMigration [ i ] ) {
54+ if ( _showMigration [ i ] )
55+ {
5056 EditorLayout . BeginSectionContent ( ) ;
5157 {
5258 EditorGUILayout . LabelField ( migration . description , descriptionStyle ) ;
53- if ( GUILayout . Button ( "Apply migration " + migration . version ) ) {
59+ if ( GUILayout . Button ( "Apply migration " + migration . version ) )
60+ {
5461 migrate ( migration , this ) ;
5562 }
5663 }
@@ -61,15 +68,17 @@ void OnGUI() {
6168 EditorGUILayout . EndScrollView ( ) ;
6269 }
6370
64- static void migrate ( IMigration migration , MigrationWindow window ) {
71+ static void migrate ( IMigration migration , MigrationWindow window )
72+ {
6573 var shouldMigrate = EditorUtility . DisplayDialog ( "Migrate" ,
6674 "You are about to migrate your source files. " +
6775 "Make sure that you have committed your current project or that you have a backup of your project before you proceed." ,
6876 "I have a backup - Migrate" ,
6977 "Cancel"
7078 ) ;
7179
72- if ( shouldMigrate ) {
80+ if ( shouldMigrate )
81+ {
7382 window . Close ( ) ;
7483 EditorUtility . DisplayDialog ( "Migrate" ,
7584 "Please select the folder, " + migration . workingDirectory + "." ,
@@ -78,14 +87,18 @@ static void migrate(IMigration migration, MigrationWindow window) {
7887
7988 var path = "Assets/" ;
8089 path = EditorUtility . OpenFolderPanel ( migration . version + ": " + migration . workingDirectory , path , string . Empty ) ;
81- if ( ! string . IsNullOrEmpty ( path ) ) {
90+ if ( ! string . IsNullOrEmpty ( path ) )
91+ {
8292 var changedFiles = migration . Migrate ( path ) ;
8393 Debug . Log ( "Applying " + migration . version ) ;
84- foreach ( var file in changedFiles ) {
94+ foreach ( var file in changedFiles )
95+ {
8596 MigrationUtils . WriteFiles ( changedFiles ) ;
8697 Debug . Log ( "Migrated " + file . fileName ) ;
8798 }
88- } else {
99+ }
100+ else
101+ {
89102 throw new Exception ( "Could not complete migration! Selected path was invalid!" ) ;
90103 }
91104 }
0 commit comments