Skip to content

Commit 6430bb6

Browse files
authored
Merge pull request #139 from brunomikoski/feature/fix-unity-2022-3
Feature/fix unity 2022 3
2 parents f71a598 + f673c04 commit 6430bb6

File tree

4 files changed

+77
-45
lines changed

4 files changed

+77
-45
lines changed

CHANGELOG.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.2.3]
10+
### Fixes
11+
- `[SOCItemEditorOptions]` now has the option to limit the displayed items to the collection selected in a given field using the ConstrainToCollectionField parameter.
12+
- `[SOCItemEditorOptions]` now has the option to fire a callback when a value is selected using the OnSelectCallbackMethod parameter.
13+
- Replaced the implementation of the `[DidReloadScripts]` by the `AssetPostprocessor` to deal with importing errors on newer unity version
14+
- Fixed issue where trying to add new custom items to a collection was not showing the create custom type properly
915

1016
## [2.2.2]
1117
### Fixes
@@ -507,6 +513,7 @@ public bool IsValidConsumable(Consumable consumable)
507513
### Added
508514
- First initial working version
509515

516+
[2.2.3]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.2.3
510517
[2.2.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.2.2
511518
[2.1.0]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.1.0
512519
[2.0.9]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.0.9

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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.brunomikoski.scriptableobjectcollection",
33
"displayName": "Scriptable Object Collection",
4-
"version": "2.2.2",
4+
"version": "2.2.3",
55
"unity": "2021.2",
66
"description": "A library to help improve the usability of Unity3D Scriptable Objects by grouping them into a collection and exposing them by code or nice inspectors!",
77
"keywords": [

0 commit comments

Comments
 (0)