Skip to content

Commit 7aa6e4f

Browse files
author
Unity Technologies
committed
Unity 2022.1.0a8 C# reference source code
1 parent b88328c commit 7aa6e4f

File tree

54 files changed

+681
-145
lines changed

Some content is hidden

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

54 files changed

+681
-145
lines changed

Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEngine;
77
using UnityEngine.U2D;
88
using UnityEngine.Bindings;
9+
using System;
910

1011
namespace UnityEditor.U2D
1112
{
@@ -27,6 +28,11 @@ public class SpriteAtlasUtility
2728

2829
public static void PackAtlases(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true)
2930
{
31+
if (atlases == null)
32+
throw new ArgumentNullException("atlases", "Value for parameter atlases is null");
33+
foreach (var atlas in atlases)
34+
if (atlas == null)
35+
throw new ArgumentNullException("atlases", "One of the elements in atlases is null. Please check your Inputs.");
3036
PackAtlasesInternal(atlases, target, canCancel, false, true);
3137
}
3238
}

Editor/Mono/EditorGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,7 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
28392839

28402840
Object targetObject = property.serializedObject.targetObject;
28412841

2842-
var shouldDisplayPrefabContextMenuItems = property.prefabOverride;
2842+
var shouldDisplayPrefabContextMenuItems = property.prefabOverride || (linkedProperty?.prefabOverride ?? false);
28432843

28442844
// Only display the custom apply/revert menu for GameObjects/Components that are not part of a Prefab instance & variant.
28452845
var shouldDisplayApplyRevertProviderContextMenuItems = targetObject is IApplyRevertPropertyContextMenuItemProvider

Editor/Mono/FileUtil.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.IO;
99
using System.Text.RegularExpressions;
1010
using UnityEngine;
11+
using UnityEngine.Scripting;
1112

1213
namespace UnityEditor
1314
{
@@ -333,6 +334,7 @@ internal static bool HasReadOnly(IEnumerable<UnityEngine.Object> assets)
333334
return false;
334335
}
335336

337+
[RequiredByNativeCode]
336338
internal static bool MakeWritable(string path)
337339
{
338340
string absolutePath = FileUtil.PathToAbsolutePath(path);

Editor/Mono/Inspector/InspectorWindow.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Linq;
8+
using UnityEditor.Profiling;
89
using UnityEngine;
910
using UnityEngine.Scripting;
1011
using UnityEngine.UIElements;
@@ -83,6 +84,23 @@ protected override void OnEnable()
8384

8485
EditorApplication.projectWasLoaded += OnProjectWasLoaded;
8586
Selection.selectionChanged += OnSelectionChanged;
87+
AssemblyReloadEvents.afterAssemblyReload += OnAfterAssemblyReload;
88+
}
89+
90+
private void OnAfterAssemblyReload()
91+
{
92+
// Case 1348788: After reloading the assemblies after a script compilation,
93+
// active editors are not rebuilt automatically. If a custom editor changed
94+
// the way it handles multi object editing you won't see the effect in the inspector unless
95+
// you change the selection. It is a minor issue. But this call makes sure to rebuild the active
96+
// editors if necessary.
97+
// Note: This is only a problem when adding the attribute CanEditMultipleObjects. When the attribute is not
98+
// there, the editor used for multi editing is the generic inspector. If you add the CanEditMultipleObjects attribute,
99+
// a refresh is triggered and we check if the editor instance is still valid, which is the case for the generic inspector
100+
// so we don't rebuild it. When removing the CanEditMultipleObjects, the refresh sees that the editor was the custom inspector
101+
// but its instance is no longer valid, so it rebuilds the inspector.
102+
if (EditorsForMultiEditingChanged())
103+
tracker.ForceRebuild();
86104
}
87105

88106
private void OnProjectWasLoaded()
@@ -127,6 +145,7 @@ protected override void OnDisable()
127145

128146
EditorApplication.projectWasLoaded -= OnProjectWasLoaded;
129147
Selection.selectionChanged -= OnSelectionChanged;
148+
AssemblyReloadEvents.afterAssemblyReload -= OnAfterAssemblyReload;
130149
}
131150

