Skip to content

Commit 0aa4923

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a4 C# reference source code
1 parent 67d5d85 commit 0aa4923

File tree

26 files changed

+330
-380
lines changed

26 files changed

+330
-380
lines changed

Editor/Mono/GUI/Tools/EditorToolCache.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,22 @@ public void InstantiateEditors(EditorToolContext ctx, List<ComponentEditor> edit
303303
// represented. Addresses case where a single locked inspector is open.
304304
var shared = ActiveEditorTracker.sharedTracker;
305305
var activeTracker = shared.isLocked ? sharedTracker : shared;
306-
var inspectors = InspectorWindow.GetInspectors();
306+
var propertyEditors = PropertyEditor.GetPropertyEditors();
307307

308-
// Collect editor tools for the shared tracker first, then any locked inspectors
308+
// Collect editor tools for the shared tracker first, then any locked inspectors or open properties editors
309309
CollectEditorsForTracker(ctx, activeTracker, editors);
310310

311-
foreach (var inspector in inspectors)
311+
foreach (var propertyEditor in propertyEditors)
312312
{
313-
if (inspector.isLocked)
314-
CollectEditorsForTracker(ctx, inspector.tracker, editors);
313+
if (propertyEditor is InspectorWindow)
314+
{
315+
if ((propertyEditor as InspectorWindow).isLocked)
316+
CollectEditorsForTracker(ctx, propertyEditor.tracker, editors);
317+
}
318+
else
319+
{
320+
CollectEditorsForTracker(ctx, propertyEditor.tracker, editors);
321+
}
315322
}
316323

317324
foreach (var editor in editors)

Editor/Mono/GameView/GameView.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,10 @@ private void DoToolbarGUI()
638638
using (new EditorGUI.DisabledScope(!RenderDoc.IsSupported()))
639639
{
640640
if (GUILayout.Button(Styles.renderdocContent, EditorStyles.toolbarButton))
641+
{
641642
RenderDoc.CaptureRenderDoc();
643+
GUIUtility.ExitGUI();
644+
}
642645
}
643646
}
644647

Editor/Mono/Inspector/GraphicsSettingsInspectors/IRenderPipelineGraphicsSettingsPropertyDrawer.cs

Lines changed: 129 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System.Collections.Generic;
6-
using System.Reflection;
7-
using System.Text;
86
using UnityEditor.UIElements;
97
using UnityEngine;
108
using UnityEngine.Rendering;
@@ -30,18 +28,18 @@ public static bool IsEmpty(SerializedProperty property, out string warnings)
3028
// Used in Unit tests
3129
public static IEnumerable<SerializedProperty> VisibleChildrenEnumerator(SerializedProperty property)
3230
{
33-
if (property.hasVisibleChildren)
34-
{
35-
var iterator = property.Copy();
36-
var end = iterator.GetEndProperty();
31+
if (!property.hasVisibleChildren)
32+
yield break;
3733

38-
iterator.NextVisible(true); // Move to the first child property
39-
do
40-
{
41-
yield return iterator;
42-
iterator.NextVisible(false);
43-
} while (!SerializedProperty.EqualContents(iterator, end)); // Move to the next sibling property
44-
}
34+
var iterator = property.Copy();
35+
var end = iterator.GetEndProperty();
36+
37+
iterator.NextVisible(true); // Move to the first child property
38+
do
39+
{
40+
yield return iterator;
41+
iterator.NextVisible(false);
42+
} while (!SerializedProperty.EqualContents(iterator, end)); // Move to the next sibling property
4543
}
4644

4745
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
@@ -52,13 +50,33 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
5250
return;
5351
}
5452

53+
int baseNameLength = property.propertyPath.Length + 1;
5554
foreach (var child in VisibleChildrenEnumerator(property))
5655
{
57-
EditorGUI.PropertyField(position, child);
58-
position.y += EditorGUI.GetPropertyHeight(property) + EditorGUIUtility.standardVerticalSpacing;
56+
Rect childPosition = position;
57+
childPosition.height = EditorGUI.GetPropertyHeight(child);
58+
EditorGUI.BeginChangeCheck();
59+
EditorGUI.PropertyField(childPosition, child);
60+
if (EditorGUI.EndChangeCheck())
61+
{
62+
child.serializedObject.ApplyModifiedProperties();
63+
var settings = property.boxedValue as IRenderPipelineGraphicsSettings;
64+
settings.NotifyValueChanged(child.propertyPath.Substring(baseNameLength));
65+
}
66+
position.y += childPosition.height + EditorGUIUtility.standardVerticalSpacing;
5967
}
6068
}
6169

