Skip to content

Commit 70efa34

Browse files
authored
Merge pull request #144 from brunomikoski/feature/small-fixes
Feature/small fixes
2 parents d5360e7 + b893de4 commit 70efa34

File tree

7 files changed

+40
-32
lines changed

7 files changed

+40
-32
lines changed

CHANGELOG.MD

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [2.3.2]
10+
## Added
11+
- Added tooltip for the Generate Addressables Method toggle
12+
13+
## Changed
14+
- Changed the Save method for the SOCSettings to be less expensive
15+
- Fixed issue when the Addressables Settings haven't been created yet
16+
- Organized Methods/Properties on the Collection
17+
- Bumped minimum supported version to 2022.2
18+
919
## [2.3.1]
1020
### Added
1121
- Added Addressables support again, now you if addressables is available on your project and the collection is set to non auto loaded, and the collection is set to use addressables, will write some helper code on the static file to load the collectiom from the addressables.
@@ -552,6 +562,7 @@ public bool IsValidConsumable(Consumable consumable)
552562
### Added
553563
- First initial working version
554564

565+
[2.3.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.2
555566
[2.3.1]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.1
556567
[2.3.0]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.0
557568
[2.2.4]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.2.4

Editor/UXML/CollectionCustomEditorTreeAsset.uxml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<uie:ObjectField label="Generated Scripts Folde" type="UnityEditor.DefaultAsset, UnityEditor.CoreModule" allow-scene-objects="false" name="generated-scripts-parent-folder" tooltip="Specifies the target folder for generating the static file access. If left null, the file will be generated in the same location as the original file." class="unity-base-field__aligned" />
2424
<ui:TextField picking-mode="Ignore" label="Static Filename" value="filler text" name="static-filename-textfield" is-delayed="true" class="unity-base-field__aligned" />
2525
<ui:TextField picking-mode="Ignore" label="Namespace" value="filler text" name="namespace-textfield" is-delayed="true" class="unity-base-field__aligned" />
26-
<ui:Toggle label="Generate Addressables Loading Methods" name="write-addressables-load-toggle" class="unity-base-field__aligned" />
26+
<ui:Toggle label="Generate Addressables Methods" name="write-addressables-load-toggle" tooltip="When enabled the static file file will be generated with the Asset Loading Key and with Loading/Unloading methods." class="unity-base-field__aligned" />
2727
</ui:VisualElement>
2828
<ui:VisualElement style="flex-grow: 1; flex-direction: row; height: 26px; border-top-left-radius: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; border-bottom-left-radius: 0;">
2929
<ui:Button text="Generate Static File" parse-escape-sequences="true" display-tooltip-when-elided="true" tooltip="Uses Code Generation to generate the Static File to access collection items by code." name="generate-static-file-button" style="flex-grow: 1; padding-right: 0; padding-left: -2px; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 0; padding-bottom: 0; border-bottom-right-radius: 0; border-bottom-left-radius: 4px; border-top-left-radius: 0; border-top-right-radius: 0;" />

Scripts/Editor/Core/CollectionSettings.cs

+12-17
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,10 @@ public CollectionSettings(ScriptableObjectCollection targetCollection)
5252
else
5353
StaticFilename = $"{targetCollection.GetType().Name}".FirstToUpper();
5454

55-
56-
5755
WriteAsPartialClass = canBePartial;
5856
UseBaseClassForItems = false;
5957
EnforceIndirectAccess = false;
58+
Save();
6059
}
6160

6261
public bool ShouldWriteAddressableLoadingMethods()
@@ -67,30 +66,27 @@ public bool ShouldWriteAddressableLoadingMethods()
6766
return WriteAddressableLoadingMethods;
6867
}
6968

70-
public void SetWriteAddressableLoadingMethods(bool evtNewValue)
71-
{
72-
if (WriteAddressableLoadingMethods == evtNewValue)
73-
return;
74-
75-
WriteAddressableLoadingMethods = evtNewValue;
76-
Save();
77-
}
78-
7969
public void SetImporter(AssetImporter targetImporter)
8070
{
8171
importer = targetImporter;
8272
}
8373

84-
public void Save(bool forceSave = false)
74+
public void Save()
8575
{
8676
if (importer == null)
8777
return;
8878

8979
importer.userData = EditorJsonUtility.ToJson(this);
90-
if (forceSave)
91-
{
92-
importer.SaveAndReimport();
93-
}
80+
AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);
81+
}
82+
83+
public void SetWriteAddressableLoadingMethods(bool shouldWriteAddressablesMethods)
84+
{
85+
if (WriteAddressableLoadingMethods == shouldWriteAddressablesMethods)
86+
return;
87+
88+
WriteAddressableLoadingMethods = shouldWriteAddressablesMethods;
89+
Save();
9490
}
9591

9692
public void SetEnforceIndirectAccess(bool enforceIndirectAccess)
@@ -109,7 +105,6 @@ public void SetStaticFilename(string targetNewName)
109105

110106
StaticFilename = targetNewName;
111107
Save();
112-
113108
}
114109

115110
public void SetNamespace(string targetNamespace)

Scripts/Editor/Core/SOCSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public bool GetWriteAddressableLoadingMethods(ScriptableObjectCollection collect
299299
public void SaveCollectionSettings(ScriptableObjectCollection collection, bool forceSave = false)
300300
{
301301
CollectionSettings settings = GetOrCreateCollectionSettings(collection);
302-
settings.Save(forceSave);
302+
settings.Save();
303303
}
304304
}
305305
}

Scripts/Editor/CustomEditors/CollectionCustomEditor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ private bool IsAddressableAsset(ScriptableObject target)
580580
#if ADDRESSABLES_ENABLED
581581
string assetPath = AssetDatabase.GetAssetPath(target);
582582
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
583+
if (settings == null)
584+
return false;
585+
583586
AddressableAssetEntry entry = settings.FindAssetEntry(AssetDatabase.AssetPathToGUID(assetPath));
584587
return entry != null;
585588
#else

Scripts/Runtime/Core/ScriptableObjectCollection.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ public LongGuid GUID
3535
private bool automaticallyLoaded = true;
3636
public bool AutomaticallyLoaded => automaticallyLoaded;
3737

38+
public int Count => items.Count;
39+
40+
public object SyncRoot => throw new NotSupportedException();
41+
public bool IsSynchronized => throw new NotSupportedException();
42+
43+
public bool IsFixedSize => false;
44+
public bool IsReadOnly => false;
45+
46+
public virtual bool ShouldProtectItemOrder => false;
47+
3848
public ScriptableObject this[int index]
3949
{
4050
get => items[index];
@@ -77,17 +87,6 @@ public void CopyTo(List<ScriptableObject> list)
7787
list.Add(e);
7888
}
7989
}
80-
81-
public int Count => items.Count;
82-
83-
public object SyncRoot => throw new NotSupportedException();
84-
public bool IsSynchronized => throw new NotSupportedException();
85-
86-
public bool IsFixedSize => false;
87-
public bool IsReadOnly => false;
88-
89-
public virtual bool ShouldProtectItemOrder => false;
90-
9190

9291
public int Add(object value)
9392
{

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "com.brunomikoski.scriptableobjectcollection",
33
"displayName": "Scriptable Object Collection",
4-
"version": "2.3.1",
5-
"unity": "2021.2",
4+
"version": "2.3.2",
5+
"unity": "2022.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": [
88
"scriptable object",

0 commit comments

Comments
 (0)