Skip to content

Commit 6c247dc

Browse files
author
Unity Technologies
committed
Unity 2023.1.0a6 C# reference source code
1 parent a6cadb9 commit 6c247dc

70 files changed

Lines changed: 853 additions & 377 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/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Styles
5858
public readonly GUIContent paddingLabel = EditorGUIUtility.TrTextContent("Padding", "The amount of extra padding between packed sprites.");
5959

6060
public readonly GUIContent generateMipMapLabel = EditorGUIUtility.TrTextContent("Generate Mip Maps");
61+
public readonly GUIContent packPreviewLabel = EditorGUIUtility.TrTextContent("Pack Preview", "Save and preview packed Sprite Atlas textures.");
6162
public readonly GUIContent sRGBLabel = EditorGUIUtility.TrTextContent("sRGB", "Texture content is stored in gamma space.");
6263
public readonly GUIContent readWrite = EditorGUIUtility.TrTextContent("Read/Write", "Enable to be able to access the raw pixel data from code.");
6364
public readonly GUIContent variantMultiplierLabel = EditorGUIUtility.TrTextContent("Scale", "Down scale ratio.");
@@ -152,6 +153,7 @@ private enum AtlasType { Undefined = -1, Master = 0, Variant = 1 }
152153

153154
private float m_MipLevel = 0;
154155
private bool m_ShowAlpha;
156+
private bool m_Discard = false;
155157

156158
private List<string> m_PlatformSettingsOptions;
157159
private int m_SelectedPlatformSettings = 0;
@@ -406,7 +408,11 @@ protected override void Apply()
406408
if (HasModified())
407409
{
408410
if (spriteAtlasAsset)
411+
{
409412
SpriteAtlasAsset.Save(spriteAtlasAsset, m_AssetPath);
413+
AssetDatabase.ImportAsset(m_AssetPath);
414+
}
415+
410416
m_ContentHash = GetInspectorHash();
411417
}
412418
base.Apply();
@@ -424,7 +430,7 @@ protected void PackPreviewGUI()
424430
{
425431
GUILayout.FlexibleSpace();
426432

427-
if (GUILayout.Button("Pack Preview"))
433+
if (GUILayout.Button(styles.packPreviewLabel))
428434
{
429435
GUI.FocusControl(null);
430436
SpriteAtlasUtility.EnableV2Import(true);
@@ -445,7 +451,7 @@ private bool IsValidAtlas()
445451

446452
public override bool HasModified()
447453
{
448-
return base.HasModified() || m_ContentHash != GetInspectorHash();
454+
return !m_Discard && (base.HasModified() || m_ContentHash != GetInspectorHash());
449455
}
450456

451457
private void ValidateMasterAtlas()
@@ -829,6 +835,20 @@ private void HandlePackableListUI()
829835
}
830836
}
831837