70+
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
71+
{
72+
float height = 0f;
73+
foreach (var child in VisibleChildrenEnumerator(property))
74+
height += EditorGUI.GetPropertyHeight(child) + EditorGUIUtility.standardVerticalSpacing;
75+
if (height > 0)
76+
height -= EditorGUIUtility.standardVerticalSpacing; //remove last one
77+
return height;
78+
}
79+
6280
public override VisualElement CreatePropertyGUI(SerializedProperty property)
6381
{
6482
VisualElement root = new();
@@ -69,12 +87,107 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
6987
return root;
7088
}
7189

90+
notifier = new(property);
7291
foreach (var child in VisibleChildrenEnumerator(property))
7392
{
74-
root.Add(new PropertyField(child));
93+
var propertyField = new PropertyField(child);
94+
propertyField.RegisterCallback(PropagateOnChangeRecursivelyAtBinding(propertyField));
95+
root.Add(propertyField);
7596
}
7697

7798
return root;
7899
}
100+
101+
EventCallback<SerializedPropertyBindEvent> PropagateOnChangeRecursivelyAtBinding(PropertyField propertyField)
102+
{
103+
EventCallback<SerializedPropertyBindEvent> callback = null;
104+
callback = (SerializedPropertyBindEvent evt) => {
105+
UQueryState<VisualElement> childs;
106+
if(evt.bindProperty.isArray
107+
|| (childs = propertyField.Query(name: "unity-content").Visible().Build())
108+
.AtIndex(0) == null) //no child
109+
{
110+
// Fields that have no childs or array (handle all resizing and cell changes directly)
111+
propertyField.RegisterCallback<SerializedPropertyChangeEvent>(notifier.AddNotificationRequest);
112+
}
113+
else
114+
{
115+
// Propagate to custom struct and class childs
116+
childs.ForEach(e => e.Query<PropertyField>().Visible().ForEach(p => p.RegisterCallback(PropagateOnChangeRecursivelyAtBinding(p))));
117+
}
118+
119+
propertyField.UnregisterCallback(callback);
120+
callback = null;
121+
};
122+
return callback;
123+
}
124+
125+
// Aim is to batch notification for case where several are trigerred.
126+
// Example:
127+
// - Modifying a color, several channel amongst r, g, b, a can be altered with same editor modification
128+
// - This result in several time the SerializedPropertyChangeEvent being raised.
129+
// Also at binding we do not want to raise notification. As there is a previous SerializedObject state to
130+
// compare, we can trim that, even for Arrays that have a lot of elements to bind/update.
131+
class Notifier
132+
{
133+
HashSet<string> notificationRequests = new();
134+
SerializedObject lastSO;
135+
IRenderPipelineGraphicsSettings rpgs;
136+
int baseNameLength;
137+
138+
public Notifier(SerializedProperty property)
139+
{
140+
rpgs = property.boxedValue as IRenderPipelineGraphicsSettings;
141+
baseNameLength = property.propertyPath.Length + 1;
142+
lastSO = new SerializedObject(property.serializedObject.targetObject);
143+
}
144+
145+
public void AddNotificationRequest(SerializedPropertyChangeEvent evt)
146+
{
147+
SerializedProperty property = evt?.changedProperty;
148+
if (property == null)
149+
throw new System.ArgumentException("ChangedProperty cannot be null.", $"{nameof(evt)}.changedProperty");
150+
151+
if (SameThanLast(property))
152+
return;
153+
154+
Register(property.propertyPath);
155+
}
156+
157+
bool SameThanLast(SerializedProperty property)
158+
{
159+
if (SerializedProperty.DataEquals(property, lastSO?.FindProperty(property.propertyPath)))
160+
return true;
161+
162+
lastSO = new SerializedObject(property.serializedObject.targetObject);
163+
return false;
164+
}
165+
166+
string TrimPath(string path)
167+
{
168+
int length = path.IndexOf('.', baseNameLength) - baseNameLength;
169+
path = length < 0
170+
? path.Substring(baseNameLength)
171+
: path.Substring(baseNameLength, length);
172+
return path;
173+
}
174+
175+
void Register(string propertyPath)
176+
{
177+
if (notificationRequests.Count == 0)
178+
EditorApplication.CallDelayed(Notify);
179+
180+
notificationRequests.Add(TrimPath(propertyPath));
181+
}
182+
183+
void Notify()
184+
{
185+
foreach (var path in notificationRequests)
186+
rpgs.NotifyValueChanged(path);
187+
notificationRequests.Clear();
188+
}
189+
}
190+
191+
Notifier notifier;
79192
}
80193
}

