Skip to content

Commit 4075713

Browse files
authored
Merge pull request #8083 from Unity-Technologies/internal/master
Internal/master
2 parents a49d759 + 74326b1 commit 4075713

File tree

940 files changed

+103382
-31695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

940 files changed

+103382
-31695
lines changed

Packages/com.unity.render-pipelines.core/Documentation~/User-Render-Requests.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ The request is processed sequentially in your script, so there's no callback inv
88

99
`RenderPipeline.StandardRequest` renders the following:
1010

11-
- A full stack of cameras in the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP).
12-
- A single camera in the [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html) (HDRP).
11+
* A full stack of cameras in the [Universal Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/index.html) (URP).
12+
* A single camera in the [High Definition Render Pipeline](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html) (HDRP).
1313

1414
The following code sample gets the output of the scriptable render pipeline when you select a GUI button. Attach the script to a camera and select **Enter Play Mode**.
1515

16-
```
16+
```c#
1717
using System.Collections;
1818
using System.Collections.Generic;
1919
using UnityEngine;
@@ -91,5 +91,4 @@ public class StandardRenderRequest : MonoBehaviour
9191

9292
## Other useful information
9393

94-
- On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@latest/User-Render-Requests.html).
95-
94+
* On [Universal Render Pipeline (URP)](https://docs.unity3d.com/Packages/[email protected]/manual/User-Render-Requests.html).

Packages/com.unity.render-pipelines.core/Editor/Analytics/AnalyticsUtils.cs

Lines changed: 116 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -156,53 +156,93 @@ static Dictionary<string, string> GetDiffAsDictionary(Type type, object current,
156156

157157
foreach (var field in type.GetSerializableFields())
158158
{
159-
var t = field.FieldType;
160-
try
161-
{
162-
if (t.GetCustomAttribute<ObsoleteAttribute>() != null || typeof(ScriptableObject).IsAssignableFrom(t))
163-
continue;
159+
var fieldType = field.FieldType;
160+
if (!IsFieldIgnored(fieldType))
161+
AddDiff(current, defaults, field, fieldType, diff);
162+
}
164163

165-
var valueCurrent = current != null ? field.GetValue(current) : null;
166-
var valueDefault = defaults != null ? field.GetValue(defaults) : null;
164+
return diff;
165+
}
167166

168-
if (t == typeof(string))
169-
{
170-
var stringCurrent = (string)valueCurrent;
171-
var stringDefault = (string)valueDefault;
172-
if (stringCurrent != stringDefault)
173-
{
174-
diff[field.Name] = stringCurrent;
175-
}
176-
}
177-
else if (t.IsPrimitive || t.IsEnum)
178-
{
179-
if (!valueCurrent.Equals(valueDefault))
180-
diff[field.Name] = ConvertPrimitiveWithInvariants(valueCurrent);
181-
}
182-
else if (t.IsArray && valueCurrent is IList valueCurrentList)
183-
{
184-
if (AreArraysDifferent(valueCurrentList, valueDefault as IList))
185-
diff[field.Name] = valueCurrentList.DumpValues();
186-
}
187-
else if (t.IsClass || t.IsValueType)
188-
{
189-
if (valueCurrent is IEnumerable ea)
190-
continue; // List<T> not supported
167+
private static void AddDiff(object current, object defaults, FieldInfo field, Type fieldType, Dictionary<string, string> diff)
168+
{
169+
try
170+
{
171+
var valueCurrent = current != null ? field.GetValue(current) : null;
172+
var valueDefault = defaults != null ? field.GetValue(defaults) : null;
173+
AddIfDifferent(field, fieldType, diff, valueCurrent, valueDefault);
174+
}
175+
catch (Exception ex)
176+
{
177+
Debug.LogError($"Exception found while parsing {field}, {ex}");
178+
}
179+
}
191180

192-
var subDiff = GetDiffAsDictionary(t, valueCurrent, valueDefault);
193-
foreach (var d in subDiff)
194-
{
195-
diff[field.Name + "." + d.Key] = d.Value;
196-
}
181+
private static void AddIfDifferent(FieldInfo field, Type fieldType, Dictionary<string, string> diff, object valueCurrent, object valueDefault)
182+
{
183+
if (!AreValuesEqual(fieldType, valueCurrent, valueDefault))
184+
{
185+
if (IsComplexType(fieldType))
186+
{
187+
var subDiff = GetDiffAsDictionary(fieldType, valueCurrent, valueDefault);
188+
foreach (var d in subDiff)
189+
{
190+
diff[$"{field.Name}.{d.Key}"] = d.Value;
197191
}
198192
}
199-
catch (Exception ex)
193+
else
200194
{
201-
Debug.LogError($"Exception found while parsing {field}, {ex}");
195+
diff[field.Name] = ConvertValueToString(valueCurrent);
202196
}
203197
}
198+
}
204199

205-
return diff;
200+
static bool IsFieldIgnored(Type fieldType)
201+
{
202+
return fieldType.GetCustomAttribute<ObsoleteAttribute>() != null || typeof(ScriptableObject).IsAssignableFrom(fieldType);
203+
}
204+
205+
internal static bool AreValuesEqual(Type fieldType, object valueCurrent, object valueDefault)
206+
{
207+
if (fieldType == typeof(string))
208+
return (string)valueCurrent == (string)valueDefault;
209+
210+
if (fieldType.IsPrimitive || fieldType.IsEnum)
211+
return valueCurrent.Equals(valueDefault);
212+
213+
if (fieldType.IsArray && valueCurrent is IList currentList)
214+
return !AreArraysDifferent(currentList, valueDefault as IList);
215+
216+
if (valueCurrent == null && valueDefault == null)
217+
return true;
218+
219+
return valueDefault?.Equals(valueCurrent) ?? valueCurrent?.Equals(null) ?? false;
220+
}
221+
222+
internal static bool IsComplexType(Type fieldType)
223+
{
224+
// Primitive types and enums are not considered complex
225+
if (fieldType.IsPrimitive || fieldType.IsEnum)
226+
return false;
227+
228+
// String is considered a primitive type for our purposes
229+
if (fieldType == typeof(string))
230+
return false;
231+
232+
// Arrays can be converted to string easy without sub-elements
233+
if (fieldType.IsArray)
234+
return false;
235+
236+
// Value types (structs) that are not primitive are considered complex
237+
// Classes are considered complex types
238+
return fieldType.IsValueType || fieldType.IsClass;
239+
}
240+
241+
static string ConvertValueToString(object value)
242+
{
243+
if (value == null) return null;
244+
if (value is IList list) return list.DumpValues();
245+
return ConvertPrimitiveWithInvariants(value);
206246
}
207247

208248
static string ConvertPrimitiveWithInvariants(object obj)
@@ -212,17 +252,49 @@ static string ConvertPrimitiveWithInvariants(object obj)
212252
return obj.ToString();
213253
}
214254

215-
static string[] ToStringArray(Dictionary<string, string> diff)
255+
static string[] ToStringArray(Dictionary<string, string> diff, string format = null)
216256
{
217257
var changedSettings = new string[diff.Count];
218258

259+
if (string.IsNullOrEmpty(format))
260+
format = @"{{""{0}"":""{1}""}}";
261+
219262
int i = 0;
220263
foreach (var d in diff)
221-
changedSettings[i++] = $@"{{""{d.Key}"":""{d.Value}""}}";
264+
changedSettings[i++] = string.Format(format, d.Key, d.Value);
222265

223266
return changedSettings;
224267
}
225268

269+
private static string[] EnumerableToNestedColumn<T>([DisallowNull] this IEnumerable collection)
270+
{
271+
using (ListPool<string>.Get(out var tmp))
272+
{
273+
foreach (var element in collection)
274+
{
275+
string[] elementColumns = ToStringArray(DumpValues(element.GetType(), element), @"""{0}"":""{1}""");
276+
tmp.Add("{" + string.Join(", ", elementColumns) + "}");
277+
}
278+
279+
return tmp.ToArray();
280+
}
281+
}
282+
283+
private static string[] ToNestedColumnSimplify<T>([DisallowNull] this T current)
284+
where T : new()
285+
{
286+
var type = current.GetType();
287+
288+
if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(T)))
289+
{
290+
var instance = ScriptableObject.CreateInstance(type);
291+
ToStringArray(GetDiffAsDictionary(type, current, instance));
292+
ScriptableObject.DestroyImmediate(instance);
293+
}
294+
295+
return ToStringArray(GetDiffAsDictionary(type, current, new T()));
296+
}
297+
226298
/// <summary>
227299
/// Obtains the Serialized fields and values in form of nested columns for BigQuery
228300
/// https://cloud.google.com/bigquery/docs/nested-repeated
@@ -238,28 +310,13 @@ public static string[] ToNestedColumn<T>([DisallowNull] this T current, bool com
238310
if (current == null)
239311
throw new ArgumentNullException(nameof(current));
240312

241-
var type = current.GetType();
313+
if (current is IEnumerable currentAsEnumerable)
314+
return EnumerableToNestedColumn<T>(currentAsEnumerable);
242315

243-
Dictionary<string, string> diff;
244316
if (compareAndSimplifyWithDefault)
245-
{
246-
if (typeof(UnityEngine.Object).IsAssignableFrom(typeof(T)))
247-
{
248-
var instance = ScriptableObject.CreateInstance(type);
249-
diff = GetDiffAsDictionary(type, current, instance);
250-
ScriptableObject.DestroyImmediate(instance);
251-
}
252-
else
253-
{
254-
diff = GetDiffAsDictionary(type, current, new T());
255-
}
256-
}
257-
else
258-
{
259-
diff = DumpValues(type, current);
260-
}
317+
return ToNestedColumnSimplify(current);
261318

262-
return ToStringArray(diff);
319+
return ToStringArray(DumpValues(current.GetType(), current));
263320
}
264321

265322
/// <summary>

Packages/com.unity.render-pipelines.core/Editor/Analytics/BuildTargetAnalytic.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool TryGatherData([NotNullWhen(true)] out IAnalytic.IData data, [NotNull
2222
{
2323
var activeBuildTarget = EditorUserBuildSettings.activeBuildTarget;
2424
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(activeBuildTarget);
25-
var activeBuildTargetGroupName = activeBuildTargetGroup.ToString();
25+
var activeBuildTargetGroupName = NamedBuildTarget.FromBuildTargetGroup(activeBuildTargetGroup).TargetName;
2626

2727
error = null;
2828

@@ -37,7 +37,6 @@ public bool TryGatherData([NotNullWhen(true)] out IAnalytic.IData data, [NotNull
3737
};
3838
return true;
3939
}
40-
4140
};
4241

4342
[System.Diagnostics.DebuggerDisplay("{render_pipeline_asset_type} - {quality_levels}/{total_quality_levels_on_project}")]

Packages/com.unity.render-pipelines.core/Editor/Analytics/DebugManagerWidgetUsedAnalytic.cs

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

0 commit comments

Comments
 (0)