Skip to content

Commit 1e7cf58

Browse files
committed
fix: ordering
1 parent 3e81317 commit 1e7cf58

2 files changed

Lines changed: 69 additions & 44 deletions

File tree

Scripts/Editor/CustomEditors/CollectionCustomEditor.cs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using JetBrains.Annotations;
45
using UnityEditor;
56
using UnityEditor.Callbacks;
67
using 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
}

Scripts/Editor/EditorWindows/CreateCollectionWizard.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using JetBrains.Annotations;
56
using UnityEditor;
67
using UnityEditor.Callbacks;
78
using UnityEditor.Compilation;
@@ -604,7 +605,7 @@ private void CreateNewCollection()
604605
AssetDatabase.Refresh();
605606

606607
if (!scriptsGenerated)
607-
OnAfterScriptsReloading();
608+
AfterScriptsAreReady();
608609
}
609610

610611
private void CreateIndirectAccess()
@@ -710,8 +711,7 @@ private bool CheckValidityOfSettings()
710711
return isValid;
711712
}
712713

713-
[DidReloadScripts]
714-
static void OnAfterScriptsReloading()
714+
private static void AfterScriptsAreReady()
715715
{
716716
if (!WaitingRecompileForContinue.Value)
717717
return;
@@ -735,5 +735,19 @@ static void OnAfterScriptsReloading()
735735
AssetDatabase.SaveAssets();
736736
AssetDatabase.Refresh();
737737
}
738+
739+
740+
class CollectionCustomEditorAssetPostProcessor : AssetPostprocessor
741+
{
742+
[UsedImplicitly]
743+
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths,
744+
bool didDomainReload)
745+
{
746+
if (!didDomainReload)
747+
return;
748+
749+
AfterScriptsAreReady();
750+
}
751+
}
738752
}
739753
}

0 commit comments

Comments
 (0)