Skip to content

Commit ba3c75a

Browse files
RoseHirigoyenEvergreen
authored andcommitted
SRP-1077 Improve batchmode converter command line tool
1 parent 889f809 commit ba3c75a

File tree

13 files changed

+550
-162
lines changed

13 files changed

+550
-162
lines changed

Packages/com.unity.render-pipelines.universal/Editor/2D/Converter/BuiltInAndURP3DTo2DMaterialUpgrader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace UnityEditor.Rendering.Universal
88
{
99
[Serializable]
1010
[PipelineTools]
11+
[BatchModeConverterClassInfo("UpgradeURP2DAssets", "URPToReadonlyMaterial2D")]
1112
[ElementInfo(Name = "Convert Built-in and URP ( Universal Renderer ) Materials to Mesh2D-Lit-Default",
1213
Order = 300,
1314
Description = "This will upgrade/crossgrade all 3D materials and 3D material references for URP 2D.")]

Packages/com.unity.render-pipelines.universal/Editor/2D/Converter/BuiltInToURP2DReadonlyMaterialConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace UnityEditor.Rendering.Universal
1010
{
1111
[Serializable]
1212
[PipelineConverter("Built-in", "Universal Render Pipeline (2D Renderer)")]
13+
[BatchModeConverterClassInfo("BuiltInToURP2D", "ReadonlyMaterial2D")]
1314
[ElementInfo(Name = "Material Reference Converter",
1415
Order = 100,
1516
Description = "Converts references to Built-In readonly materials to URP (2D) readonly materials.")]

Packages/com.unity.render-pipelines.universal/Editor/2D/Converter/BuiltInToURP2DRenderSettingsConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace UnityEditor.Rendering.Universal
99
{
1010
[Serializable]
1111
[PipelineConverter("Built-in", "Universal Render Pipeline (2D Renderer)")]
12+
[BatchModeConverterClassInfo("BuiltInToURP2D", "RenderSettings2D")]
1213
[ElementInfo(Name = "Rendering Settings",
1314
Order = int.MinValue,
1415
Description = "This converter creates Universal Render Pipeline (URP) assets and corresponding Renderer assets, configuring their settings to match the equivalent settings from the Built-in Render Pipeline.")]

Packages/com.unity.render-pipelines.universal/Editor/2D/Converter/ParametricToFreeformLightUpgrader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public ParametricToFreeformLightUpgraderItem(GlobalObjectId gid, string assetPat
2727

2828
[Serializable]
2929
[PipelineTools]
30+
[BatchModeConverterClassInfo("UpgradeURP2DAssets", "ParametricToFreeformLight")]
3031
[ElementInfo(Name = "Parametric to Freeform Light Upgrade",
3132
Order = 100,
3233
Description = "This will upgrade all parametric lights to freeform lights.")]

Packages/com.unity.render-pipelines.universal/Editor/Converter/Converters.cs

Lines changed: 204 additions & 149 deletions
Large diffs are not rendered by default.

Packages/com.unity.render-pipelines.universal/Editor/Converter/Converters.cs.meta

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

Packages/com.unity.render-pipelines.universal/Editor/Deprecated.cs

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using System.Text;
5+
using UnityEditor.Rendering.Converter;
6+
using UnityEngine;
27

38
namespace UnityEditor.Rendering.Universal
49
{
@@ -18,4 +23,195 @@ public override void OnInspectorGUI()
1823
static partial class EditorUtils
1924
{
2025
}
26+
27+
/// <summary>
28+
/// Filter for the list of converters used in batch mode.
29+
/// </summary>
30+
/// <seealso cref="Converters.RunInBatchMode(UnityEditor.Rendering.Universal.ConverterContainerId, List{UnityEditor.Rendering.Universal.ConverterId}, UnityEditor.Rendering.Universal.ConverterFilter)"/>
31+
[Obsolete("ConverterFilter has been deprecated.", false)]
32+
33+
public enum ConverterFilter
34+
{
35+
/// <summary>
36+
/// Use this to include converters matching the filter.
37+
/// </summary>
38+
Inclusive,
39+
40+
/// <summary>
41+
/// Use this to exclude converters matching the filter.
42+
/// </summary>
43+
Exclusive
44+
}
45+
46+
/// <summary>
47+
/// The container to run in batch mode.
48+
/// </summary>
49+
/// <seealso cref="Converters.RunInBatchMode(UnityEditor.Rendering.Universal.ConverterContainerId)"/>
50+
[Obsolete("ConverterContainerId has been deprecated.", false)]
51+
public enum ConverterContainerId
52+
{
53+
/// <summary>
54+
/// Use this for Built-in to URP converter.
55+
/// </summary>
56+
BuiltInToURP,
57+
58+
/// <summary>
59+
/// Use this for Built-in to 2D (URP) converter.
60+
/// </summary>
61+
BuiltInToURP2D,
62+
63+
/// <summary>
64+
/// Use this for Built-in and 3D URP to 2D (URP) converter.
65+
/// </summary>
66+
BuiltInAndURPToURP2D,
67+
68+
/// <summary>
69+
/// Use this to upgrade 2D (URP) assets.
70+
/// </summary>
71+
UpgradeURP2DAssets,
72+
}
73+
74+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
75+
[Obsolete("BatchModeConverterInfo has been deprecated. Please use BatchModeConverterClassInfo or upgrade using UnityEditor.Rendering.Universal.Converters.RunInBatchModeCmdLine instead.", false)]
76+
internal class BatchModeConverterInfo : Attribute
77+
{
78+
public Type converterType { get; }
79+
public ConverterContainerId containerName { get; }
80+
81+
public BatchModeConverterInfo(ConverterContainerId containerName, Type converterType)
82+
{
83+
this.converterType = converterType;
84+
this.containerName = containerName;
85+
}
86+
}
87+
88+
/// <summary>
89+
/// The converter to run in batch mode.
90+
/// </summary>
91+
/// <seealso cref="Converters.RunInBatchMode(UnityEditor.Rendering.Universal.ConverterContainerId, List{UnityEditor.Rendering.Universal.ConverterId}, UnityEditor.Rendering.Universal.ConverterFilter)"/>
92+
[Obsolete("ConverterId has been deprecated. Please upgrade using UnityEditor.Rendering.Universal.Converters.RunInBatchModeCmdLine instead.", false)]
93+
public enum ConverterId
94+
{
95+
/// <summary>
96+
/// Use this for the material converters.
97+
/// </summary>
98+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP, typeof(BuiltInToURP3DMaterialUpgrader))]
99+
Material,
100+
101+
/// <summary>
102+
/// Use this for the render settings converters.
103+
/// </summary>
104+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP, typeof(BuiltInToURP3DRenderSettingsConverter))]
105+
RenderSettings,
106+
107+
/// <summary>
108+
/// Use this for the animation clip converters.
109+
/// </summary>
110+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP, typeof(AnimationClipConverter))]
111+
AnimationClip,
112+
113+
/// <summary>
114+
/// Use this for readonly material converters.
115+
/// </summary>
116+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP, typeof(BuiltInToURP3DReadonlyMaterialConverter))]
117+
ReadonlyMaterial,
118+
119+
/// <summary>
120+
/// Use this for 2D material conversion
121+
/// </summary>
122+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP2D,
123+
typeof(BuiltInToURP2DReadonlyMaterialConverter))]
124+
ReadonlyMaterial2D,
125+
126+
/// <summary>
127+
/// Use this for 2D material conversion
128+
/// </summary>
129+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP2D, typeof(BuiltInToURP2DRenderSettingsConverter))]
130+
RenderSettings2D,
131+
132+
/// <summary>
133+
/// Use this for 3D URP material conversion
134+
/// </summary>
135+
[BatchModeConverterInfo(ConverterContainerId.UpgradeURP2DAssets,
136+
typeof(BuiltInAndURP3DTo2DMaterialUpgrader))]
137+
URPToReadonlyMaterial2D,
138+
139+
#if PPV2_EXISTS
140+
/// <summary>
141+
/// Use this for post processing V2 converters.
142+
/// </summary>
143+
[BatchModeConverterInfo(ConverterContainerId.BuiltInToURP, typeof(PPv2Converter))]
144+
PPv2,
145+
#endif
146+
147+
/// <summary>
148+
/// Use this for parametric to freeform light converters.
149+
/// </summary>
150+
[BatchModeConverterInfo(ConverterContainerId.UpgradeURP2DAssets, typeof(ParametricToFreeformLightUpgrader))]
151+
ParametricToFreeformLight,
152+
}
153+
154+
public static partial class Converters
155+
{
156+
/// <summary>
157+
/// Call this method to run all the converters in a specific container in batch mode.
158+
/// </summary>
159+
/// <param name="containerName">The name of the container which will be batched. All Converters in this Container will run if prerequisites are met.</param>
160+
[Obsolete("RunInBatchMode(ConverterContainerId) has been deprecated. Please use RunInBatchMode(string) or upgrade using UnityEditor.Rendering.Universal.Converters.RunInBatchModeCmdLine instead.", false)]
161+
public static void RunInBatchMode(ConverterContainerId containerName)
162+
{
163+
RunInBatchMode(containerName, new List<ConverterId>() { }, ConverterFilter.Exclusive);
164+
}
165+
166+
[Obsolete("TryGetTypeInContainer has been deprecated. Please upgrade using UnityEditor.Rendering.Universal.Converters.RunInBatchModeCmdLine instead.", false)]
167+
static bool TryGetTypeInContainer(ConverterId value, ConverterContainerId containerName, out Type type)
168+
{
169+
type = null;
170+
var memberInfo = typeof(ConverterId).GetMember(value.ToString());
171+
if (memberInfo.Length > 0)
172+
{
173+
var attr = memberInfo[0].GetCustomAttribute<BatchModeConverterInfo>();
174+
if (attr != null)
175+
{
176+
if(attr.containerName == containerName)
177+
type = attr.converterType;
178+
}
179+
}
180+
return type != null;
181+
}
182+
183+
/// <summary>
184+
/// Call this method to run a specific list of converters in a specific container in batch mode.
185+
/// </summary>
186+
/// <param name="containerName">The name of the container which will be batched.</param>
187+
/// <param name="converterList">The list of converters that will be either included or excluded from batching. These converters need to be part of the passed in container for them to run.</param>
188+
/// <param name="converterFilter">The enum that decide if the list of converters will be included or excluded when batching.</param>
189+
[Obsolete("RunInBatchMode(ConverterContainerId, List<ConverterId>, ConverterFilter) has been deprecated. Please use RunInBatchMode(string, List<string>, bool) or upgrade using UnityEditor.Rendering.Universal.Converters.RunInBatchModeCmdLine instead.", false)]
190+
public static void RunInBatchMode(ConverterContainerId containerName, List<ConverterId> converterList, ConverterFilter converterFilter)
191+
{
192+
var types = FilterConverters(containerName, converterList, converterFilter);
193+
SuggestUpdatedCommand(containerName.ToString(), converterList.ConvertAll(id => id.ToString()), converterFilter == ConverterFilter.Inclusive);
194+
RunInBatchMode(types);
195+
}
196+
197+
[Obsolete("FilterConverters(ConverterContainerId, List<ConverterId>, ConverterFilter) has been deprecated. Please use FilterConverters(string, List<string>, bool) instead.", false)]
198+
internal static List<Type> FilterConverters(ConverterContainerId containerName, List<ConverterId> converterList, ConverterFilter converterFilter)
199+
{
200+
Array converters = Enum.GetValues(typeof(ConverterId));
201+
202+
List<Type> converterTypes = new();
203+
foreach (object value in converters)
204+
{
205+
var converterEnum = (ConverterId)value;
206+
if (TryGetTypeInContainer(converterEnum, containerName, out var type))
207+
{
208+
bool inFilter = converterList.Contains(converterEnum);
209+
if ((converterFilter == ConverterFilter.Inclusive) ^ !inFilter)
210+
converterTypes.Add(type);
211+
}
212+
}
213+
214+
return converterTypes;
215+
}
216+
}
21217
}