838+
public override void SaveChanges()
839+
{
840+
if (!m_Discard)
841+
base.SaveChanges();
842+
m_ContentHash = GetInspectorHash();
843+
}
844+
845+
public override void DiscardChanges()
846+
{
847+
m_Discard = true;
848+
base.DiscardChanges();
849+
m_ContentHash = GetInspectorHash();
850+
}
851+
832852
void CachePreviewTexture()
833853
{
834854
var spriteAtlas = AssetDatabase.LoadAssetAtPath<SpriteAtlas>(m_AssetPath);

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ internal static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBu
633633
private static extern AssetBundleManifest BuildAssetBundlesWithInfoInternal(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget);
634634

635635
[FreeFunction("GetPlayerDataSessionId")]
636-
internal static extern string GetSessionIdForBuildTarget(BuildTarget target);
636+
internal static extern string GetSessionIdForBuildTarget(BuildTarget target, int subtarget);
637637

638638
[FreeFunction("ExtractCRCFromAssetBundleManifestFile")]
639639
public static extern bool GetCRCForAssetBundle(string targetPath, out uint crc);

Editor/Mono/BuildPipelineExperimental.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
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+
57
namespace UnityEditor.Experimental
68
{
9+
[Obsolete("BuildPipelineExperimental is no longer supported and will be removed")]
710
public static class BuildPipelineExperimental
811
{
912
public static string GetSessionIdForBuildTarget(BuildTarget target)
1013
{
11-
return BuildPipeline.GetSessionIdForBuildTarget(target);
14+
return BuildPipeline.GetSessionIdForBuildTarget(target, 0);
1215
}
1316
}
1417
}

Editor/Mono/Display/EditorDisplayManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private void UpdateAssociatedPlayModeView()
103103
m_views[i] = view;
104104
if (view != null)
105105
{
106-
EditorDisplayUtility.AddVirtualDisplay(i, (int)view.targetSize.x, (int)view.targetSize.y);
106+
EditorDisplayUtility.AddVirtualDisplay(i, Mathf.RoundToInt(view.targetSize.x), Mathf.RoundToInt(view.targetSize.y));
107107
}
108108
else
109109
{

Editor/Mono/EditorAssemblies.bindings.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace UnityEditor
1212
{
13-
[NativeHeader("Runtime/Mono/MonoAttributeHelpers.h")]
13+
[NativeHeader("Runtime/Scripting/TypeCache.h")]
1414
static partial class EditorAssemblies
1515
{
1616
const BindingFlags k_DefaultMethodBindingFlags =
@@ -27,31 +27,5 @@ internal static IEnumerable<MethodInfo> GetAllMethodsWithAttribute<T>(BindingFla
2727

2828
[FreeFunction(Name = "GetAllMethodsWithAttribute")]
2929
extern static object[] Internal_GetAllMethodsWithAttribute(Type attrType, BindingFlags staticness);
30-
31-
[Obsolete("Use public TypeCache.GetTypesWithAttribute<> API instead.")]
32-
internal static IEnumerable<Type> GetAllTypesWithAttribute<T>() where T : Attribute
33-
{
34-
return Internal_GetAllTypesWithAttribute(typeof(T));
35-
}
36-
37-
[FreeFunction(Name = "GetAllTypesWithAttribute")]
38-
extern static Type[] Internal_GetAllTypesWithAttribute(Type attrType);
39-
40-
[Obsolete("Use public TypeCache.GetTypesDerivedFrom<> API instead.")]
41-
internal static IEnumerable<Type> GetAllTypesWithInterface<T>() where T : class
42-
{
43-
return GetAllTypesWithInterface(typeof(T));
44-
}
45-
46-
[Obsolete("Use public TypeCache.GetTypesDerivedFrom<> API instead.")]
47-
private static IEnumerable<Type> GetAllTypesWithInterface(Type interfaceType)
48-
{
49-
if (!interfaceType.IsInterface)
50-
throw new ArgumentException(string.Format("Specified type {0} is not an interface.", interfaceType), nameof(interfaceType));
51-
return Internal_GetAllTypesWithInterface(interfaceType);
52-
}
53-
54-
[FreeFunction(Name = "GetAllTypesWithInterface")]
55-
extern static Type[] Internal_GetAllTypesWithInterface(Type interfaceType);
5630
}
5731
}

Editor/Mono/EditorAssemblies.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,6 @@ static internal IEnumerable<Type> loadedTypes
7070
get { return loadedAssemblies.SelectMany(assembly => AssemblyHelper.GetTypesFromAssembly(assembly)); }
7171
}
7272

73-
[Obsolete("Use public TypeCache.GetTypesDerivedFrom<> API instead.")]
74-
static internal IEnumerable<Type> SubclassesOf(Type parent)
75-
{
76-
return parent.IsInterface ?
77-
GetAllTypesWithInterface(parent) :
78-
SubclassesOfClass(parent);
79-
}
80-
81-
[Obsolete("Use public TypeCache.GetTypesDerivedFrom<> API instead.")]
82-
static internal IEnumerable<Type> SubclassesOfClass(Type parent)
83-
{
84-
Type[] types;
85-
if (!m_subClasses.TryGetValue(parent, out types))
86-
{
87-
types = loadedTypes.Where(klass => klass.IsSubclassOf(parent)).ToArray();
88-
m_subClasses[parent] = types;
89-
}
90-
return types;
91-
}
92-
93-
[Obsolete("Use public TypeCache.GetTypesDerivedFrom<> API instead.")]
94-
static internal IEnumerable<Type> SubclassesOfGenericType(Type genericType)
95-
{
96-
return loadedTypes.Where(klass => IsSubclassOfGenericType(klass, genericType));
97-
}
98-
9973
private static bool IsSubclassOfGenericType(Type klass, Type genericType)
10074
{
10175
if (klass.IsGenericType && klass.GetGenericTypeDefinition() == genericType)

Editor/Mono/EditorGUI.cs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ static class Styles
214214
public static Texture2D prefabOverlayRemovedIcon = EditorGUIUtility.LoadIcon("PrefabOverlayRemoved Icon");
215215
public static readonly GUIStyle linkButton = "FloatFieldLinkButton";
216216
public static Texture2D repaintDot = EditorGUIUtility.LoadIcon("RepaintDot");
217+
public static string revertPropertyValueIdenticalToSource = L10n.Tr("Revert (identical value to Prefab '{0}')");
217218
}
218219

219220
static EditorGUI()
@@ -3027,6 +3028,14 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
30273028
}
30283029
else if (shouldDisplayPrefabContextMenuItems)
30293030
{
3031+
bool samePropertyValueAsSource = false;
3032+
3033+
Object source = PrefabUtility.GetCorrespondingObjectFromSource(targetObject);
3034+
SerializedObject sourceSerializedObject = new SerializedObject(source);
3035+
SerializedProperty sourceProperty = sourceSerializedObject.FindProperty(property.propertyPath);
3036+
3037+
samePropertyValueAsSource = SerializedProperty.DataEquals(property, sourceProperty);
3038+
30303039
PrefabUtility.HandleApplyRevertMenuItems(
30313040
null,
30323041
targetObject,
@@ -3045,7 +3054,18 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
30453054
(menuItemContent) =>
30463055
{
30473056
// Add revert menu item.
3048-
pm.AddItem(menuItemContent, false, TargetChoiceHandler.RevertPrefabPropertyOverride, properties);
3057+
GUIContent content;
3058+
if (samePropertyValueAsSource)
3059+
{
3060+
GameObject sourceRoot = PrefabUtility.GetRootGameObject(source);
3061+
content = new GUIContent(string.Format(Styles.revertPropertyValueIdenticalToSource, sourceRoot.name));
3062+
}
3063+
else
3064+
{
3065+
content = menuItemContent;
3066+
}
3067+
3068+
pm.AddItem(content, false, TargetChoiceHandler.RevertPrefabPropertyOverride, properties);
30493069
},
30503070
false,
30513071
property.serializedObject.targetObjectsCount
@@ -5827,12 +5847,10 @@ static Rect GetSettingsRect(Rect position, GUIStyle baseStyle, GUIStyle iconButt
58275847

58285848
internal static bool EnableCheckBoxInTitlebar(Object targetObj)
58295849
{
5830-
if (targetObj is ScriptableObject && targetObj is StateMachineBehaviour)
5831-
return true;
5832-
else if (targetObj is ScriptableObject)
5850+
if (targetObj is ScriptableObject && targetObj is not StateMachineBehaviour)
58335851
return false;
5834-
else
5835-
return true;
5852+
5853+
return true;
58365854
}
58375855

58385856
// Make an inspector-window-like titlebar.
@@ -5865,17 +5883,24 @@ internal static void DoInspectorTitlebar(Rect position, int id, bool foldout, Ob
58655883
int enabled = -1;
58665884
foreach (Object targetObj in targetObjs)
58675885
{
5868-
int thisEnabled = EditorUtility.GetObjectEnabled(targetObj);
5869-
if (enabled == -1)
5886+
if (comp is MonoBehaviour)
58705887
{
5871-
if (EnableCheckBoxInTitlebar(targetObj))
5872-
enabled = thisEnabled;
5888+
enabled = 1;
58735889
}
5874-
else if (enabled != thisEnabled)
5890+
else
58755891
{
5876-
enabled = -2;
5877-
// Early out: mix value mode
5878-
break;
5892+
int thisEnabled = EditorUtility.GetObjectEnabled(targetObj);
5893+
if (enabled == -1)
5894+
{
5895+
if (EnableCheckBoxInTitlebar(targetObj))
5896+
enabled = thisEnabled;
5897+
}
5898+
else if (enabled != thisEnabled)
5899+
{
5900+
enabled = -2;
5901+
// Early out: mix value mode
5902+
break;
5903+
}
58795904
}
58805905
}
58815906

Editor/Mono/GUI/ReorderableList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ private float GetListElementHeight()
794794

795795
if (m_CacheCount == 0) CacheIfNeeded();
796796

797-
if (m_Count <= 0 || isOverMaxMultiEditLimit)
797+
if (count <= 0 || isOverMaxMultiEditLimit)
798798
height = elementHeight * (isOverMaxMultiEditLimit ? 2 : 1) + listElementPadding;
799799
else
800800
height = GetElementYOffset(m_Count - 1) + GetElementHeight(m_Count - 1) + listElementPadding;

Editor/Mono/HandleUtility.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,14 +1291,19 @@ internal static GameObject FindSelectionBaseForPicking(GameObject go)
12911291
// alternatively a GameObject with the SelectionBaseAttribute assigned.
12921292
Transform tr = go.transform;
12931293
GameObject outerMostSelectableRoot = null;
1294+
GameObject prefabBaseGo = null;
12941295

12951296
while (tr != null)
12961297
{
12971298
if (!SceneVisibilityState.IsGameObjectPickingDisabled(tr.gameObject))
12981299
{
1299-
// If we come across the prefab base, no need to search further
1300-
if (tr == prefabBase)
1301-
return tr.gameObject;
1300+
// If we come across the prefab base, we still need to make sure there are no
1301+
// go with the SelectionBaseAttribute assigned before returning prefabBaseGo.
1302+
if (tr == prefabBase && prefabBaseGo == null)
1303+
{
1304+
prefabBaseGo = tr.gameObject;
1305+
continue;
1306+
}
13021307

13031308
// Only test again nested prefab if go is already part of a prefab to avoid selecting a
13041309
// parent prefab is the current go is only child of this prefab but does not belong to it
@@ -1311,14 +1316,18 @@ internal static GameObject FindSelectionBaseForPicking(GameObject go)
13111316
outerMostSelectableRoot = tr.gameObject;
13121317
}
13131318

1314-
// If a SelectionBaseAttribute is found, select the nearest to the picked GameObject
1319+
// If a SelectionBaseAttribute is found, select the nearest to the picked GameObject.
1320+
// GameObjects with the SelectionBaseAttribute should have priority over all others.
13151321
if (AttributeHelper.GameObjectContainsAttribute<SelectionBaseAttribute>(tr.gameObject))
13161322
return tr.gameObject;
13171323
}
13181324

13191325
tr = tr.parent;
13201326
}
13211327

1328+
if (prefabBaseGo != null)
1329+
return prefabBaseGo;
1330+
13221331
return outerMostSelectableRoot;
13231332
}
13241333

Editor/Mono/Handles.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ public sealed partial class Handles
5050
// internal blend ratio for static colors
5151
internal static float staticBlend = 0.6f;
5252

53-
static PrefColor s_ElementPreselectionColor => new PrefColor("Scene/Element Preselection", .29f, .93f, .88f, 1f);
54-
static PrefColor s_ElementSelectionColor => new PrefColor("Scene/Element Selection", .93f, 1f, .99f, 1f);
53+
static PrefColor s_ElementColor => new PrefColor("Scene/Element Default", 0f, 224f / 255f, 1f, 1f);
54+
static PrefColor s_ElementPreselectionColor => new PrefColor("Scene/Element Preselection", 1f, 207f / 255f, 112f / 255f, 1f);
55+
static PrefColor s_ElementSelectionColor => new PrefColor("Scene/Element Selection", 1f, 182f / 255f, 40f / 255f, 1f);
5556

57+
public static Color elementColor => s_ElementColor;
5658
public static Color elementPreselectionColor => s_ElementPreselectionColor;
5759
public static Color elementSelectionColor => s_ElementSelectionColor;
5860

0 commit comments

Comments
 (0)