Skip to content

Commit 7c95a72

Browse files
author
Unity Technologies
committed
Unity 2023.3.0b3 C# reference source code
1 parent 8f0516b commit 7c95a72

File tree

568 files changed

+497
-74285
lines changed

Some content is hidden

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

568 files changed

+497
-74285
lines changed

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,11 @@ static bool IsVirtualTexturingSettingsValid(BuildPlatform platform)
572572
static Dictionary<string, string> s_ModuleNames = new Dictionary<string, string>()
573573
{
574574
{ "tvOS", "AppleTV" },
575-
{ "OSXStandalone", "Mac" },
575+
{ "OSXStandalone", "Mac-Mono" },
576576
{ "OSXDedicatedServer", "Mac-Server" },
577-
{ "WindowsStandalone", "Windows" },
577+
{ "WindowsStandalone", "Windows-Mono" },
578578
{ "WindowsDedicatedServer", "Windows-Server" },
579-
{ "LinuxStandalone", "Linux" },
579+
{ "LinuxStandalone", "Linux-Mono" },
580580
{ "LinuxDedicatedServer", "Linux-Server" },
581581
{ "UWP", "Universal-Windows-Platform"}
582582
};
@@ -624,7 +624,7 @@ static public string GetPlaybackEngineDownloadURL(string moduleName)
624624
}
625625
else if (Application.platform == RuntimePlatform.LinuxEditor)
626626
{
627-
if (moduleName == "Android" || moduleName == "Mac" || moduleName == "Windows")
627+
if (moduleName == "Android" || moduleName == "Mac-Mono" || moduleName == "Windows-Mono")
628628
{
629629
folder = "MacEditorTargetInstaller";
630630
extension = ".pkg";

Editor/Mono/ContainerWindow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
125125
m_RootView.SetWindowRecurse(this);
126126
Internal_SetTitle(m_Title);
127127
Save();
128+
129+
// System windows that come from the OS (like a context menu from search) need theming
130+
SetBackgroundColor(skinBackgroundColor);
131+
128132
// only set focus if mode is a popupMenu.
129133
Internal_BringLiveAfterCreation(true, giveFocus, false);
130134

Editor/Mono/EditorGUI.RenderPipeline.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5-
using System.Diagnostics.CodeAnalysis;
5+
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
7+
using UnityEditor.Rendering;
68
using UnityEngine;
79

810
namespace UnityEditor
@@ -49,8 +51,7 @@ static uint RenderingLayerMaskFieldInternal(Rect position, GUIContent label, uin
4951
if (label != null)
5052
position = PrefixLabel(position, id, label);
5153

52-
var names = RenderingLayerMask.GetDefinedRenderingLayerNames();
53-
var values = RenderingLayerMask.GetDefinedRenderingLayerValues();
54+
var (names, values) = RenderPipelineEditorUtility.GetRenderingLayerNamesAndValuesForMask(layers);
5455

5556
using var scope = new MixedValueScope();
5657

@@ -63,6 +64,11 @@ static uint RenderingLayerMaskFieldInternal(Rect position, GUIContent label, uin
6364
bits.uintValue = (uint)newValue;
6465
}
6566

67+
var currentLimit = RenderPipelineEditorUtility.GetActiveMaxRenderingLayers();
68+
var newValueUint = unchecked((uint)newValue);
69+
if (currentLimit != 32 && newValueUint != uint.MaxValue && newValueUint >= 1u << currentLimit)
70+
EditorGUILayout.HelpBox($"Current mask contains layers outside of a supported range by active Render Pipeline. The active Render Pipeline only supports up to {currentLimit} layers. Rendering Layers above {currentLimit} are ignored.", MessageType.Warning);
71+
6672
return unchecked((uint)newValue);
6773
}
6874
}

Editor/Mono/EditorGraphicsSettings.bindings.cs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ internal static void ForEachPipelineSettings(Action<RenderPipelineGlobalSettings
148148
action?.Invoke(Internal_GetSettingsForRenderPipelineAt(i) as RenderPipelineGlobalSettings);
149149
}
150150

151+
public static TSettingsInterfaceType[] GetRenderPipelineSettingsFromInterface<TSettingsInterfaceType>()
152+
where TSettingsInterfaceType : class, IRenderPipelineGraphicsSettings
153+
{
154+
if (!GraphicsSettings.TryGetCurrentRenderPipelineGlobalSettings(out RenderPipelineGlobalSettings asset))
155+
return new TSettingsInterfaceType[] {};
156+
157+
if (asset.GetSettingsImplementingInterface<TSettingsInterfaceType>(out var baseSettings))
158+
{
159+
return baseSettings.ToArray();
160+
}
161+
162+
return new TSettingsInterfaceType[] {};
163+
}
164+
151165
public static bool TryGetFirstRenderPipelineSettingsFromInterface<TSettingsInterfaceType>(out TSettingsInterfaceType settings)
152166
where TSettingsInterfaceType : class, IRenderPipelineGraphicsSettings
153167
{
@@ -165,18 +179,40 @@ public static bool TryGetFirstRenderPipelineSettingsFromInterface<TSettingsInter
165179
return false;
166180
}
167181

168-
public static TSettingsInterfaceType[] GetRenderPipelineSettingsFromInterface<TSettingsInterfaceType>()
182+
public static bool TryGetRenderPipelineSettingsFromInterface<TSettingsInterfaceType>(out TSettingsInterfaceType[] settings)
169183
where TSettingsInterfaceType : class, IRenderPipelineGraphicsSettings
170184
{
185+
settings = null;
186+
171187
if (!GraphicsSettings.TryGetCurrentRenderPipelineGlobalSettings(out RenderPipelineGlobalSettings asset))
172-
return new TSettingsInterfaceType[] {};
188+
return false;
173189

174190
if (asset.GetSettingsImplementingInterface<TSettingsInterfaceType>(out var baseSettings))
175-
{
176-
return baseSettings.ToArray();
177-
}
191+
settings = baseSettings.ToArray();
178192

179-
return new TSettingsInterfaceType[] {};
193+
return settings != null;
194+
}
195+
196+
public static bool TryGetRenderPipelineSettingsFromInterfaceForPipeline<TSettingsInterfaceType, TPipeline>(out TSettingsInterfaceType[] settings)
197+
where TSettingsInterfaceType : class, IRenderPipelineGraphicsSettings
198+
where TPipeline : RenderPipeline
199+
{
200+
return TryGetRenderPipelineSettingsFromInterfaceForPipeline(typeof(TPipeline), out settings);
201+
}
202+
203+
public static bool TryGetRenderPipelineSettingsFromInterfaceForPipeline<TSettingsInterfaceType>(Type renderPipelineType, out TSettingsInterfaceType[] settings)
204+
where TSettingsInterfaceType : class, IRenderPipelineGraphicsSettings
205+
{
206+
settings = null;
207+
208+
var pipelineGlobalSettings = GraphicsSettings.GetSettingsForRenderPipeline(renderPipelineType);
209+
if (pipelineGlobalSettings == null)
210+
return false;
211+
212+
if (pipelineGlobalSettings.GetSettingsImplementingInterface<TSettingsInterfaceType>(out var baseSettings))
213+
settings = baseSettings.ToArray();
214+
215+
return settings != null;
180216
}
181217
}
182218
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEngine;
7+
using UnityEngine.Rendering;
8+
9+
namespace UnityEditor.Rendering
10+
{
11+
public abstract class RenderingLayersLimitSettings : IRenderPipelineGraphicsSettings
12+
{
13+
#region Version
14+
15+
internal enum Version
16+
{
17+
Initial = 0,
18+
}
19+
20+
[SerializeField] [HideInInspector] Version m_Version = Version.Initial;
21+
22+
/// <summary>Current version.</summary>
23+
public int version => (int)m_Version;
24+
25+
#endregion
26+
27+
protected abstract int maxRenderingLayersForPipeline { get; }
28+
29+
public int maxSupportedRenderingLayers => maxRenderingLayersForPipeline is > 1 and <= 32 ? maxRenderingLayersForPipeline : 32;
30+
}
31+
}

