Skip to content

Commit 667dd8b

Browse files
author
Unity Technologies
committed
Unity 2022.2.0a17 C# reference source code
1 parent 4d031e5 commit 667dd8b

60 files changed

Lines changed: 472 additions & 344 deletions

File tree

Some content is hidden

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

Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override void UpdateBootConfig(BuildTarget target, BootConfigData config,
3838
if (PlayerSettings.forceSingleInstance)
3939
config.AddKey("single-instance");
4040
if (!PlayerSettings.useFlipModelSwapchain)
41-
config.AddKey("force-d3d11-bitblt-mode");
41+
config.AddKey("force-d3d11-bitblt-model");
4242
if (IL2CPPUtils.UseIl2CppCodegenWithMonoBackend(NamedBuildTarget.FromActiveSettings(target)))
4343
config.Set("mono-codegen", "il2cpp");
4444
if ((options & BuildOptions.EnableCodeCoverage) != 0)

Editor/Mono/EditorApplication.bindings.cs

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

55
using System;
6+
using System.Reflection;
67
using UnityEditor.Scripting.ScriptCompilation;
78
using UnityEngine;
89
using UnityEngine.Bindings;
@@ -168,28 +169,55 @@ public static bool ExecuteMenuItem(string menuItemPath)
168169
var isDefaultMode = ModeService.currentId == ModeService.k_DefaultModeId;
169170
var result = ExecuteMenuItemInternal(sanitizedPath, isDefaultMode);
170171
if (result)
171-
return result;
172+
return true;
172173

173174
if (!isDefaultMode)
174175
{
176+
// Check if the menu was found first. If so, it means that the menu just
177+
// didn't pass validation. No need to check further.
178+
if (Menu.MenuItemExists(sanitizedPath))
179+
return false;
180+
175181
var menuItems = TypeCache.GetMethodsWithAttribute<MenuItem>();
182+
MethodInfo validateItem = null;
183+
MethodInfo executeItem = null;
176184
foreach (var item in menuItems)
177185
{
178186
MenuItem itemData = (MenuItem)item.GetCustomAttributes(typeof(MenuItem), false)[0];
179-
if (!itemData.validate && itemData.menuItem == sanitizedPath)
187+
var hotKeyIndex = Menu.FindHotkeyStartIndex(itemData.menuItem);
188+
var hasHotkey = hotKeyIndex != -1 && hotKeyIndex != itemData.menuItem.Length;
189+
bool matches;
190+
if (!hasHotkey)
180191
{
181-
if (item.GetParameters().Length == 0)
182-
{
183-
item.Invoke(null, new object[0]);
184-
return true;
185-
}
186-
else if (item.GetParameters()[0].ParameterType == typeof(MenuCommand))
187-
{
188-
item.Invoke(null, new[] { new MenuCommand(null) });
189-
return true;
190-
}
191-
break;
192+
matches = itemData.menuItem == sanitizedPath;
193+
}
194+
else
195+
{
196+
var stringView = itemData.menuItem.AsSpan(0, hotKeyIndex);
197+
stringView = stringView.TrimEnd();
198+
matches = stringView == sanitizedPath;
192199
}
200+
if (!matches)
201+
continue;
202+
203+
if (itemData.validate)
204+
validateItem = item;
205+
else
206+
executeItem = item;
207+
208+
if (validateItem != null && executeItem != null)
209+
break;
210+
}
211+
212+
if (validateItem != null)
213+
{
214+
if (!ExecuteMenuItem(validateItem, true))
215+
return false;
216+
}
217+
218+
if (executeItem != null)
219+
{
220+
return ExecuteMenuItem(executeItem, false);
193221
}
194222

195223
Debug.LogError($"ExecuteMenuItem failed because there is no menu named '{menuItemPath}'");
@@ -198,6 +226,22 @@ public static bool ExecuteMenuItem(string menuItemPath)
198226
return false;
199227
}
200228

229+
static bool ExecuteMenuItem(MethodInfo menuMethodInfo, bool validate)
230+
{
231+
if (menuMethodInfo.GetParameters().Length == 0)
232+
{
233+
var result = menuMethodInfo.Invoke(null, new object[0]);
234+
return !validate || (bool)result;
235+
}
236+
237+
if (menuMethodInfo.GetParameters()[0].ParameterType == typeof(MenuCommand))
238+
{
239+
var result = menuMethodInfo.Invoke(null, new[] { new MenuCommand(null) });
240+
return !validate || (bool)result;
241+
}
242+
return false;
243+
}
244+
201245
// Validates the menu item in the specific path
202246
internal static extern bool ValidateMenuItem(string menuItemPath);
203247

Editor/Mono/EditorGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2782,7 +2782,7 @@ internal static int DelayedIntFieldInternal(Rect position, GUIContent label, int
27822782
bool draggable = SetDelayedDraggable(ref position, ref dragHotzone, label, id);
27832783

27842784
BeginChangeCheck();
2785-
DelayedNumberFieldInternal(position, dragHotzone, id, false, ref dummy, ref longValue, kFloatFieldFormatString, style, draggable, Event.current.GetTypeForControl(id) == EventType.MouseDown ? (float)NumericFieldDraggerUtility.CalculateFloatDragSensitivity(s_DragStartValue) : 0.0f);
2785+
DelayedNumberFieldInternal(position, dragHotzone, id, false, ref dummy, ref longValue, kIntFieldFormatString, style, draggable, Event.current.GetTypeForControl(id) == EventType.MouseDown ? (float)NumericFieldDraggerUtility.CalculateIntDragSensitivity(value) : 0.0f);
27862786
if (EndChangeCheck())
27872787
{
27882788
if ((int)longValue != value)

Editor/Mono/EditorGUIUtility.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using UnityEngineInternal;
1818
using UnityEditor.StyleSheets;
1919
using UnityEditor.Experimental;
20+
using UnityEditor.SceneManagement;
2021
using UnityEngine.UIElements;
2122
using UnityObject = UnityEngine.Object;
2223

@@ -118,6 +119,9 @@ internal static Material GUITextureBlitSceneGUIMaterial
118119
private static readonly GUIContent s_Image = new GUIContent();
119120
private static readonly GUIContent s_TextImage = new GUIContent();
120121

122+
private static GUIContent s_SceneMismatch = TrTextContent("Scene mismatch (cross scene references not supported)");
123+
private static GUIContent s_TypeMismatch = TrTextContent("Type mismatch");
124+
121125
internal static readonly SVC<Color> kViewBackgroundColor = new SVC<Color>("view", StyleCatalogKeyword.backgroundColor, GetDefaultBackgroundColor);
122126

123127
/// The current UI scaling factor for high-DPI displays. For instance, 2.0 on a retina display
@@ -976,6 +980,54 @@ internal static GUIContent ObjectContent(UnityObject obj, Type type, int instanc
976980
return s_ObjectContent;
977981
}
978982

983+
internal static GUIContent ObjectContent(UnityObject obj, Type type, SerializedProperty property, EditorGUI.ObjectFieldValidator validator = null)
984+
{
985+
if (validator == null)
986+
validator = EditorGUI.ValidateObjectFieldAssignment;
987+
988+
GUIContent temp;
989+
990+
// If obj or objType are both null, we have to rely on
991+
// property.objectReferenceStringValue to display None/Missing and the
992+
// correct type. But if not, EditorGUIUtility.ObjectContent is more reliable.
993+
// It can take a more specific object type specified as argument into account,
994+
// and it gets the icon at the same time.
995+
if (obj == null && type == null && property != null)
996+
{
997+
temp = TempContent(property.objectReferenceStringValue);
998+
}
999+
else
1000+
{
1001+
// In order for ObjectContext to be able to distinguish between None/Missing,
1002+
// we need to supply an instanceID. For some reason, getting the instanceID
1003+
// from property.objectReferenceValue is not reliable, so we have to
1004+
// explicitly check property.objectReferenceInstanceIDValue if a property exists.
1005+
if (property != null)
1006+
temp = ObjectContent(obj, type, property.objectReferenceInstanceIDValue);
1007+
else
1008+
temp = ObjectContent(obj, type);
1009+
}
1010+
1011+
if (property != null)
1012+
{
1013+
if (obj != null)
1014+
{
1015+
UnityObject[] references = { obj };
1016+
if (EditorSceneManager.preventCrossSceneReferences && EditorGUI.CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject))
1017+
{
1018+
if (!EditorApplication.isPlaying)
1019+
temp = s_SceneMismatch;
1020+
else
1021+
temp.text = temp.text + string.Format(" ({0})", EditorGUI.GetGameObjectFromObject(obj).scene.name);
1022+
}
1023+
else if (validator(references, type, property, EditorGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null)
1024+
temp = s_TypeMismatch;
1025+
}
1026+
}
1027+
1028+
return temp;
1029+
}
1030+
9791031
internal static GUIContent TempContent(string t)
9801032
{
9811033
s_Text.image = null;

Editor/Mono/GUI/GradientEditor.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,8 @@ public void OnGUI(Rect position)
180180

181181
// Gradient texture
182182
position.y += swatchHeight;
183-
if (Event.current.type == EventType.Repaint)
184-
{
185-
position.height = gradientTextureHeight;
186-
DrawGradientWithBackground(position, m_Gradient, m_ColorSpace == ColorSpace.Linear);
187-
}
183+
position.height = gradientTextureHeight;
184+
DrawGradientWithBackground(position, m_Gradient, m_ColorSpace == ColorSpace.Linear);
188185
position.y += gradientTextureHeight;
189186
position.height = swatchHeight;
190187

Editor/Mono/GUI/MaskFieldGUI.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal static int DoMaskField(Rect position, int controlID, int mask, string[]
115115
{
116116
mask = MaskCallbackInfo.GetSelectedValueForControl(controlID, mask, out changedFlags, out changedToValue);
117117

118-
GetMenuOptions(mask, flagNames, flagValues, out var buttonText, out var buttonTextMixed, out var optionNames, out var optionMaskValues, out var selectedOptions, enumType);
118+
GetMenuOptions(mask, flagNames, flagValues, out var buttonText, out var buttonTextMixed, out var optionNames, out var optionMaskValues, out _, enumType);
119119

120120
Event evt = Event.current;
121121
if (evt.type == EventType.Repaint)
@@ -126,7 +126,7 @@ internal static int DoMaskField(Rect position, int controlID, int mask, string[]
126126
else if ((evt.type == EventType.MouseDown && position.Contains(evt.mousePosition)) || evt.MainActionKeyForControl(controlID))
127127
{
128128
MaskCallbackInfo.m_Instance = new MaskCallbackInfo(controlID);
129-
PopupWindowWithoutFocus.Show(position, new MaskFieldDropDown(optionNames, optionMaskValues, mask, MaskCallbackInfo.m_Instance.SetMaskValueDelegate));
129+
PopupWindowWithoutFocus.Show(position, new MaskFieldDropDown(optionNames, flagValues, optionMaskValues, mask, MaskCallbackInfo.m_Instance.SetMaskValueDelegate));
130130
}
131131

132132
return mask;
@@ -349,10 +349,6 @@ internal static void GetMenuOptions(int mask, string[] flagNames, int[] flagValu
349349
var flagSet = ((intermediateMask & flagValue) == flagValue);
350350
var newMask = (flagSet ? intermediateMask & ~flagValue : intermediateMask | flagValue);
351351

352-
// If all flag options are selected the mask becomes everythingValue to be consistent with the "Everything" option
353-
if (newMask == flagMask)
354-
newMask = everythingValue;
355-
356352
optionMaskValues[optionIndex] = newMask;
357353
}
358354
}

Editor/Mono/GUI/ObjectField.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -410,43 +410,7 @@ static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, Ob
410410
}
411411
else
412412
{
413-
// If obj or objType are both null, we have to rely on
414-
// property.objectReferenceStringValue to display None/Missing and the
415-
// correct type. But if not, EditorGUIUtility.ObjectContent is more reliable.
416-
// It can take a more specific object type specified as argument into account,
417-
// and it gets the icon at the same time.
418-
if (obj == null && objType == null && property != null)
419-
{
420-
temp = EditorGUIUtility.TempContent(property.objectReferenceStringValue);
421-
}
422-
else
423-
{
424-
// In order for ObjectContext to be able to distinguish between None/Missing,
425-
// we need to supply an instanceID. For some reason, getting the instanceID
426-
// from property.objectReferenceValue is not reliable, so we have to
427-
// explicitly check property.objectReferenceInstanceIDValue if a property exists.
428-
if (property != null)
429-
temp = EditorGUIUtility.ObjectContent(obj, objType, property.objectReferenceInstanceIDValue);
430-
else
431-
temp = EditorGUIUtility.ObjectContent(obj, objType);
432-
}
433-
434-
if (property != null)
435-
{
436-
if (obj != null)
437-
{
438-
Object[] references = { obj };
439-
if (EditorSceneManager.preventCrossSceneReferences && CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject))
440-
{
441-
if (!EditorApplication.isPlaying)
442-
temp = s_SceneMismatch;
443-
else
444-
temp.text = temp.text + string.Format(" ({0})", GetGameObjectFromObject(obj).scene.name);
445-
}
446-
else if (validator(references, objType, property, ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null)
447-
temp = s_TypeMismatch;
448-
}
449-
}
413+
temp = EditorGUIUtility.ObjectContent(obj, objType, property, validator);
450414
}
451415

452416
switch (visualType)

Editor/Mono/GUI/ReorderableList.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ bool CheckForChildInvalidation()
140140
return false;
141141
}
142142

143+
internal void InvalidateForGUI()
144+
{
145+
if (!m_SerializedObject?.isEditingMultipleObjects ?? true)
146+
{
147+
InvalidateCache();
148+
}
149+
else
150+
{
151+
InvalidateExistingListCaches();
152+
EditorApplication.delayCall += InspectorWindow.RefreshInspectors;
153+
}
154+
}
155+
143156
// class for default rendering and behavior of reorderable list - stores styles and is statically available as s_Defaults
144157
public class Defaults
145158
{
@@ -160,7 +173,7 @@ public class Defaults
160173
internal const int minHeaderHeight = 2;
161174
const float elementPadding = 2;
162175
private int ArrayCountInPropertyPath(SerializedProperty prop) => Regex.Matches(prop.propertyPath, ".Array.data").Count;
163-
private float FieldLabelSize(Rect r, SerializedProperty prop) => r.xMax * 0.45f - 35 - prop.depth * 15 - ArrayCountInPropertyPath(prop) * 10;
176+
private float FieldLabelSize(Rect r, SerializedProperty prop) => r.width * 0.45f - 20 - ArrayCountInPropertyPath(prop) * 22 + (prop.depth < 2 ? 7 : 0);
164177
private static readonly GUIContent s_ListIsEmpty = EditorGUIUtility.TrTextContent("List is Empty");
165178
internal static readonly string undoAdd = "Add Element To Array";
166179
internal static readonly string undoRemove = "Remove Element From Array";
@@ -279,7 +292,7 @@ internal void DoAddButton(ReorderableList list, Object value)
279292
Debug.LogError("Cannot add element of type Null.");
280293
}
281294
Undo.SetCurrentGroupName(undoAdd);
282-
list.InvalidateCache();
295+
list.InvalidateForGUI();
283296
}
284297

285298
public void DoAddButton(ReorderableList list)
@@ -323,7 +336,7 @@ public void DoRemoveButton(ReorderableList list)
323336
}
324337
list.index = Mathf.Clamp(lastDeletedIndex - 1, 0, list.count - 1);
325338
Undo.SetCurrentGroupName(undoRemove);
326-
list.InvalidateCache();
339+
list.InvalidateForGUI();
327340
}
328341

329342
// draw the default header background

Editor/Mono/GameObjectUtility.bindings.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ public static void SetParentAndAlign(GameObject child, GameObject parent)
103103
SetLayerRecursively(child, parent.layer);
104104
}
105105

106+
internal static void SetDefaultParentForNewObject(GameObject gameObject, Transform parent = null, bool align = false)
107+
{
108+
if (parent == null && (parent = SceneView.GetDefaultParentObjectIfSet()) == null)
109+
{
110+
return;
111+
}
112+
113+
if(align)
114+
{
115+
GameObjectUtility.SetParentAndAlign(gameObject, parent?.gameObject);
116+
}
117+
else
118+
{
119+
gameObject.transform.SetParent(parent);
120+
}
121+
}
122+
106123
private static void SetLayerRecursively(GameObject go, int layer)
107124
{
108125
go.layer = layer;

Editor/Mono/Inspector/BlendTreeInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ private void ComputeProperty(GetFloatFromMotion func, ChildPropertyToCompute pro
16641664

16651665
if (variance < Mathf.Epsilon)
16661666
{
1667-
Debug.LogWarning("Could not compute threshold for '" + m_BlendTree.name + "' there is not enough data");
1667+
Debug.LogWarning($"Can't distribute the motions of '{m_BlendTree.name}', they all have the same threshold value.");
16681668
m_SerializedObject.Update();
16691669
}
16701670
else

0 commit comments

Comments
 (0)