Skip to content

Commit 0421747

Browse files
git-upm-publisherstarikcetin
authored andcommitted
UPM release 3.2.1
1 parent cae84cb commit 0421747

File tree

9 files changed

+122
-107
lines changed

9 files changed

+122
-107
lines changed

CHANGELOG.md

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

2020

2121

22+
## [3.2.1] - 2023-12-27
23+
24+
### Fixed
25+
- Prevent `Scene GUID to path map file not found!` errors and null reference exceptions in `SceneAssetPostprocessor` if the scene GUID to path map file is missing.
26+
- Prevent null reference exceptions at project launch due to addressables settings not being loaded yet.
27+
- Ensure map files are always generated at editor startup, even if they are empty.
28+
29+
30+
2231
## [3.2.0] - 2023-11-20
2332

2433
### Added

Editor/MapGeneratorTriggers/AddressablesChangeListener.cs

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

3-
using Eflatun.SceneReference.Editor.Utility;
4-
using System.Linq;
53
using UnityEditor;
6-
using UnityEditor.AddressableAssets;
74
using UnityEditor.AddressableAssets.Settings;
8-
using UnityEngine;
95

106
namespace Eflatun.SceneReference.Editor.MapGeneratorTriggers
117
{
128
[InitializeOnLoad]
139
internal class AddressablesChangeListener : AssetPostprocessor
1410
{
15-
private static bool _isSubscribed;
16-
1711
static AddressablesChangeListener()
1812
{
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-
}
13+
AddressableAssetSettings.OnModificationGlobal += OnAddressablesChange;
5214
}
5315

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

Editor/MapGeneratorTriggers/SceneAssetPostprocessor.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System.Collections.Generic;
2+
using System.Linq;
23
using Eflatun.SceneReference.Editor.Utility;
34
using UnityEditor;
45

@@ -8,9 +9,7 @@ internal class SceneAssetPostprocessor : AssetPostprocessor
89
{
910
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
1011
{
11-
var createdAssets = importedAssets.Except(SceneGuidToPathMapProvider.SceneGuidToPathMap.Values);
12-
13-
var hasSceneChange = createdAssets
12+
var hasSceneChange = GetCreatedAssets(importedAssets)
1413
.Concat(deletedAssets)
1514
.Concat(movedAssets)
1615
.Concat(movedFromAssetPaths)
@@ -28,5 +27,12 @@ private static void OnPostprocessAllAssets(string[] importedAssets, string[] del
2827
}
2928
}
3029
}
30+
31+
private static IEnumerable<string> GetCreatedAssets(string[] importedAssets)
32+
{
33+
// If we don't have a map, then we should treat all imported assets as created assets.
34+
var sceneGuidToPathMap = SceneGuidToPathMapProvider.GetSceneGuidToPathMap(false);
35+
return sceneGuidToPathMap == null ? importedAssets : importedAssets.Except(sceneGuidToPathMap.Values);
36+
}
3137
}
3238
}

Editor/ScaffoldingEnsurer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using UnityEditor;
2+
3+
namespace Eflatun.SceneReference.Editor.Packages.com.eflatun.scenereference.Editor
4+
{
5+
internal class ScaffoldingEnsurer : AssetPostprocessor
6+
{
7+
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
8+
{
9+
SceneDataMapsGenerator.EnsureScaffolding();
10+
}
11+
}
12+
}

Editor/ScaffoldingEnsurer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/SceneDataMapsGenerator.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using Newtonsoft.Json;
66
using UnityEditor;
77
using UnityEngine;
8+
using System;
9+
using UnityEngine.Scripting;
810

911
#if ESR_ADDRESSABLES
1012
using UnityEditor.AddressableAssets;
@@ -33,7 +35,7 @@ public static void Run()
3335
{
3436
EditorLogger.Debug("Generating scene data maps.");
3537

36-
WriteScaffolding();
38+
EnsureScaffolding();
3739

3840
var allSceneGuids = AssetDatabase.FindAssets("t:Scene");
3941

@@ -49,10 +51,22 @@ public static void Run()
4951
}
5052
}
5153

52-
private static void WriteScaffolding()
54+
internal static void EnsureScaffolding()
5355
{
5456
Directory.CreateDirectory(Paths.Absolute.SceneDataMapsFolder.PlatformPath);
5557
File.WriteAllText(Paths.Absolute.SceneDataMapsDotKeepFile.PlatformPath, DotKeepFileContent);
58+
59+
if (!File.Exists(Paths.Absolute.SceneGuidToPathMapFile.PlatformPath))
60+
{
61+
File.WriteAllText(Paths.Absolute.SceneGuidToPathMapFile.PlatformPath, "{}");
62+
}
63+
64+
#if ESR_ADDRESSABLES
65+
if (!File.Exists(Paths.Absolute.SceneGuidToAddressMapFile.PlatformPath))
66+
{
67+
File.WriteAllText(Paths.Absolute.SceneGuidToAddressMapFile.PlatformPath, "{}");
68+
}
69+
#endif // ESR_ADDRESSABLES
5670
}
5771

5872
private static Dictionary<string, string> GenerateSceneGuidToPathMap(string[] allSceneGuids)

0 commit comments

Comments
 (0)