Skip to content

Commit

Permalink
feat: add API to return the original renderer for a proxy (#481)
Browse files Browse the repository at this point in the history
Closes: #466
  • Loading branch information
bdunderscore authored Nov 28, 2024
1 parent 8212db6 commit 47b8ae9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#473] Added `BuildContext.SetEnableUVDistributionRecalculation` to allow opting out from the automatic call to
`Mesh.RecalculateUVDistributionMetrics` on generated meshes.
- [#478] Added `ProfilerScope` API
- [#481] Added `NDMFPreview.GetOriginalObjectForProxy`
- [#480] Added `IExtensionContext.Owner` API. Setting this property will allow errors to be correctly attributed to the
plugin that contains an extension context.
- [#479] Added `IAssetSaver` and `SerializationScope` APIs.
Expand Down
25 changes: 24 additions & 1 deletion Editor/PreviewSystem/NDMFPreview.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
using JetBrains.Annotations;
#nullable enable

using System.Collections.Immutable;
using JetBrains.Annotations;
using nadena.dev.ndmf.preview.UI;
using nadena.dev.ndmf.ui;
using UnityEditor;
using UnityEngine;

namespace nadena.dev.ndmf.preview
{
/// <summary>
/// General utilities for controlling the NDMF preview system.
/// </summary>
[PublicAPI]
// ReSharper disable once InconsistentNaming
public static class NDMFPreview
{
Expand Down Expand Up @@ -93,5 +98,23 @@ internal static void ForceResetPreview()
{
_globalPreviewSession.ForceRebuild();
}

/// <summary>
/// If the given game object is a preview proxy object, returns the original object that the proxy was created
/// for.
/// </summary>
/// <param name="proxy">The suspected proxy object</param>
/// <returns>The original object, or null if the given object is not a proxy</returns>
public static GameObject? GetOriginalObjectForProxy(GameObject proxy)
{
var sess = PreviewSession.Current;

if (sess == null)
{
return null;
}

return sess.ProxyToOriginalObject.GetValueOrDefault(proxy);
}
}
}

0 comments on commit 47b8ae9

Please sign in to comment.