Editor/Mono/Inspector/RenderPipelineEditorUtility.cs

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using UnityEngine;
1010
using UnityEngine.Rendering;
11+
using Object = UnityEngine.Object;
1112

1213
namespace UnityEditor.Rendering
1314
{
@@ -31,13 +32,12 @@ public static Type FetchFirstCompatibleTypeUsingScriptableRenderPipelineExtensio
3132
if (Attribute.GetCustomAttribute(extensionType, typeof(ScriptableRenderPipelineExtensionAttribute)) is ScriptableRenderPipelineExtensionAttribute { inUse: true })
3233
return extensionType;
3334
#pragma warning restore CS0618
34-
3535
}
3636

3737
return null;
3838
}
3939

40-
private static Dictionary<Type, Type> s_RenderPipelineAssetToRenderPipelineType = new ();
40+
private static Dictionary<Type, Type> s_RenderPipelineAssetToRenderPipelineType = new();
4141

4242
public static Type GetPipelineTypeFromPipelineAssetType(Type pipelineAssetType)
4343
{
@@ -63,12 +63,95 @@ public static Type GetPipelineTypeFromPipelineAssetType(Type pipelineAssetType)
6363

6464
var pipelineAsset = ScriptableObject.CreateInstance(pipelineAssetType) as RenderPipelineAsset;
6565
pipelineType = pipelineAsset.pipelineType;
66-
UnityEngine.Object.DestroyImmediate(pipelineAsset);
66+
Object.DestroyImmediate(pipelineAsset);
6767
s_RenderPipelineAssetToRenderPipelineType[pipelineAssetType] = pipelineType;
6868
return pipelineType;
6969
}
7070