Editor/Mono/Inspector/PropertyEditor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class PropertyEditor : EditorWindow, IPropertyView, IHasCustomMenu
9797
[SerializeField] protected string m_GlobalObjectId = "";
9898
[SerializeField] protected InspectorMode m_InspectorMode = InspectorMode.Normal;
9999

100+
private static readonly List<PropertyEditor> m_AllPropertyEditors = new List<PropertyEditor>();
100101
private Object m_InspectedObject;
101102
private static PropertyEditor s_LastPropertyEditor;
102103
protected int m_LastInitialEditorInstanceID;
@@ -356,6 +357,8 @@ protected virtual void OnEnable()
356357

357358
if (shouldUpdateSupportedDataModes)
358359
EditorApplication.CallDelayed(UpdateSupportedDataModesList);
360+
361+
if (!m_AllPropertyEditors.Contains(this)) m_AllPropertyEditors.Add(this);
359362
}
360363

361364
[UsedImplicitly]
@@ -382,6 +385,8 @@ protected virtual void OnDisable()
382385

383386
dataModeController.dataModeChanged -= OnDataModeChanged;
384387
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
388+
389+
m_AllPropertyEditors.Remove(this);
385390
}
386391

387392
private void OnMouseEnter(MouseEnterEvent e) => HoveredPropertyEditor = this;
@@ -464,6 +469,12 @@ protected virtual void Update()
464469
UpdateWindowObjectNameTitle();
465470
}
466471

472+
internal static IEnumerable<PropertyEditor> GetPropertyEditors()
473+
{
474+
return m_AllPropertyEditors.AsEnumerable();
475+
}
476+
477+
467478
protected void SetMode(InspectorMode mode)
468479
{
469480
if (m_InspectorMode != mode)

Editor/Mono/MenuItem.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public MenuItem(string itemName, bool isValidateFunction, int priority) : this(i
3232

3333
public MenuItem(string itemName, bool isValidateFunction, int priority, string disabledTooltip) : this(itemName, isValidateFunction, priority, false, disabledTooltip) { }
3434

35+
public MenuItem(string itemName, bool isValidateFunction, int priority, string disabledTooltip, string iconResource) : this(itemName, isValidateFunction, priority, false, disabledTooltip, iconResource) { }
36+
3537
// Creates a menu item and invokes the static function following it, when the menu item is selected.
3638
internal MenuItem(string itemName, bool isValidateFunction, int priority, bool internalMenu, string disabledTooltip = "", string iconResource = null)
3739
: this(itemName, isValidateFunction, priority, internalMenu, new string[] { "default" }, disabledTooltip, iconResource) {}
@@ -144,10 +146,10 @@ internal void Update(MenuItem menuItemAttribute, MethodInfo methodInfo)
144146
return;
145147
}
146148
priority = menuItemAttribute.priority;
147-
148149
secondaryPriority = menuItemAttribute.secondaryPriority;
149-
150150
execute = methodInfo;
151+
disabledTooltip = menuItemAttribute.disabledTooltip;
152+
iconResource = menuItemAttribute.iconResource;
151153
}
152154
else
153155
{

Editor/Mono/MenuUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static void AddMenuItemWithContext(DropdownMenu menu, IEnumerable<Objec
4848

4949
AddAction(menu, path,
5050
() => { EditorApplication.delayCall += () => ExecuteMenuItem(contextArray, menuItemPath); }, enabled,
51-
string.IsNullOrEmpty(iconResource) ? null : EditorGUIUtility.LoadIcon(iconResource),
51+
string.IsNullOrEmpty(iconResource) ? null : EditorGUIUtility.LoadIconRequired(iconResource),
5252
enabled ? string.Empty : Menu.GetDisabledTooltip(menuItemPath));
5353
}
5454

Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ bool LoadStage()
562562
dummyCanvas.sortingOrder = instanceCanvas.sortingOrder;
563563
dummyCanvas.referencePixelsPerUnit = instanceCanvas.referencePixelsPerUnit;
564564
dummyCanvas.stagePriority = (byte)stagePriority;
565+
dummyCanvas.sortingLayerID = instanceCanvas.sortingLayerID;
565566
}
566567
}
567568

