Skip to content

Commit

Permalink
Merge pull request #340 from De-Panther/error_no_urp
Browse files Browse the repository at this point in the history
Added error message when there's no Universal Render Pipeline package…
  • Loading branch information
De-Panther authored Jan 16, 2024
2 parents 321d65a + 6d6799b commit 8b67291
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 55 deletions.
1 change: 1 addition & 0 deletions Packages/webxr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- An option to auto-load WebXRManager on start in WebXRSettings.
- An option to auto-load WebXRInputSystem on start in WebXRSettings.
- Error message when there's no Universal Render Pipeline package in project.

## [0.20.0] - 2023-12-18
### Added
Expand Down
9 changes: 8 additions & 1 deletion Packages/webxr/Editor/WebXR.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "WebXR.Editor",
"rootNamespace": "",
"references": [
"GUID:fd4abe4ffe74ef1448afe15c6cb36bb7",
"GUID:f9fe0089ec81f4079af78eb2287a6163"
Expand All @@ -13,6 +14,12 @@
"precompiledReferences": [],
"autoReferenced": false,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "com.unity.render-pipelines.universal",
"expression": "",
"define": "HAS_URP"
}
],
"noEngineReferences": false
}
116 changes: 62 additions & 54 deletions Packages/webxr/Editor/WebXRBuildProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,46 @@ namespace WebXR
{
public class WebXRBuildProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
/// <summary>Override of <see cref="IPreprocessBuildWithReport"/> and <see cref="IPostprocessBuildWithReport"/></summary>
public int callbackOrder
{
get { return 0; }
}
/// <summary>Override of <see cref="IPreprocessBuildWithReport"/> and <see cref="IPostprocessBuildWithReport"/></summary>
public int callbackOrder
{
get { return 0; }
}

void CleanOldSettings()
{
UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
if (preloadedAssets == null)
return;
void CleanOldSettings()
{
UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
if (preloadedAssets == null)
return;

var oldSettings = from s in preloadedAssets
where s != null && s.GetType() == typeof(WebXRSettings)
select s;

if (oldSettings != null && oldSettings.Any())
{
var assets = preloadedAssets.ToList();
foreach (var s in oldSettings)
{
assets.Remove(s);
}
var oldSettings = from s in preloadedAssets
where s != null && s.GetType() == typeof(WebXRSettings)
select s;

PlayerSettings.SetPreloadedAssets(assets.ToArray());
}
if (oldSettings != null && oldSettings.Any())
{
var assets = preloadedAssets.ToList();
foreach (var s in oldSettings)
{
assets.Remove(s);
}

/// <summary>Override of <see cref="IPreprocessBuildWithReport"/></summary>
/// <param name="report">Build report.</param>
public void OnPreprocessBuild(BuildReport report)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();
PlayerSettings.SetPreloadedAssets(assets.ToArray());
}
}

if (report.summary.platform != BuildTarget.WebGL)
{
return;
}
/// <summary>Override of <see cref="IPreprocessBuildWithReport"/></summary>
/// <param name="report">Build report.</param>
public void OnPreprocessBuild(BuildReport report)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();

if (report.summary.platform != BuildTarget.WebGL)
{
return;
}

#if UNITY_2020_3 || UNITY_2021_1
if (!PlayerSettings.WebGL.emscriptenArgs.Contains("-std="))
Expand All @@ -56,28 +56,36 @@ public void OnPreprocessBuild(BuildReport report)
}
#endif

WebXRSettings settings = null;
EditorBuildSettings.TryGetConfigObject<WebXRSettings>("WebXR.Settings", out settings);
if (settings == null)
return;
WebXRSettings settings = WebXRSettings.GetSettings();
if (settings == null)
return;

UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();

if (!preloadedAssets.Contains(settings))
{
var assets = preloadedAssets.ToList();
assets.Add(settings);
PlayerSettings.SetPreloadedAssets(assets.ToArray());
}
}
if (!preloadedAssets.Contains(settings))
{
var assets = preloadedAssets.ToList();
assets.Add(settings);
PlayerSettings.SetPreloadedAssets(assets.ToArray());
}
}

/// <summary>Override of <see cref="IPostprocessBuildWithReport"/></summary>
/// <param name="report">Build report.</param>
public void OnPostprocessBuild(BuildReport report)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();
}
/// <summary>Override of <see cref="IPostprocessBuildWithReport"/></summary>
/// <param name="report">Build report.</param>
public void OnPostprocessBuild(BuildReport report)
{
// Always remember to cleanup preloaded assets after build to make sure we don't
// dirty later builds with assets that may not be needed or are out of date.
CleanOldSettings();
}

#if !HAS_URP
[InitializeOnLoadMethod]
private static void OnPostprocessAssets()
{
UnityEngine.Debug.LogError(@"WebXR Export requires Universal Render Pipeline,
using Built-in Render Pipeline might cause issues.");
}
#endif
}
}

0 comments on commit 8b67291

Please sign in to comment.