-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13a17e7
commit 31028ed
Showing
68 changed files
with
1,586 additions
and
448 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#if ESR_ADDRESSABLES | ||
|
||
using UnityEditor; | ||
using UnityEditor.AddressableAssets; | ||
using UnityEditor.AddressableAssets.Settings; | ||
|
||
namespace Eflatun.SceneReference.Editor.MapGeneratorTriggers | ||
{ | ||
[InitializeOnLoad] | ||
internal class AddressablesChangeListener | ||
{ | ||
static AddressablesChangeListener() | ||
{ | ||
AddressableAssetSettingsDefaultObject.Settings.OnModification += OnAddressablesChange; | ||
} | ||
|
||
private static void OnAddressablesChange(AddressableAssetSettings s, AddressableAssetSettings.ModificationEvent e, object o) | ||
{ | ||
if (e == AddressableAssetSettings.ModificationEvent.EntryAdded || | ||
e == AddressableAssetSettings.ModificationEvent.EntryRemoved || | ||
e == AddressableAssetSettings.ModificationEvent.EntryModified || | ||
e == AddressableAssetSettings.ModificationEvent.EntryMoved || | ||
e == AddressableAssetSettings.ModificationEvent.EntryCreated) | ||
{ | ||
if (SettingsManager.SceneDataMaps.IsGenerationTriggerEnabled(SceneDataMapsGeneratorTriggers.AfterAddressablesChange)) | ||
{ | ||
SceneDataMapsGenerator.Run(); | ||
} | ||
else | ||
{ | ||
Logger.Warn($"Skipping scene data maps generation after addressables changes. It is recommended to enable map generation after addressables changes, as an outdated map can result in broken scene references in runtime. You can enable it in {SettingsManager.SettingsMenuPathForDisplay}."); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#endif // ESR_ADDRESSABLES |
3 changes: 3 additions & 0 deletions
3
Editor/MapGeneratorTriggers/AddressablesChangeListener.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using UnityEditor; | ||
using UnityEditor.PackageManager; | ||
|
||
// TODO: run the generator only if there is a change in the packages we are interested in. | ||
|
||
namespace Eflatun.SceneReference.Editor.MapGeneratorTriggers | ||
{ | ||
[InitializeOnLoad] | ||
internal static class PackagesChangeListener | ||
{ | ||
static PackagesChangeListener() | ||
{ | ||
UnityEditor.PackageManager.Events.registeredPackages += OnRegisteredPackages; | ||
} | ||
|
||
private static void OnRegisteredPackages(PackageRegistrationEventArgs obj) | ||
{ | ||
if (SettingsManager.SceneDataMaps.IsGenerationTriggerEnabled(SceneDataMapsGeneratorTriggers.AfterPackagesResolve)) | ||
{ | ||
SceneDataMapsGenerator.Run(); | ||
} | ||
else | ||
{ | ||
Logger.Warn($"Skipping scene data maps generation after packages resolve. It is recommended to enable map generation after packages resolve, as an outdated map can result in broken scene references in runtime. You can enable it in {SettingsManager.SettingsMenuPathForDisplay}."); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using Newtonsoft.Json; | ||
using UnityEditor; | ||
|
||
#if ESR_ADDRESSABLES | ||
using UnityEditor.AddressableAssets; | ||
#endif // ESR_ADDRESSABLES | ||
|
||
namespace Eflatun.SceneReference.Editor | ||
{ | ||
/// <summary> | ||
/// Generates and writes the scene data maps. | ||
/// </summary> | ||
[PublicAPI] | ||
public static class SceneDataMapsGenerator | ||
{ | ||
private const string DotKeepFileContent = "Add this file to version control. See for explanation: https://stackoverflow.com/a/17929518/6301627"; | ||
|
||
/// <summary> | ||
/// Runs the generator. | ||
/// </summary> | ||
/// <remarks> | ||
/// The menu item "Tools/Eflatun/Scene Reference/Generate Scene Data Maps" executes this method. | ||
/// </remarks> | ||
[MenuItem("Tools/" + Constants.MenuPrefixBase + "/Generate Scene Data Maps", priority = -3130)] | ||
public static void Run() | ||
{ | ||
try | ||
{ | ||
Logger.Debug("Generating scene data maps."); | ||
|
||
WriteScaffolding(); | ||
|
||
var allSceneGuids = AssetDatabase.FindAssets("t:Scene"); | ||
|
||
var sceneGuidToPathMap = GenerateSceneGuidToPathMap(allSceneGuids); | ||
WriteSceneGuidToPathMap(sceneGuidToPathMap); | ||
|
||
var sceneGuidToAddressMap = GenerateSceneGuidToAddressMap(allSceneGuids); | ||
WriteSceneGuidToAddressMap(sceneGuidToAddressMap); | ||
} | ||
finally | ||
{ | ||
AssetDatabase.Refresh(); | ||
} | ||
} | ||
|
||
private static void WriteScaffolding() | ||
{ | ||
Directory.CreateDirectory(Paths.Absolute.SceneDataMapsFolder.PlatformPath); | ||
File.WriteAllText(Paths.Absolute.SceneDataMapsDotKeepFile.PlatformPath, DotKeepFileContent); | ||
} | ||
|
||
private static Dictionary<string, string> GenerateSceneGuidToPathMap(string[] allSceneGuids) | ||
{ | ||
var sceneGuidToPathMap = allSceneGuids.ToDictionary( | ||
x => x, // key generator: take guids | ||
AssetDatabase.GUIDToAssetPath // value generator: take paths | ||
); | ||
return sceneGuidToPathMap; | ||
} | ||
|
||
private static void WriteSceneGuidToPathMap(Dictionary<string, string> sceneGuidToPathMap) | ||
{ | ||
var jsonRaw = JsonConvert.SerializeObject(sceneGuidToPathMap, SettingsManager.SceneDataMaps.JsonFormatting.value); | ||
File.WriteAllText(Paths.Absolute.SceneGuidToPathMapFile.PlatformPath, jsonRaw); | ||
|
||
SceneGuidToPathMapProvider.DirectAssign(sceneGuidToPathMap); | ||
} | ||
|
||
private static Dictionary<string, string> GenerateSceneGuidToAddressMap(string[] allSceneGuids) | ||
{ | ||
#if ESR_ADDRESSABLES | ||
var addressableSettings = AddressableAssetSettingsDefaultObject.Settings; | ||
|
||
var addressableSceneAssetEntries = allSceneGuids | ||
.Select(addressableSettings.FindAssetEntry) | ||
.Where(x => x != null); | ||
|
||
var sceneGuidToAddressMap = addressableSceneAssetEntries.ToDictionary( | ||
x => x.guid, // key generator: take guids | ||
x => x.address // value generator: take addresses | ||
); | ||
|
||
return sceneGuidToAddressMap; | ||
#else // ESR_ADDRESSABLES | ||
return new Dictionary<string, string>(); | ||
#endif // ESR_ADDRESSABLES | ||
} | ||
|
||
private static void WriteSceneGuidToAddressMap(Dictionary<string, string> sceneGuidToAddressMap) | ||
{ | ||
var jsonRaw = JsonConvert.SerializeObject(sceneGuidToAddressMap, SettingsManager.SceneDataMaps.JsonFormatting.value); | ||
File.WriteAllText(Paths.Absolute.SceneGuidToAddressMapFile.PlatformPath, jsonRaw); | ||
|
||
SceneGuidToAddressMapProvider.DirectAssign(sceneGuidToAddressMap); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.