Skip to content

Commit b7e7e02

Browse files
april-roszkowskiEvergreen
authored andcommitted
[Port][6000.4][UUM-131564] Fix NullReferenceException when using custom preview mesh in Shader Graph
1 parent ec8a2ea commit b7e7e02

9 files changed

Lines changed: 59 additions & 11 deletions

Packages/com.unity.shadergraph/Editor/Drawing/Inspector/MasterPreviewView.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public VisualElement preview
4242
}
4343

4444
List<string> m_DoNotShowPrimitives = new List<string>(new string[] { PrimitiveType.Plane.ToString() });
45-
static Type s_ObjectSelector = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypesOrNothing()).FirstOrDefault(t => t.FullName == "UnityEditor.ObjectSelector");
4645

4746
public string assetName
4847
{
@@ -154,12 +153,6 @@ void ChangeMesh(Mesh mesh)
154153
m_Graph.previewData.serializedMesh.mesh = changedMesh;
155154
}
156155

157-
private static EditorWindow Get()
158-
{
159-
PropertyInfo P = s_ObjectSelector.GetProperty("get", BindingFlags.Public | BindingFlags.Static);
160-
return P.GetValue(null, null) as EditorWindow;
161-
}
162-
163156
void OnMeshChanged(Object obj)
164157
{
165158
var mesh = obj as Mesh;
@@ -178,9 +171,7 @@ void ChangeMeshSprite()
178171

179172
void ChangeMeshCustom()
180173
{
181-
var ShowMethod = s_ObjectSelector.GetMethod("Show", BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(UnityEngine.Object), typeof(Type), typeof(UnityEngine.Object), typeof(bool), typeof(List<int>), typeof(Action<UnityEngine.Object>), typeof(Action<UnityEngine.Object>), typeof(bool) }, new ParameterModifier[8]);
182-
m_PreviousMesh = m_Graph.previewData.serializedMesh.mesh;
183-
ShowMethod.Invoke(Get(), new object[] { null, typeof(Mesh), null, false, null, (Action<Object>)OnMeshChanged, (Action<Object>)OnMeshChanged, false });
174+
InternalBridge.ObjectSelector.Show(null, typeof(Mesh), null, false, null, (Action<Object>)OnMeshChanged, (Action<Object>)OnMeshChanged, false);
184175
}
185176

186177
void OnGeometryChanged(GeometryChangedEvent evt)

Packages/com.unity.shadergraph/Editor/InternalBridge.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
using System.Runtime.CompilerServices;
2+
3+
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor")]

Packages/com.unity.shadergraph/Editor/InternalBridge/AssemblyInfo.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Collections.Generic;
2+
using System;
3+
using UnityEngine;
4+
5+
namespace UnityEditor.ShaderGraph.InternalBridge
6+
{
7+
internal static class ObjectSelector
8+
{
9+
public static void Show(UnityEngine.Object obj, Type requiredType, UnityEngine.Object objectBeingEdited,
10+
bool allowSceneObjects, List<EntityId> allowedEntityIds = null,
11+
Action<UnityEngine.Object> onObjectSelectorClosed = null,
12+
Action<UnityEngine.Object> onObjectSelectedUpdated = null, bool showNoneItem = true)
13+
{
14+
UnityEditor.ObjectSelector.get.Show(obj, requiredType, objectBeingEdited, allowSceneObjects,
15+
allowedEntityIds, onObjectSelectorClosed, onObjectSelectedUpdated, showNoneItem);
16+
}
17+
}
18+
}

Packages/com.unity.shadergraph/Editor/InternalBridge/ObjectSelector.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Unity.InternalAPIEditorBridge.ShaderGraph.Editor",
3+
"rootNamespace": "",
4+
"references": [],
5+
"includePlatforms": [
6+
"Editor"
7+
],
8+
"excludePlatforms": [],
9+
"allowUnsafeCode": false,
10+
"overrideReferences": false,
11+
"precompiledReferences": [],
12+
"autoReferenced": true,
13+
"defineConstraints": [],
14+
"versionDefines": [],
15+
"noEngineReferences": false
16+
}

Packages/com.unity.shadergraph/Editor/InternalBridge/Unity.InternalAPIEditorBridge.ShaderGraph.Editor.asmdef.meta

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

Packages/com.unity.shadergraph/Editor/Unity.ShaderGraph.Editor.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"GUID:ade7125e800904674ba0c115208f7ed5",
66
"GUID:4988cf9794f41d64c884876ab6574b89",
77
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
8-
"GUID:3eae0364be2026648bf74846acb8a731"
8+
"GUID:3eae0364be2026648bf74846acb8a731",
9+
"GUID:1a9e721432c3e5048950da7f3cf524e7"
910
],
1011
"includePlatforms": [
1112
"Editor"

0 commit comments

Comments
 (0)