Skip to content

Commit

Permalink
UPM release 3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
git-upm-publisher authored and starikcetin committed Nov 12, 2023
1 parent b06da5b commit 5bbf917
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),



## [3.1.3] - 2023-11-12

### Fixed
- Prevent null reference errors when addressables package is installed, but addressables settings are not initialized.



## [3.1.2] - 2023-11-12

### Fixed
Expand Down
41 changes: 39 additions & 2 deletions Editor/MapGeneratorTriggers/AddressablesChangeListener.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
#if ESR_ADDRESSABLES

using Eflatun.SceneReference.Editor.Utility;
using System.Linq;
using UnityEditor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;

namespace Eflatun.SceneReference.Editor.MapGeneratorTriggers
{
[InitializeOnLoad]
internal class AddressablesChangeListener
internal class AddressablesChangeListener : AssetPostprocessor
{
private static bool _isSubscribed;

static AddressablesChangeListener()
{
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
if (AddressableAssetSettingsDefaultObject.SettingsExists)
{
if (!_isSubscribed)
{
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
_isSubscribed = true;
}
}
else
{
EditorLogger.Warn("Addressables settings not found. Skipping subscribing to addressables changes.");
}
}

private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
if (AddressableAssetSettingsDefaultObject.SettingsExists)
{
if (!_isSubscribed)
{
EditorLogger.Debug("Found addressables settings. Subscribing to addressables changes.");
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange;
_isSubscribed = true;
}
}
else
{
if (_isSubscribed)
{
EditorLogger.Warn("Lost addressables settings. Unsubscribing from addressables changes.");
_isSubscribed = false;
}
}
}

private static void OnAddressablesChange(AddressableAssetSettings s, AddressableAssetSettings.ModificationEvent e, object o)
Expand Down
7 changes: 7 additions & 0 deletions Editor/SceneDataMapsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using JetBrains.Annotations;
using Newtonsoft.Json;
using UnityEditor;
using UnityEngine;

#if ESR_ADDRESSABLES
using UnityEditor.AddressableAssets;
Expand Down Expand Up @@ -74,6 +75,12 @@ private static void WriteSceneGuidToPathMap(Dictionary<string, string> sceneGuid
private static Dictionary<string, string> GenerateSceneGuidToAddressMap(string[] allSceneGuids)
{
#if ESR_ADDRESSABLES
if (!AddressableAssetSettingsDefaultObject.SettingsExists)
{
EditorLogger.Warn("Addressables settings not found. Skipping map generation.");
return new Dictionary<string, string>();
}

var addressableSettings = AddressableAssetSettingsDefaultObject.Settings;

var addressableSceneAssetEntries = allSceneGuids
Expand Down
9 changes: 8 additions & 1 deletion Editor/SceneReferencePropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ private void Init(SerializedProperty property)
_buildEntry = EditorBuildSettings.scenes.FirstOrDefault(x => x.guid.ToString() == _guid);

#if ESR_ADDRESSABLES
_addressableEntry = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(_guid);
if (AddressableAssetSettingsDefaultObject.SettingsExists)
{
_addressableEntry = AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(_guid);
}
else
{
_addressableEntry = null;
}
#endif // ESR_ADDRESSABLES

_optionsAttribute = fieldInfo.GetCustomAttribute<SceneReferenceOptionsAttribute>(false) ?? DefaultOptionsAttribute;
Expand Down
7 changes: 7 additions & 0 deletions Editor/Utility/EditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Eflatun.SceneReference.Exceptions;
using UnityEditor;
using UnityEngine;

#if ESR_ADDRESSABLES
using UnityEditor.AddressableAssets;
Expand Down Expand Up @@ -85,6 +86,12 @@ public static void EnableSceneInBuild(string sceneGuid)
/// </summary>
public static void AddToDefaultAddressableGroup(string sceneGuid)
{
if (!AddressableAssetSettingsDefaultObject.SettingsExists)
{
EditorLogger.Warn("Addressables settings not found. Skipping adding to group.");
return;
}

var defaultGroup = AddressableAssetSettingsDefaultObject.Settings.DefaultGroup;
AddressableAssetSettingsDefaultObject.Settings.CreateOrMoveEntry(sceneGuid, defaultGroup);
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ openupm add com.eflatun.scenereference

### With Git URL

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.
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.

```json
"com.eflatun.scenereference": "git+https://github.com/starikcetin/Eflatun.SceneReference.git#3.1.2"
"com.eflatun.scenereference": "git+https://github.com/starikcetin/Eflatun.SceneReference.git#3.1.3"
```

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

## Ignore Auto-Generated Map Files in Version Control

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.eflatun.scenereference",
"version": "3.1.2",
"version": "3.1.3",
"displayName": "Eflatun.SceneReference",
"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",
"documentationUrl": "https://github.com/starikcetin/Eflatun.SceneReference/blob/main/README.md",
Expand Down

0 comments on commit 5bbf917

Please sign in to comment.