132151
static internal void RepaintAllInspectors()
@@ -438,5 +457,30 @@ internal Object[] GetInspectedObjects()
438457
return null;
439458
return editor.targets;
440459
}
460+
461+
private bool EditorsForMultiEditingChanged()
462+
{
463+
foreach (var editor in tracker.activeEditors)
464+
{
465+
if (EditorForMultiEditingChanged(editor, editor.target))
466+
return true;
467+
}
468+
469+
return false;
470+
}
471+
472+
private static bool EditorForMultiEditingChanged(Editor editor, Object target)
473+
{
474+
if (editor.targets.Length <= 1)
475+
return false;
476+
477+
var currentEditorType = editor.GetType();
478+
var expectedEditorType = CustomEditorAttributes.FindCustomEditorType(target, true);
479+
480+
// Going from generic to generic inspector for multi editing is correctly handled.
481+
if (editor is GenericInspector && expectedEditorType == null)
482+
return false;
483+
return currentEditorType != expectedEditorType;
484+
}
441485
}
442486
}

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2861,7 +2861,7 @@ private void OtherSectionOptimizationGUI(BuildPlatform platform)
28612861
}
28622862

28632863
static ManagedStrippingLevel[] mono_levels = new ManagedStrippingLevel[] { ManagedStrippingLevel.Disabled, ManagedStrippingLevel.Minimal, ManagedStrippingLevel.Low, ManagedStrippingLevel.Medium, ManagedStrippingLevel.High };
2864-
static ManagedStrippingLevel[] il2cpp_levels = new ManagedStrippingLevel[] { ManagedStrippingLevel.Low, ManagedStrippingLevel.Minimal, ManagedStrippingLevel.Medium, ManagedStrippingLevel.High };
2864+
static ManagedStrippingLevel[] il2cpp_levels = new ManagedStrippingLevel[] { ManagedStrippingLevel.Minimal, ManagedStrippingLevel.Low, ManagedStrippingLevel.Medium, ManagedStrippingLevel.High };
28652865
// stripping levels vary based on scripting backend
28662866
private ManagedStrippingLevel[] GetAvailableManagedStrippingLevels(ScriptingImplementation backend)
28672867
{

Editor/Mono/Inspector/PreviewRenderUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public void BeginPreview(Rect r, GUIStyle previewBackground)
237237
RenderSettings.ambientLight = ambientColor;
238238

239239
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
240-
RenderSettings.customReflection = defaultEnvTexture as Cubemap;
240+
RenderSettings.customReflectionTexture = defaultEnvTexture;
241241
}
242242

243243
InitPreview(r);
@@ -272,7 +272,7 @@ public void BeginStaticPreview(Rect r)
272272
// Most preview windows just want the light probe from the main scene so by default we copy it here. It can then be overridden if user wants.
273273
RenderSettings.ambientProbe = oldProbe;
274274
RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
275-
RenderSettings.customReflection = defaultEnvTexture as Cubemap;
275+
RenderSettings.customReflectionTexture = defaultEnvTexture;
276276
}
277277
}
278278
}