7171
public static bool TrySetRenderingLayerName(int index, string name)
72-
=> TagManager.TrySetRenderingLayerName(index, name);
72+
=> TagManager.Internal_TrySetRenderingLayerName(index, name);
73+
74+
public static bool TryAddRenderingLayerName(string name)
75+
=> TagManager.Internal_TryAddRenderingLayerName(name);
76+
77+
internal static int GetActiveMaxRenderingLayers()
78+
{
79+
if (EditorGraphicsSettings.TryGetRenderPipelineSettingsFromInterface<RenderingLayersLimitSettings>(out var settings)
80+
&& settings.Length != 0)
81+
return settings[0].maxSupportedRenderingLayers;
82+
return 32;
83+
}
84+
85+
internal static List<(int, string)> GetMaxRenderingLayersFromSettings()
86+
{
87+
var result = new List<(int, string)>();
88+
var renderPipelineAssets = GraphicsSettings.allConfiguredRenderPipelines;
89+
foreach (var renderPipelineAsset in renderPipelineAssets)
90+
{
91+
var pipelineType = GetPipelineTypeFromPipelineAssetType(renderPipelineAsset.GetType());
92+
if (pipelineType == null)
93+
continue;
94+
95+
if (!EditorGraphicsSettings.TryGetRenderPipelineSettingsFromInterfaceForPipeline<RenderingLayersLimitSettings>(pipelineType, out var settings))
96+
continue;
97+
98+
if (settings.Length == 0)
99+
continue;
100+
101+
result.Add((settings[0].maxSupportedRenderingLayers, renderPipelineAsset.pipelineType.Name));
102+
}
103+
104+
return result;
105+
}
106+
107+
internal static (string[], int[]) GetRenderingLayerNamesAndValuesForMask(uint currentMask)
108+
{
109+
var names = RenderingLayerMask.GetDefinedRenderingLayerNames();
110+
var values = RenderingLayerMask.GetDefinedRenderingLayerValues();
111+
112+
if (currentMask != uint.MaxValue)
113+
{
114+
//calculate remaining mask value
115+
uint remainingMask = currentMask;
116+
for (int i = 0; i < values.Length; i++)
117+
{
118+
uint valueUint = unchecked((uint)values[i]);
119+
if ((currentMask & valueUint) != 0)
120+
remainingMask &= ~valueUint;
121+
}
122+
123+
//add remaining mask value to the end of the list
124+
if (remainingMask != 0)
125+
{
126+
var listOfUnnamedBits = new List<(int, uint)>();
127+
for (int i = 0; i < 32; i++)
128+
{
129+
if ((remainingMask & (1u << i)) != 0)
130+
listOfUnnamedBits.Add((i, 1u << i));
131+
}
132+
133+
var allNames = new List<string>(names.Length + listOfUnnamedBits.Count);
134+
var allValues = new List<int>(names.Length + listOfUnnamedBits.Count);
135+
allNames.AddRange(names);
136+
allValues.AddRange(values);
137+
138+
for (int i = 0; i < listOfUnnamedBits.Count; i++)
139+
{
140+
var bit = listOfUnnamedBits[i];
141+
var indexOfTheNextValue = allValues.FindIndex((currentValue) => unchecked((uint)currentValue) > bit.Item2);
142+
if (indexOfTheNextValue == -1)
143+
indexOfTheNextValue = allValues.Count;
144+
145+
//find an index of specific bit value
146+
allNames.Insert(indexOfTheNextValue, $"Undefined Layer {bit.Item1}");
147+
allValues.Insert(indexOfTheNextValue, unchecked((int)bit.Item2));
148+
}
149+
names = allNames.ToArray();
150+
values = allValues.ToArray();
151+
}
152+
}
153+
154+
return (names, values);
155+
}
73156
}
74157
}

0 commit comments

Comments
 (0)