@@ -14,6 +14,11 @@ internal sealed class LDtkProjectSettingsGUI
1414
1515 private readonly Action _saveAction ;
1616 private readonly SerializedProperty _internalIconsTexture ;
17+ private readonly SerializedProperty _revertOverridesInScene ;
18+
19+ private readonly GUILayoutOption _buttonWidth = GUILayout . Width ( 180 ) ;
20+ private readonly GUILayoutOption _buttonWidthSmall = GUILayout . Width ( 88.5f ) ;
21+ private readonly EditorGUIUtility . IconSizeScope _iconSizeScope = new EditorGUIUtility . IconSizeScope ( new Vector2 ( 16 , 16 ) ) ;
1722
1823 private static readonly GUIContent InternalIconsTexture = new GUIContent
1924 {
@@ -65,12 +70,25 @@ internal sealed class LDtkProjectSettingsGUI
6570 tooltip = "Reimports all tileset files" ,
6671 image = LDtkIconUtility . LoadTilesetFileIcon ( )
6772 } ;
73+ private static readonly GUIContent RevertOverridesInScene = new GUIContent
74+ {
75+ text = "Revert Overrides On Import" ,
76+ tooltip = "If enabled, then after any LDtk asset import, will attempt a prefab revert of all LDtk prefab instances in all currently loaded scenes.\n " +
77+ "This is used for when you always want to maintain an unchanged state of the imported hierarchy in the scene, because Unity's tilemaps and other various components can accidentally change without notice nor intention." ,
78+ image = LDtkIconUtility . GetUnityIcon ( "PrefabModel On" )
79+ } ;
80+ private static readonly GUIContent RevertOverridesInSceneButton = new GUIContent
81+ {
82+ text = "Revert Now" ,
83+ tooltip = "Revert all LDtk prefab instances in all loaded scenes immediately" ,
84+ } ;
6885
6986 public LDtkProjectSettingsGUI ( SerializedObject obj , Action saveAction )
7087 {
7188 _saveAction = saveAction ;
7289 _serializedObject = obj ;
7390 _internalIconsTexture = obj . FindProperty ( LDtkProjectSettings . PROPERTY_INTERAL_ICONS_TEXTURE ) ;
91+ _revertOverridesInScene = obj . FindProperty ( LDtkProjectSettings . PROPERTY_REVERT_OVERRIDES_IN_SCENE ) ;
7492 }
7593
7694 public void OnGUI ( string searchContext )
@@ -82,86 +100,97 @@ public void OnGUI(string searchContext)
82100 LDtkSettingsSwitchGUI . DrawSwitchPrefsButton ( ) ;
83101 LDtkEditorGUIUtility . DrawDivider ( ) ;
84102
85- using ( new EditorGUIUtility . IconSizeScope ( new Vector2 ( 16 , 16 ) ) )
103+ LDtkScriptingDefines . PreprocessorAddRemoveGui ( ) ;
104+
105+ using ( _iconSizeScope )
86106 {
87- LDtkScriptingDefines . PreprocessorAddRemoveGui ( ) ;
88- EditorGUILayout . PropertyField ( _internalIconsTexture , InternalIconsTexture ) ;
89-
90- if ( _internalIconsTexture . objectReferenceValue is Texture2D tex )
91- {
92- if ( tex . width != 512 || tex . height != 1024 )
93- {
94- LDtkDebug . LogWarning ( "Only assigning the internal icons texture is valid. (Needs a 512x1024 resolution)" ) ;
95- _internalIconsTexture . objectReferenceValue = null ;
96- }
97- }
107+ DrawFieldInternalIcons ( ) ;
108+ DrawRevertInstancesField ( ) ;
109+ DrawItchButtons ( ) ;
110+ LDtkEditorGUIUtility . DrawDivider ( ) ;
111+ DrawReimportAllButtons ( ) ;
98112 }
99- DrawItchButton ( ) ;
100- LDtkEditorGUIUtility . DrawDivider ( ) ;
101- DrawReimportAllButton ( ) ;
102113
103-
104114 if ( _serializedObject . ApplyModifiedPropertiesWithoutUndo ( ) )
105115 {
106116 _saveAction ? . Invoke ( ) ;
107117 }
108118 }
109119
110- private static void DrawItchButton ( )
120+ private void DrawFieldInternalIcons ( )
121+ {
122+ EditorGUILayout . PropertyField ( _internalIconsTexture , InternalIconsTexture ) ;
123+ if ( _internalIconsTexture . objectReferenceValue is Texture2D tex )
124+ {
125+ if ( tex . width != 512 || tex . height != 1024 )
126+ {
127+ LDtkDebug . LogWarning ( "Only assigning the internal icons texture is valid. (Needs a 512x1024 resolution)" ) ;
128+ _internalIconsTexture . objectReferenceValue = null ;
129+ }
130+ }
131+ }
132+
133+ private void DrawItchButtons ( )
111134 {
112135 EditorGUILayout . BeginHorizontal ( ) ;
113136 GUILayout . FlexibleSpace ( ) ;
114137
115- using ( new EditorGUIUtility . IconSizeScope ( new Vector2 ( 16 , 16 ) ) )
138+ if ( GUILayout . Button ( GithubButton , _buttonWidthSmall ) )
116139 {
117- if ( GUILayout . Button ( GithubButton , GUILayout . Width ( 89 ) ) )
118- {
119- Application . OpenURL ( GITHUB_LINK ) ;
120- }
121- if ( GUILayout . Button ( ItchButton , GUILayout . Width ( 88 ) ) )
122- {
123- Application . OpenURL ( ITCH_LINK ) ;
124- }
140+ Application . OpenURL ( GITHUB_LINK ) ;
141+ }
142+ if ( GUILayout . Button ( ItchButton , _buttonWidthSmall ) )
143+ {
144+ Application . OpenURL ( ITCH_LINK ) ;
125145 }
126146
127147 EditorGUILayout . EndHorizontal ( ) ;
128148 }
129- private static void DrawReimportAllButton ( )
149+
150+ private void DrawRevertInstancesField ( )
151+ {
152+ EditorGUILayout . BeginHorizontal ( ) ;
153+ EditorGUILayout . PropertyField ( _revertOverridesInScene , RevertOverridesInScene ) ;
154+ if ( GUILayout . Button ( RevertOverridesInSceneButton , _buttonWidth ) )
155+ {
156+ LDtkPostImportSceneAlterations . QueueRevertPrefabs ( InteractionMode . UserAction ) ;
157+ }
158+ EditorGUILayout . EndHorizontal ( ) ;
159+ }
160+
161+ private void DrawReimportAllButtons ( )
130162 {
131163 EditorGUILayout . BeginHorizontal ( ) ;
132164 GUILayout . FlexibleSpace ( ) ;
133165 EditorGUILayout . BeginVertical ( ) ;
134166
135- using ( new EditorGUIUtility . IconSizeScope ( new Vector2 ( 16 , 16 ) ) )
167+ if ( GUILayout . Button ( ReimportAllButton , _buttonWidth ) )
136168 {
137- if ( GUILayout . Button ( ReimportAllButton , GUILayout . Width ( 180 ) ) )
138- {
139- WrapInAssetEditing ( ReimportAll ) ;
140- }
141- if ( GUILayout . Button ( ReimportAllProjectsButton , GUILayout . Width ( 180 ) ) )
169+ WrapInAssetEditing ( ReimportAll ) ;
170+ }
171+ if ( GUILayout . Button ( ReimportAllProjectsButton , _buttonWidth ) )
172+ {
173+ WrapInAssetEditing ( ( ) =>
142174 {
143- WrapInAssetEditing ( ( ) =>
144- {
145- string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
146- ReimportAllFiles ( allPaths , ".ldtk" ) ;
147- } ) ;
148- }
149- if ( GUILayout . Button ( ReimportAllLevelsButton , GUILayout . Width ( 180 ) ) )
175+ string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
176+ ReimportAllFiles ( allPaths , ".ldtk" ) ;
177+ } ) ;
178+ }
179+ if ( GUILayout . Button ( ReimportAllLevelsButton , _buttonWidth ) )
180+ {
181+ WrapInAssetEditing ( ( ) =>
150182 {
151- WrapInAssetEditing ( ( ) =>
152- {
153- string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
154- ReimportAllFiles ( allPaths , ".ldtkl" ) ;
155- } ) ;
156- }
157- if ( GUILayout . Button ( ReimportAllTilesetFilesButton , GUILayout . Width ( 180 ) ) )
183+ string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
184+ ReimportAllFiles ( allPaths , ".ldtkl" ) ;
185+ } ) ;
186+ }
187+ if ( GUILayout . Button ( ReimportAllTilesetFilesButton , _buttonWidth ) )
188+ {
189+ WrapInAssetEditing ( ( ) =>
158190 {
159- WrapInAssetEditing ( ( ) =>
160- {
161- string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
162- ReimportAllFiles ( allPaths , ".ldtkt" ) ;
163- } ) ;
164- }
191+ string [ ] allPaths = AssetDatabase . GetAllAssetPaths ( ) ;
192+ ReimportAllFiles ( allPaths , ".ldtkt" ) ;
193+ } ) ;
165194 }
166195
167196 EditorGUILayout . EndVertical ( ) ;
0 commit comments