Packages/com.unity.render-pipelines.universal/Editor/Tools/Converters/AnimationClipConverter/AnimationClipConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public AnimationClipConverterItem(GlobalObjectId gid, string assetPath)
4040
[Serializable]
4141
[URPHelpURL("features/rp-converter")]
4242
[PipelineConverter("Built-in", "Universal Render Pipeline (Universal Renderer)")]
43+
[BatchModeConverterClassInfo("BuiltInToURP", "AnimationClip")]
4344
[ElementInfo(Name = "Animation Clip",
4445
Order = 110,
4546
Description = "Updates animation clips that reference material properties to work with URP shaders.\nEnsures material animations continue working after converting Materials from Built-in RP to URP.")]

Packages/com.unity.render-pipelines.universal/Editor/Tools/Converters/BuiltInToURP3DMaterialUpgrader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace UnityEditor.Rendering.Universal
88
{
99
[Serializable]
1010
[PipelineConverter("Built-in", "Universal Render Pipeline (Universal Renderer)")]
11+
[BatchModeConverterClassInfo("BuiltInToURP", "Material")]
1112
[ElementInfo(Name = "Material Shader Converter",
1213
Order = 100,
1314
Description = "This converter scans all materials that reference Built-in shaders and upgrades them to use Universal Render Pipeline (URP) shaders.")]

Packages/com.unity.render-pipelines.universal/Editor/Tools/Converters/BuiltInToURP3DReadonlyMaterialConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace UnityEditor.Rendering.Universal
1010
{
1111
[Serializable]
1212
[PipelineConverter("Built-in", "Universal Render Pipeline (Universal Renderer)")]
13+
[BatchModeConverterClassInfo("BuiltInToURP", "ReadonlyMaterial")]
1314
[ElementInfo(Name = "Material Reference Converter",
1415
Order = 100,
1516
Description = "Converts references to Built-In readonly materials to URP readonly materials.")]

0 commit comments

Comments
 (0)