Skip to content

Commit 79d86f8

Browse files
author
Unity Technologies
committed
Unity 2022.2.0a11 C# reference source code
1 parent 0a2eeb7 commit 79d86f8

File tree

102 files changed

+4843
-1096
lines changed

Some content is hidden

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

102 files changed

+4843
-1096
lines changed

Editor/IncrementalBuildPipeline/ScriptCompilationBuildProgram.Data/Data.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static class Constants
1414
public class ScriptCompilationData
1515
{
1616
public AssemblyData[] Assemblies;
17+
public AssemblyData[] CodegenAssemblies;
1718
public string DotnetRuntimePath;
1819
public string DotnetRoslynPath;
1920
public string MovedFromExtractorPath;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 UnityEngine.Bindings;
6+
7+
namespace UnityEditor
8+
{
9+
[NativeHeader("Modules/AssetPipelineEditor/Public/BrokenPrefabAsset.h")]
10+
public class BrokenPrefabAsset : DefaultAsset
11+
{
12+
private BrokenPrefabAsset() {}
13+
14+
public extern BrokenPrefabAsset brokenPrefabParent { get; }
15+
public extern bool isVariant { get; }
16+
public extern bool isPrefabFileValid { get; }
17+
}
18+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 UnityEditor.UIElements;
6+
using UnityEngine;
7+
using UnityEngine.UIElements;
8+
9+
namespace UnityEditor
10+
{
11+
[CustomEditor(typeof(BrokenPrefabAsset))]
12+
class BrokenPrefabAssetEditor : Editor
13+
{
14+
public override VisualElement CreateInspectorGUI()
15+
{
16+
var container = new VisualElement();
17+
18+
var brokenPrefab = (BrokenPrefabAsset)target;
19+
20+
container.Add(new HelpBox(
21+
brokenPrefab.message,
22+
brokenPrefab.isWarning ? HelpBoxMessageType.Error : HelpBoxMessageType.Info));
23+
24+
if (brokenPrefab.isVariant)
25+
{
26+
var brokenPrefabParent = brokenPrefab.brokenPrefabParent;
27+
var field = new ObjectField("Variant Parent");
28+
field.SetEnabled(false);
29+
if(brokenPrefabParent != null)
30+
{
31+
field.value = brokenPrefabParent;
32+
field.objectType = typeof(BrokenPrefabAsset);
33+
}
34+
else
35+
{
36+
//Hack to display "Missing" instead of "None"
37+
var missingGameObject = EditorUtility.CreateGameObjectWithHideFlags("Missing GameObject for Object Field", HideFlags.HideAndDontSave);
38+
DestroyImmediate(missingGameObject);
39+
field.value = missingGameObject;
40+
field.objectType = typeof(GameObject);
41+
}
42+
43+
container.Add(field);
44+
}
45+
46+
return container;
47+
}
48+
}
49+
}

Editor/Mono/DefaultAsset.bindings.cs

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

5-
using System;
6-
using UnityEngine;
75
using UnityEngine.Bindings;
6+
using UnityEngine.UIElements;
87

98
namespace UnityEditor
109
{
1110
[NativeHeader("Modules/AssetPipelineEditor/Public/DefaultImporter.h")]
1211
// This class is public for users to be able to make custom editors for this type (see case 656580)
1312
public class DefaultAsset : UnityEngine.Object
1413
{
15-
private DefaultAsset() {}
14+
private protected DefaultAsset() {}
1615
internal extern string message { get; }
1716
internal extern bool isWarning {[NativeName("IsWarning")] get; }
1817
}
1918

2019
[CustomEditor(typeof(DefaultAsset), isFallback = true)] // fallback so broad-matching user inspectors always win (e.g. case #656580)
2120
class DefaultAssetInspector : Editor
2221
{
23-
public override void OnInspectorGUI()
22+
public override VisualElement CreateInspectorGUI()
2423
{
24+
var container = new VisualElement();
25+
2526
var defaultAsset = (DefaultAsset)target;
2627
if (defaultAsset.message.Length > 0)
2728
{
28-
EditorGUILayout.HelpBox(
29+
var helpBox = new HelpBox(
2930
defaultAsset.message,
30-
defaultAsset.isWarning ? MessageType.Warning : MessageType.Info);
31+
defaultAsset.isWarning ? HelpBoxMessageType.Warning : HelpBoxMessageType.Info);
32+
container.Add(helpBox);
3133
}
34+
35+
return container;
3236
}
3337
}
3438
}

Editor/Mono/EditorApplication.bindings.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ internal static extern bool useLibmonoBackendForIl2cpp
164164
// Invokes the menu item in the specified path.
165165
public static bool ExecuteMenuItem(string menuItemPath)
166166
{
167+
var sanitizedPath = MenuService.SanitizeMenuItemName(menuItemPath);
167168
var isDefaultMode = ModeService.currentId == ModeService.k_DefaultModeId;
168-
var result = ExecuteMenuItemInternal(menuItemPath, isDefaultMode);
169+
var result = ExecuteMenuItemInternal(sanitizedPath, isDefaultMode);
169170
if (result)
170171
return result;
171172

@@ -175,7 +176,7 @@ public static bool ExecuteMenuItem(string menuItemPath)
175176
foreach (var item in menuItems)
176177
{
177178
MenuItem itemData = (MenuItem)item.GetCustomAttributes(typeof(MenuItem), false)[0];
178-
if (!itemData.validate && itemData.menuItem == menuItemPath)
179+
if (!itemData.validate && itemData.menuItem == sanitizedPath)
179180
{
180181
if (item.GetParameters().Length == 0)
181182
{

Editor/Mono/EditorApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public enum PlayModeStateChange
3232
internal enum ScriptChangesDuringPlayOptions
3333
{
3434
RecompileAndContinuePlaying = 0,
35-
RecompileAfterFinishedPlaying = 1,
35+
// RecompileAfterFinishedPlaying = 1, Deprecated feature
3636
StopPlayingAndRecompile = 2
3737
}
3838

Editor/Mono/EditorGUI.cs

Lines changed: 126 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,21 @@ internal class RecycledTextEditor : TextEditor
479479
{
480480
internal static bool s_ActuallyEditing = false; // internal so we can save this state.
481481
internal static bool s_AllowContextCutOrPaste = true; // e.g. selectable labels only allow for copying
482+
private long[] s_OriginalLongValues;
483+
private double[] s_OriginalDoubleValues;
482484

483485
IMECompositionMode m_IMECompositionModeBackup;
484486

487+
public long[] GetOriginalLongValues()
488+
{
489+
return s_OriginalLongValues;
490+
}
491+
492+
public double[] GetOriginalDoubleValues()
493+
{
494+
return s_OriginalDoubleValues;
495+
}
496+
485497
internal bool IsEditingControl(int id)
486498
{
487499
return GUIUtility.keyboardControl == id && controlID == id && s_ActuallyEditing && GUIView.current.hasFocus;
@@ -509,6 +521,29 @@ public virtual void BeginEditing(int id, string newText, Rect _position, GUIStyl
509521

510522
m_IMECompositionModeBackup = Input.imeCompositionMode;
511523
Input.imeCompositionMode = IMECompositionMode.On;
524+
525+
if (EditorGUI.s_PropertyStack.Count > 0)
526+
{
527+
var property = EditorGUI.s_PropertyStack.Peek().property;
528+
529+
switch (property.propertyType)
530+
{
531+
case SerializedPropertyType.Integer:
532+
s_OriginalLongValues = new long[property.serializedObject.targetObjectsCount];
533+
property.allLongValues.CopyTo(s_OriginalLongValues, 0);
534+
break;
535+
536+
case SerializedPropertyType.Float:
537+
s_OriginalDoubleValues = new double[property.serializedObject.targetObjectsCount];
538+
property.allDoubleValues.CopyTo(s_OriginalDoubleValues, 0);
539+
break;
540+
541+
default:
542+
s_OriginalDoubleValues = null;
543+
s_OriginalLongValues = null;
544+
break;
545+
}
546+
}
512547
}
513548

514549
public virtual void EndEditing()
@@ -1189,6 +1224,17 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
11891224
s_OriginalText = "";
11901225
}
11911226

1227+
if (s_PropertyStack.Count > 0)
1228+
{
1229+
if (s_RecycledEditor.GetOriginalDoubleValues() != null)
1230+
s_PropertyStack.Peek().property.allDoubleValues =
1231+
s_RecycledEditor.GetOriginalDoubleValues();
1232+
1233+
if (s_RecycledEditor.GetOriginalLongValues() != null)
1234+
s_PropertyStack.Peek().property.allLongValues =
1235+
s_RecycledEditor.GetOriginalLongValues();
1236+
}
1237+
11921238
editor.text = s_OriginalText;
11931239

11941240
editor.EndEditing();
@@ -2345,6 +2391,60 @@ internal static void DoNumberField(RecycledTextEditor editor, Rect position, Rec
23452391
}
23462392
}
23472393

2394+
internal static void StringToNumericValue(in string str, ref NumberFieldValue value)
2395+
{
2396+
if (value.isDouble)
2397+
StringToDouble(str, ref value);
2398+
else
2399+
StringToLong(str, ref value);
2400+
}
2401+
2402+
internal static void EvaluateExpressionOnNumberFieldValue(ref NumberFieldValue value)
2403+
{
2404+
if (value.isDouble)
2405+
value.success = value.expression.Evaluate(ref value.doubleVal);
2406+
else
2407+
value.success = value.expression.Evaluate(ref value.longVal);
2408+
}
2409+
2410+
internal static void GetInitialValue(ref NumberFieldValue value)
2411+
{
2412+
if (value.isDouble)
2413+
{
2414+
double oldValue = default;
2415+
if (UINumericFieldsUtils.StringToDouble(s_OriginalText, out oldValue) && oldValue != value.doubleVal)
2416+
{
2417+
value.doubleVal = oldValue;
2418+
return;
2419+
}
2420+
}
2421+
else
2422+
{
2423+
long oldValue = default;
2424+
if (UINumericFieldsUtils.StringToLong(s_OriginalText, out oldValue) && oldValue != value.longVal)
2425+
{
2426+
value.longVal = oldValue;
2427+
return;
2428+
}
2429+
}
2430+
}
2431+
2432+
internal static void UpdateNumberValueIfNeeded(ref NumberFieldValue value, in string str)
2433+
{
2434+
StringToNumericValue(str, ref value);
2435+
2436+
if (!value.success && value.expression != null)
2437+
{
2438+
using (s_EvalExpressionMarker.Auto())
2439+
{
2440+
GetInitialValue(ref value);
2441+
2442+
EvaluateExpressionOnNumberFieldValue(ref value);
2443+
}
2444+
}
2445+
2446+
GUI.changed = value.success || value.expression != null;
2447+
}
23482448
internal static void DoNumberField(RecycledTextEditor editor, Rect position, Rect dragHotZone, int id,
23492449
ref NumberFieldValue value, string formatString, GUIStyle style, bool draggable,
23502450
double dragSensitivity)
@@ -2378,25 +2478,14 @@ internal static void DoNumberField(RecycledTextEditor editor, Rect position, Rec
23782478
str = value.isDouble ? value.doubleVal.ToString(formatString, CultureInfo.InvariantCulture) : value.longVal.ToString(formatString, CultureInfo.InvariantCulture);
23792479
}
23802480

2381-
if (GUIUtility.keyboardControl == id)
2382-
{
2383-
str = DoTextField(editor, id, position, str, style, allowedCharacters, out changed, false, false, false);
2481+
str = DoTextField(editor, id, position, str, style, allowedCharacters, out changed, false, false, false);
23842482

2483+
if (GUIUtility.keyboardControl == id && changed)
2484+
{
23852485
// If we are still actively editing, return the input values
2386-
if (changed)
2387-
{
2388-
GUI.changed = true;
2389-
s_RecycledCurrentEditingString = str;
2486+
s_RecycledCurrentEditingString = str;
23902487

2391-
if (value.isDouble)
2392-
StringToDouble(str, ref value);
2393-
else
2394-
StringToLong(str, ref value);
2395-
}
2396-
}
2397-
else
2398-
{
2399-
DoTextField(editor, id, position, str, style, allowedCharacters, out changed, false, false, false);
2488+
UpdateNumberValueIfNeeded(ref value, str);
24002489
}
24012490
}
24022491

@@ -2622,11 +2711,7 @@ static void DelayedNumberFieldInternal(Rect position, Rect dragHotZone, int id,
26222711
}
26232712
else
26242713
{
2625-
GUI.changed = true;
2626-
if (value.isDouble)
2627-
StringToDouble(str, ref value);
2628-
else
2629-
StringToLong(str, ref value);
2714+
UpdateNumberValueIfNeeded(ref value, str);
26302715
}
26312716
GUI.changed |= wasChanged;
26322717
}
@@ -6581,7 +6666,7 @@ internal static GUIContent BeginPropertyInternal(Rect totalPosition, GUIContent
65816666
Highlighter.HighlightIdentifier(totalPosition, property.propertyPath);
65826667

65836668
s_PropertyFieldTempContent.text = (label == null) ? property.localizedDisplayName : label.text; // no necessary to be translated.
6584-
s_PropertyFieldTempContent.tooltip = (label == null) ? property.tooltip : label.tooltip;
6669+
s_PropertyFieldTempContent.tooltip = (label == null || string.IsNullOrEmpty(label.tooltip)) ? property.tooltip : label.tooltip;
65856670
s_PropertyFieldTempContent.image = label?.image;
65866671

65876672
// In inspector debug mode & when holding down alt. Show the property path of the property.
@@ -7265,9 +7350,14 @@ internal static bool DefaultPropertyField(Rect position, SerializedProperty prop
72657350
{
72667351
using (s_EvalExpressionMarker.Auto())
72677352
{
7353+
var originalValues = s_RecycledEditor.GetOriginalLongValues();
7354+
72687355
var values = property.allLongValues;
72697356
for (var i = 0; i < values.Length; ++i)
7357+
{
7358+
values[i] = originalValues[i];
72707359
val.expression.Evaluate(ref values[i], i, values.Length);
7360+
}
72717361
property.allLongValues = values;
72727362
}
72737363
}
@@ -7296,14 +7386,24 @@ internal static bool DefaultPropertyField(Rect position, SerializedProperty prop
72967386
{
72977387
using (s_EvalExpressionMarker.Auto())
72987388
{
7389+
var originalValues = s_RecycledEditor.GetOriginalDoubleValues();
7390+
72997391
var values = property.allDoubleValues;
7392+
bool changed = false;
73007393
for (var i = 0; i < values.Length; ++i)
73017394
{
7302-
val.expression.Evaluate(ref values[i], i, values.Length);
7303-
if (isFloat)
7304-
values[i] = MathUtils.ClampToFloat(values[i]);
7395+
values[i] = originalValues[i];
7396+
if (val.expression.Evaluate(ref values[i], i, values.Length))
7397+
{
7398+
if (isFloat)
7399+
values[i] = MathUtils.ClampToFloat(values[i]);
7400+
7401+
changed = true;
7402+
}
73057403
}
7306-
property.allDoubleValues = values;
7404+
7405+
if (changed)
7406+
property.allDoubleValues = values;
73077407
}
73087408
}
73097409
else

Editor/Mono/EditorMode/MenuService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,14 @@ private static void AddMenuItemsFromMode(Dictionary<string, MenuItemScriptComman
428428
}
429429
}
430430

431-
private static string SanitizeMenuItemName(string menuName)
431+
internal static string SanitizeMenuItemName(string menuName)
432432
{
433433
while (menuName.StartsWith("/"))
434434
{
435435
menuName = menuName.Substring(1);
436436
}
437+
// replace double // separators with /
438+
menuName = System.Text.RegularExpressions.Regex.Replace(menuName, "//", "/");
437439
// removing trailing "/" is already done when building the tree because we're removing empty entries when splitting the menu name with /
438440
return menuName;
439441
}

0 commit comments

Comments
 (0)