Modules/Accessibility/Bindings/AccessibilityNodeData.bindings.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,6 @@
99

1010
namespace UnityEngine.Accessibility
1111
{
12-
/// <summary>
13-
/// Optional extra data about an accessibility node.
14-
/// </summary>
15-
[RequiredByNativeCode]
16-
[StructLayout(LayoutKind.Sequential)]
17-
[NativeType(CodegenOptions.Custom, "MonoAccessibilityExtraData")]
18-
[NativeHeader("Modules/Accessibility/Bindings/AccessibilityNodeData.bindings.h")]
19-
[NativeHeader("Modules/Accessibility/Native/AccessibilityNodeData.h")]
20-
public struct AccessibilityExtraData
21-
{
22-
public string label { get; set; }
23-
public string description { get; set; }
24-
}
25-
2612
/// <summary>
2713
/// Role of an accessibility node.
2814
/// </summary>
@@ -106,9 +92,10 @@ internal struct AccessibilityNodeData
10692
public string value { get; set; }
10793

10894
/// <summary>
109-
/// Optional extra data about the accessibility node.
95+
/// Additional information about the accessibility node.
96+
/// For example, the result of performing an action on the node.
11097
/// </summary>
111-
public AccessibilityExtraData[] extraData { get; set; }
98+
public string hint { get; set; }
11299

113100
/// <summary>
114101
/// The role of the accessibility node.
@@ -151,7 +138,7 @@ internal struct AccessibilityNodeData
151138

152139
/// <summary>
153140
/// The language to use when voicing the accessibility node's label,
154-
/// value, and extra data (can differ from the system or application
141+
/// value, and hint (can differ from the system or application
155142
/// language).
156143
/// </summary>
157144
internal SystemLanguage language { get; set; }

Modules/Accessibility/Bindings/AccessibilityNodeManager.bindings.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ internal static class AccessibilityNodeManager
5757
internal static extern void SetValue(int id, string value);
5858

5959
/// <summary>
60-
/// Sets optional extra data for the native accessibility node with the
61-
/// given ID.
60+
/// Sets the hint of the native accessibility node with the given ID.
6261
/// </summary>
63-
internal static extern void SetExtraData(int id, AccessibilityExtraData[] extraData);
62+
internal static extern void SetHint(int id, string hint);
6463

6564
/// <summary>
6665
/// Sets the role of the native accessibility node with the given ID.
@@ -97,7 +96,7 @@ internal static class AccessibilityNodeManager
9796
internal static extern void SetChildren(int id, int[] childIds);
9897

9998
/// <summary>
100-
/// Indicates whether an assistive technology is focused on the native
99+
/// Gets whether an assistive technology is focused on the native
101100
/// accessibility node with the given ID.
102101
/// </summary>
103102
internal static extern bool GetIsFocused(int id);
@@ -109,8 +108,8 @@ internal static class AccessibilityNodeManager
109108
internal static extern void SetActions(int id, AccessibilityAction[] actions);
110109

111110
/// <summary>
112-
/// Indicates the language to use when voicing the native accessibility
113-
/// node's label, value, and extra data (can differ from the system or
111+
/// Sets the language to use when voicing the native accessibility
112+
/// node's label, value, and hint (can differ from the system or
114113
/// application language).
115114
/// </summary>
116115
internal static extern void SetLanguage(int id, SystemLanguage language);
@@ -131,7 +130,7 @@ internal static bool Internal_InvokeSelected(int id)
131130

132131
if (service.TryGetNode(id, out var node))
133132
{
134-
return node.selected();
133+
return node.Selected();
135134
}
136135

137136
return false;

0 commit comments

Comments
 (0)