Skip to content

Commit 215c96d

Browse files
arttu-peltonenEvergreen
authored andcommitted
Remove asmref usage in SRP samples
Currently in Unity 6, asmref files are sometimes used to bypass assembly visibility rules. In the future, asmref is no longer allowed so the current usage must be removed (see [RFC](https://docs.google.com/document/d/1SWAG19Ns5gnmbVl4WD-HT0f4DO2UVdiRj_YhX1o7J7E/edit#heading=h.9tfgs0fpr1tb)). This PR solves the sub-task [Remove asmref usage in SRP samples](https://jira.unity3d.com/browse/XPIPELINE-918), part of the broader task [XPIPELINE-904](https://jira.unity3d.com/browse/XPIPELINE-904) to completely remove asmref usage from SRP code. Asmref usage in this PR originated from the need to access HDRenderPipelineUI types, in order to display configuration UI to edit which settings an individual sample needs to be enabled. The asmref files are now removed, and instead the `HighDefition.Editor` assembly does a single `[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Samples.Common.Editor")]` call to allow the editor code of HDRP Sample to access HDRP Editor internal types. In addition, asmdef files inside Core/HDRP Samples have been restrucuted and renamed to be more consistent with SRP naming conventions. The asmdef files are either "Runtime" or "Editor" assemblies, and the "Runtime" assemblies are not allowed to reference "Editor" assemblies. The new structure is displayed below: ![image](https://media.github.cds.internal.unity3d.com/user/3380/files/a59ed94f-d7de-438d-b465-38490d01059b) Finally, I took an opportunity to replace some reflection code in the samples with a simpler callback. This PR is a follow-up to earlier PR https://github.cds.internal.unity3d.com/unity/unity/pull/47596.
1 parent dd446a2 commit 215c96d

24 files changed

+90
-84
lines changed

Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/Editor/SamplesShowcaseEditor.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,21 +170,18 @@ public override VisualElement CreateInspectorGUI()
170170
var settingButton = new Button(
171171
() =>
172172
{
173-
if (string.IsNullOrEmpty(setting.editorAssemblyName) || string.IsNullOrEmpty(setting.editorClassName) || string.IsNullOrEmpty(setting.editorShowFunctionName))
173+
if (RequiredSettingBase.showSettingCallback != null)
174174
{
175-
SettingsService.OpenProjectSettings(setting.projectSettingsPath);
176-
CoreEditorUtils.Highlight("Project Settings", setting.propertyPath, HighlightSearchMode.Identifier);
175+
RequiredSettingBase.showSettingCallback(setting);
177176
}
178177
else
179178
{
180-
var editorAssembly = Assembly.Load(setting.editorAssemblyName);
181-
var editorClass = editorAssembly.GetType(setting.editorClassName);
182-
editorClass.GetMethod(setting.editorShowFunctionName).Invoke(null, new[] { setting });
179+
SettingsService.OpenProjectSettings(setting.projectSettingsPath);
180+
CoreEditorUtils.Highlight("Project Settings", setting.propertyPath, HighlightSearchMode.Identifier);
183181
}
184182
})
185183
{
186-
text = setting.name,
187-
184+
text = setting.name
188185
};
189186

190187
string description = setting.description;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "Unity.RenderPipelines.Core.Samples.Editor",
3+
"rootNamespace": "",
4+
"references": [
5+
"Unity.RenderPipelines.Core.Runtime",
6+
"Unity.RenderPipelines.Core.Editor",
7+
"Unity.RenderPipelines.Core.Samples.Runtime",
8+
"Unity.TextMeshPro",
9+
"Unity.InputSystem"
10+
],
11+
"includePlatforms": [
12+
"Editor"
13+
],
14+
"excludePlatforms": [],
15+
"allowUnsafeCode": false,
16+
"overrideReferences": true,
17+
"precompiledReferences": [],
18+
"autoReferenced": true,
19+
"defineConstraints": [],
20+
"versionDefines": [
21+
{
22+
"name": "com.unity.inputsystem",
23+
"expression": "1.0.0",
24+
"define": "INPUT_SYSTEM_INSTALLED"
25+
}
26+
],
27+
"noEngineReferences": false
28+
}

Packages/com.unity.render-pipelines.core/Samples~/CoreSamples.asmdef.meta renamed to Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/Editor/Unity.RenderPipelines.Core.Samples.Editor.asmdef.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/RequiredSettings/CoreRP_Runtime_Ref.asmref

Lines changed: 0 additions & 3 deletions
This file was deleted.

Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/RequiredSettings/CoreRP_Runtime_Ref.asmref.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if UNITY_EDITOR
22

3+
using System;
34
using System.Collections;
45
using System.Collections.Generic;
56
using UnityEngine;
@@ -12,11 +13,6 @@ public interface IRequiredSetting
1213
public bool state { get; }
1314
public string name { get; }
1415
public string description { get; }
15-
16-
// Following properties are required to store informations to call editor functions using reflection
17-
public string editorAssemblyName { get; }
18-
public string editorClassName { get; }
19-
public string editorShowFunctionName { get; }
2016
}
2117
}
2218
#endif

Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/RequiredSettings/RequiredSettingBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if UNITY_EDITOR
2+
using System;
23
using System.Collections;
34
using System.Collections.Generic;
45
using UnityEditor.Rendering;
@@ -45,10 +46,8 @@ private string[] m_propertyPathHierarchy
4546
}
4647

4748
public virtual string projectSettingsPath { get; }
48-
49-
public virtual string editorAssemblyName => null;
50-
public virtual string editorClassName => null;
51-
public virtual string editorShowFunctionName => null;
49+
50+
public static Action<RequiredSettingBase> showSettingCallback { get; set; } = null;
5251

5352
public virtual SerializedProperty property
5453
{

Packages/com.unity.render-pipelines.core/Samples~/Common/Scripts/CoreSamplesCommon.asmdef renamed to Packages/com.unity.render-pipelines.core/Samples~/Common/Unity.RenderPipelines.Core.Samples.Runtime.asmdef

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
{
2-
"name": "CoreSamplesCommon",
2+
"name": "Unity.RenderPipelines.Core.Samples.Runtime",
33
"rootNamespace": "",
44
"references": [
5-
"GUID:6055be8ebefd69e48b49212b09b47b2f",
6-
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
7-
"GUID:3eae0364be2026648bf74846acb8a731",
8-
"GUID:75469ad4d38634e559750d17036d5f7c"
5+
"Unity.TextMeshPro",
6+
"Unity.RenderPipelines.Core.Runtime",
7+
"Unity.InputSystem"
98
],
109
"includePlatforms": [],
1110
"excludePlatforms": [],
@@ -22,4 +21,4 @@
2221
}
2322
],
2423
"noEngineReferences": false
25-
}
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Runtime.CompilerServices;
22

3+
[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Samples.Common.Editor")]
34
[assembly: InternalsVisibleTo("Unity.RenderPipelines.HighDefinition.Editor.Tests")]
45
[assembly: InternalsVisibleTo("Unity.Industrial.Materials.AVRD.Editor")]
56
[assembly: InternalsVisibleTo("Unity.TextMeshPro.Editor")]

0 commit comments

Comments
 (0)