11using System ;
22using System . Collections . Generic ;
33using System . IO ;
4+ using JetBrains . Annotations ;
45using UnityEditor ;
56using UnityEditor . Callbacks ;
67using UnityEditor . Compilation ;
@@ -151,10 +152,10 @@ protected void RemoveItemAtIndex(int selectedIndex)
151152 {
152153 SerializedProperty selectedProperty = reorderableList . serializedProperty . GetArrayElementAtIndex ( selectedIndex ) ;
153154 Object asset = selectedProperty . objectReferenceValue ;
154- AssetDatabase . DeleteAsset ( AssetDatabase . GetAssetPath ( asset ) ) ;
155- AssetDatabase . SaveAssets ( ) ;
156155 reorderableList . serializedProperty . DeleteArrayElementAtIndex ( selectedIndex ) ;
157156 reorderableList . serializedProperty . serializedObject . ApplyModifiedProperties ( ) ;
157+ AssetDatabase . DeleteAsset ( AssetDatabase . GetAssetPath ( asset ) ) ;
158+ AssetDatabase . SaveAssets ( ) ;
158159 }
159160
160161 private void OnClickToAddNewItem ( Rect buttonRect , ReorderableList list )
@@ -239,6 +240,7 @@ private void DrawCollectionItemAtIndex(Rect rect, int index, bool isActive, bool
239240 AssetDatabaseUtils . RenameAsset ( collectionItemSerializedProperty . objectReferenceValue , newName ) ;
240241 AssetDatabase . SaveAssets ( ) ;
241242 }
243+ return ;
242244 }
243245 }
244246
@@ -468,7 +470,9 @@ public override void OnInspectorGUI()
468470 {
469471 DrawSearchField ( ) ;
470472 DrawSynchronizeButton ( ) ;
473+
471474 reorderableList . DoLayoutList ( ) ;
475+
472476 if ( Event . current . type == EventType . Repaint )
473477 {
474478 reorderableListYPosition = GUILayoutUtility . GetLastRect ( ) . y ;
@@ -507,15 +511,15 @@ protected virtual void SynchronizeAssets()
507511
508512 private void CheckForKeyboardShortcuts ( )
509513 {
514+ if ( Event . current . type != EventType . KeyDown )
515+ return ;
516+
510517 if ( reorderableList . index == - 1 )
511518 return ;
512519
513520 if ( ! reorderableList . HasKeyboardControl ( ) )
514521 return ;
515522
516- if ( Event . current . type == EventType . Layout || Event . current . type == EventType . Repaint )
517- return ;
518-
519523 if ( reorderableList . index > reorderableList . serializedProperty . arraySize - 1 )
520524 return ;
521525
@@ -650,7 +654,7 @@ private void AddNewItem()
650654
651655 optionsMenu . AddItem ( new GUIContent ( $ "Create New/class $NEW : { itemSubClass . Name } ") , false , ( ) =>
652656 {
653- EditorApplication . delayCall += ( ) => { AddNewItemOfType ( itemSubClass ) ; } ;
657+ EditorApplication . delayCall += ( ) => { CreateAndAddNewItemOfType ( itemSubClass ) ; } ;
654658 } ) ;
655659 }
656660 }
@@ -668,41 +672,6 @@ private void CreateAndAddNewItemOfType(Type itemSubClass)
668672 }
669673 } ) ;
670674 }
671-
672- [ DidReloadScripts ]
673- public static void AfterStaticAssemblyReload ( )
674- {
675- if ( ! IsWaitingForNewTypeBeCreated )
676- return ;
677-
678- IsWaitingForNewTypeBeCreated = false ;
679-
680- string lastGeneratedCollectionScriptPath =
681- CreateNewCollectionItemFromBaseWizard . LastGeneratedCollectionScriptPath . Value ;
682- string lastCollectionFullName = CreateNewCollectionItemFromBaseWizard . LastCollectionFullName . Value ;
683-
684- if ( string . IsNullOrEmpty ( lastGeneratedCollectionScriptPath ) )
685- return ;
686-
687- CreateNewCollectionItemFromBaseWizard . LastCollectionFullName . Value = string . Empty ;
688- CreateNewCollectionItemFromBaseWizard . LastGeneratedCollectionScriptPath . Value = string . Empty ;
689-
690- string assemblyName = CompilationPipeline . GetAssemblyNameFromScriptPath ( lastGeneratedCollectionScriptPath ) ;
691-
692- Type targetType = Type . GetType ( $ "{ lastCollectionFullName } , { assemblyName } ") ;
693-
694- if ( CollectionsRegistry . Instance . TryGetCollectionFromItemType ( targetType ,
695- out ScriptableObjectCollection collection ) )
696- {
697- Selection . activeObject = null ;
698- LAST_ADDED_COLLECTION_ITEM = collection . AddNew ( targetType ) ;
699-
700- EditorApplication . delayCall += ( ) =>
701- {
702- Selection . activeObject = collection ;
703- } ;
704- }
705- }
706675
707676 private void AddNewItemOfType ( Type targetType )
708677 {
@@ -989,5 +958,47 @@ private static bool EditGeneratorValidator(MenuCommand command)
989958 Type collectionType = command . context . GetType ( ) ;
990959 return CollectionGenerators . GetGeneratorTypeForCollection ( collectionType ) != null ;
991960 }
961+
962+
963+ class CollectionCustomEditorAssetPostProcessor : AssetPostprocessor
964+ {
965+ [ UsedImplicitly ]
966+ private static void OnPostprocessAllAssets ( string [ ] importedAssets , string [ ] deletedAssets , string [ ] movedAssets , string [ ] movedFromAssetPaths , bool didDomainReload )
967+ {
968+ if ( ! didDomainReload )
969+ return ;
970+
971+ if ( ! IsWaitingForNewTypeBeCreated )
972+ return ;
973+
974+ IsWaitingForNewTypeBeCreated = false ;
975+
976+ string lastGeneratedCollectionScriptPath =
977+ CreateNewCollectionItemFromBaseWizard . LastGeneratedCollectionScriptPath . Value ;
978+ string lastCollectionFullName = CreateNewCollectionItemFromBaseWizard . LastCollectionFullName . Value ;
979+
980+ if ( string . IsNullOrEmpty ( lastGeneratedCollectionScriptPath ) )
981+ return ;
982+
983+ CreateNewCollectionItemFromBaseWizard . LastCollectionFullName . Value = string . Empty ;
984+ CreateNewCollectionItemFromBaseWizard . LastGeneratedCollectionScriptPath . Value = string . Empty ;
985+
986+ string assemblyName = CompilationPipeline . GetAssemblyNameFromScriptPath ( lastGeneratedCollectionScriptPath ) ;
987+
988+ Type targetType = Type . GetType ( $ "{ lastCollectionFullName } , { assemblyName } ") ;
989+
990+ if ( CollectionsRegistry . Instance . TryGetCollectionFromItemType ( targetType ,
991+ out ScriptableObjectCollection collection ) )
992+ {
993+ Selection . activeObject = null ;
994+ LAST_ADDED_COLLECTION_ITEM = collection . AddNew ( targetType ) ;
995+
996+ EditorApplication . delayCall += ( ) =>
997+ {
998+ Selection . activeObject = collection ;
999+ } ;
1000+ }
1001+ }
1002+ }
9921003 }
9931004}
0 commit comments