Editor/Mono/Prefabs/PrefabUtility.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,24 +1152,32 @@ public static void RevertRemovedComponent(GameObject instanceGameObject, Compone
11521152
{
11531153
ThrowExceptionIfNotValidPrefabInstanceObject(instanceGameObject, false);
11541154

1155+
// Check dependencies
1156+
string dependentComponents = string.Join(
1157+
", ",
1158+
GetRemovedComponentDependencies(assetComponent, instanceGameObject, OverrideOperation.Revert).Select(e => ObjectNames.GetInspectorTitle(e)).ToArray());
1159+
if (!string.IsNullOrEmpty(dependentComponents))
1160+
{
1161+
string error = String.Format(
1162+
L10n.Tr("Can't revert removed component {0} because it depends on {1}."),
1163+
ObjectNames.GetInspectorTitle(assetComponent),
1164+
dependentComponents);
1165+
if (action == InteractionMode.UserAction)
1166+
{
1167+
EditorUtility.DisplayDialog(L10n.Tr("Can't revert removed component"), error, L10n.Tr("OK"));
1168+
}
1169+
else
1170+
{
1171+
Debug.LogError(error);
1172+
}
1173+
return;
1174+
}
1175+
11551176
var actionName = "Revert Prefab removed component";
11561177
var prefabInstanceObject = PrefabUtility.GetPrefabInstanceHandle(instanceGameObject);
11571178

11581179
if (action == InteractionMode.UserAction)
11591180
{
1160-
string dependentComponents = string.Join(
1161-
", ",
1162-
GetRemovedComponentDependencies(assetComponent, instanceGameObject, OverrideOperation.Revert).Select(e => ObjectNames.GetInspectorTitle(e)).ToArray());
1163-
if (!string.IsNullOrEmpty(dependentComponents))
1164-
{
1165-
string error = String.Format(
1166-
L10n.Tr("Can't revert removed component {0} because it depends on {1}."),
1167-
ObjectNames.GetInspectorTitle(assetComponent),
1168-
dependentComponents);
1169-
EditorUtility.DisplayDialog(L10n.Tr("Can't revert removed component"), error, L10n.Tr("OK"));
1170-
return;
1171-
}
1172-
11731181
Undo.RegisterCompleteObjectUndo(instanceGameObject, actionName);
11741182
}
11751183

@@ -1774,8 +1782,10 @@ public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, Repla
17741782

17751783
ReplacePrefabArgumentCheck(go, assetPath);
17761784

1785+
bool connectToInstance = ((replaceOptions & ReplacePrefabOptions.ConnectToPrefab) != 0) && !EditorUtility.IsPersistent(go);
1786+
17771787
bool success = false;
1778-
return SavePrefab_Internal(go, assetPath, (replaceOptions & ReplacePrefabOptions.ConnectToPrefab) != 0, out success);
1788+
return SavePrefab_Internal(go, assetPath, connectToInstance, out success);
17791789
}
17801790

17811791
// Returns the corresponding object from its immediate source from a connected Prefab,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static Scene CreateDefaultPreviewScene()
514514
// Setup default render settings for this preview scene
515515
Unsupported.SetOverrideLightingSettings(previewScene);
516516
UnityEngine.RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
517-
UnityEngine.RenderSettings.customReflection = GetDefaultReflection(); // ensure chrome materials do not render black
517+
UnityEngine.RenderSettings.customReflectionTexture = GetDefaultReflection(); // ensure chrome materials do not render black
518518
UnityEngine.RenderSettings.skybox = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Skybox.mat");
519519
UnityEngine.RenderSettings.ambientMode = AmbientMode.Skybox;
520520
UnityEditorInternal.InternalEditorUtility.CalculateAmbientProbeFromSkybox();

External/MirroredPackageSources/com.unity.ui.builder/Editor/Builder/Builder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ public override void OnEnableAfterAllSerialization()
205205
m_Selection.NotifyOfHierarchyChange(document);
206206
}
207207

208-
public override void LoadDocument(VisualTreeAsset asset, bool unloadAllSubdocuments = true)
208+
public override bool LoadDocument(VisualTreeAsset asset, bool unloadAllSubdocuments = true)
209209
{
210-
m_Toolbar.LoadDocument(asset, unloadAllSubdocuments);
210+
return m_Toolbar.LoadDocument(asset, unloadAllSubdocuments);
211211
}
212212

213213
public override bool NewDocument(bool checkForUnsavedChanges = true, bool unloadAllSubdocuments = true)

External/MirroredPackageSources/com.unity.ui.builder/Editor/Builder/BuilderPaneWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ public virtual void OnEnableAfterAllSerialization()
171171
// Nothing to do by default.
172172
}
173173

174-
public virtual void LoadDocument(VisualTreeAsset asset, bool unloadAllSubdocuments = true)
174+
public virtual bool LoadDocument(VisualTreeAsset asset, bool unloadAllSubdocuments = true)
175175
{
176-
// Nothing to do by default.
176+
return false;
177177
}
178178

179179
public virtual bool NewDocument(bool checkForUnsavedChanges = true, bool unloadAllSubdocuments = true)

0 commit comments

Comments
 (0)