Skip to content

Commit 5bbf917

Browse files
git-upm-publisherstarikcetin
authored andcommitted
UPM release 3.1.3
1 parent b06da5b commit 5bbf917

File tree

7 files changed

+72
-7
lines changed

7 files changed

+72
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1919

2020

2121

22+
## [3.1.3] - 2023-11-12
23+
24+
### Fixed
25+
- Prevent null reference errors when addressables package is installed, but addressables settings are not initialized.
26+
27+
28+
2229
## [3.1.2] - 2023-11-12
2330

2431
### Fixed

Editor/MapGeneratorTriggers/AddressablesChangeListener.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,54 @@
11
#if ESR_ADDRESSABLES
22

3+
using Eflatun.SceneReference.Editor.Utility;
4+
using System.Linq;
35
using UnityEditor;
46
using UnityEditor.AddressableAssets;
57
using UnityEditor.AddressableAssets.Settings;
8+
using UnityEngine;
69

710
namespace Eflatun.SceneReference.Editor.MapGeneratorTriggers
811
{
912
[InitializeOnLoad]
10-
internal class AddressablesChangeListener
13+
internal class AddressablesChangeListener : AssetPostprocessor
1114
{
15+
private static bool _isSubscribed;
16+
1217
static AddressablesChangeListener()
1318
{
14-
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
19+
if (AddressableAssetSettingsDefaultObject.SettingsExists)
20+
{
21+
if (!_isSubscribed)
22+
{
23+
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
24+
_isSubscribed = true;
25+
}
26+
}
27+
else
28+
{
29+
EditorLogger.Warn("Addressables settings not found. Skipping subscribing to addressables changes.");
30+
}
31+
}
32+
33+
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
34+
{
35+
if (AddressableAssetSettingsDefaultObject.SettingsExists)
36+
{
37+
if (!_isSubscribed)
38+
{
39+
EditorLogger.Debug("Found addressables settings. Subscribing to addressables changes.");
40+
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
41+
_isSubscribed = true;
42+
}
43+
}
44+
else
45+
{
46+
if (_isSubscribed)
47+
{
48+
EditorLogger.Warn("Lost addressables settings. Unsubscribing from addressables changes.");
49+
_isSubscribed = false;
50+
}
51+
}
1552
}
1653

1754
private static void OnAddressablesChange(AddressableAssetSettings s, AddressableAssetSettings.ModificationEvent e, object o)

Editor/SceneDataMapsGenerator.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using JetBrains.Annotations;
55
using Newtonsoft.Json;
66
using UnityEditor;
7+
using UnityEngine;
78

89
#if ESR_ADDRESSABLES
910
using UnityEditor.AddressableAssets;
@@ -74,6 +75,12 @@ private static void WriteSceneGuidToPathMap(Dictionary<string, string> sceneGuid
7475
private static Dictionary<string, string> GenerateSceneGuidToAddressMap(string[] allSceneGuids)
7576
{
7677
#if ESR_ADDRESSABLES
78+
if (!AddressableAssetSettingsDefaultObject.SettingsExists)
79+
{
80+
EditorLogger.Warn("Addressables settings not found. Skipping map generation.");
81+
return new Dictionary<string, string>();
82+
}
83+
7784
var addressableSettings = AddressableAssetSettingsDefaultObject.Settings;
7885

7986
var addressableSceneAssetEntries = allSceneGuids

Editor/SceneReferencePropertyDrawer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,14 @@ private void Init(SerializedProperty property)
8181
_buildEntry = EditorBuildSettings.scenes.FirstOrDefault(x => x.guid.ToString() == _guid);
8282

8383
#if ESR_ADDRESSABLES
84-
_addressableEntry = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(_guid);
84+
if (AddressableAssetSettingsDefaultObject.SettingsExists)
85+
{
86+
_addressableEntry = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(_guid);
87+
}
88+
else
89+
{
90+
_addressableEntry = null;
91+
}
8592
#endif // ESR_ADDRESSABLES
8693

8794
_optionsAttribute = fieldInfo.GetCustomAttribute<SceneReferenceOptionsAttribute>(false) ?? DefaultOptionsAttribute;

Editor/Utility/EditorUtils.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using Eflatun.SceneReference.Exceptions;
55
using UnityEditor;
6+
using UnityEngine;
67

78
#if ESR_ADDRESSABLES
89
using UnityEditor.AddressableAssets;
@@ -85,6 +86,12 @@ public static void EnableSceneInBuild(string sceneGuid)
8586
/// </summary>
8687
public static void AddToDefaultAddressableGroup(string sceneGuid)
8788
{
89+
if (!AddressableAssetSettingsDefaultObject.SettingsExists)
90+
{
91+
EditorLogger.Warn("Addressables settings not found. Skipping adding to group.");
92+
return;
93+
}
94+
8895
var defaultGroup = AddressableAssetSettingsDefaultObject.Settings.DefaultGroup;
8996
AddressableAssetSettingsDefaultObject.Settings.CreateOrMoveEntry(sceneGuid, defaultGroup);
9097
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ openupm add com.eflatun.scenereference
4848

4949
### With Git URL
5050

51-
Add the following line to the `dependencies` section of your project's `manifest.json` file. Replace `3.1.2` with the version you want to install.
51+
Add the following line to the `dependencies` section of your project's `manifest.json` file. Replace `3.1.3` with the version you want to install.
5252

5353
```json
54-
"com.eflatun.scenereference": "git+https://github.com/starikcetin/Eflatun.SceneReference.git#3.1.2"
54+
"com.eflatun.scenereference": "git+https://github.com/starikcetin/Eflatun.SceneReference.git#3.1.3"
5555
```
5656

57-
_Although it is highly discouraged, you can replace `3.1.2` with `upm` to get the latest version instead of a specific one._
57+
_Although it is highly discouraged, you can replace `3.1.3` with `upm` to get the latest version instead of a specific one._
5858

5959
## Ignore Auto-Generated Map Files in Version Control
6060

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.eflatun.scenereference",
3-
"version": "3.1.2",
3+
"version": "3.1.3",
44
"displayName": "Eflatun.SceneReference",
55
"description": "Scene References for Runtime and Editor. Strongly typed, robust, and reliable. Provides Asset GUID, Scene Path, Build Index, and Scene Name.\nhttps://github.com/starikcetin/Eflatun.SceneReference",
66
"documentationUrl": "https://github.com/starikcetin/Eflatun.SceneReference/blob/main/README.md",

0 commit comments

Comments
 (0)