Skip to content

Commit 2a49d60

Browse files
author
Unity Technologies
committed
Unity 2023.3.0b9 C# reference source code
1 parent 79868d3 commit 2a49d60

File tree

53 files changed

+941
-737
lines changed

Some content is hidden

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

53 files changed

+941
-737
lines changed

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ protected void PackPreviewGUI()
430430

431431
using (new GUILayout.HorizontalScope())
432432
{
433-
using (new EditorGUI.DisabledScope(!HasModified() || !IsValidAtlas()))
433+
using (new EditorGUI.DisabledScope(!HasModified() || !IsValidAtlas() || Application.isPlaying))
434434
{
435435
GUILayout.FlexibleSpace();
436436

Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public override void OnInspectorGUI()
376376

377377
bool spriteAtlasPackignEnabled = (EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnlyAtlas
378378
|| EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOnAtlas || EditorSettings.spritePackerMode == SpritePackerMode.SpriteAtlasV2);
379-
if (spriteAtlasPackignEnabled)
379+
if (spriteAtlasPackignEnabled && !Application.isPlaying)
380380
{
381381
if (GUILayout.Button(styles.packButton, GUILayout.ExpandWidth(false)))
382382
{

Editor/Mono/AssetsMenuUtility.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ internal enum ScriptTemplate
1515
CSharp_NewPlayableAsset,
1616
CSharp_NewScriptableObjectScript,
1717
Shader_NewUnlitShader,
18-
AsmDef_NewAssembly,
1918
AsmDef_NewEditModeTestAssembly,
2019
AsmDef_NewTestAssembly,
20+
AsmDef_NewAssembly,
2121
AsmRef_NewAssemblyReference,
2222
CSharp_NewEmptyScript,
2323
CSharp_NewTestScript,

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using UnityEditor.Audio;
99
using UnityEditor.Audio.UIElements;
10+
using UnityEditor.ShortcutManagement;
1011
using UnityEditor.UIElements;
1112
using UnityEngine;
1213
using UnityEngine.Assertions;
@@ -276,6 +277,7 @@ void SubscribeToGUICallbacksAndEvents()
276277
SubscribeToPitchCallbacksAndEvents();
277278
SubscribeToClipListCallbacksAndEvents();
278279
SubscribeToAutomaticTriggerCallbacksAndEvents();
280+
SubscribeToTooltipCallbacksAndEvents();
279281
m_IsSubscribedToGUICallbacksAndEvents = true;
280282
}
281283

@@ -286,6 +288,7 @@ void UnsubscribeFromGUICallbacksAndEvents()
286288
UnsubscribeFromPitchCallbacksAndEvents();
287289
UnsubscribeFromClipListCallbacksAndEvents();
288290
UnsubscribeFromAutomaticTriggerCallbacksAndEvents();
291+
UnsubscribeFromTooltipCallbacksAndEvents();
289292
m_IsSubscribedToGUICallbacksAndEvents = false;
290293
}
291294

@@ -1089,6 +1092,39 @@ void UnsubscribeFromAutomaticTriggerCallbacksAndEvents()
10891092
m_TimeRandomizationRangeSlider?.UnregisterValueChangedCallback(OnTimeRandomizationRangeChanged);
10901093
}
10911094

1095+
void SubscribeToTooltipCallbacksAndEvents()
1096+
{
1097+
rootVisualElement.RegisterCallback<TooltipEvent>(ShowTooltip, TrickleDown.TrickleDown);
1098+
}
1099+
1100+
void UnsubscribeFromTooltipCallbacksAndEvents()
1101+
{
1102+
rootVisualElement.UnregisterCallback<TooltipEvent>(ShowTooltip);
1103+
}
1104+
1105+
void ShowTooltip(TooltipEvent evt)
1106+
{
1107+
var name = (evt.target as VisualElement).name;
1108+
1109+
if (name == "play-button" || name == "play-button-image")
1110+
{
1111+
var mode = State.IsPlayingOrPaused() ? "Stop" : "Play";
1112+
var shortcut = ShortcutManager.instance.GetShortcutBinding("Audio/Play-stop Audio Random Container");
1113+
1114+
if (shortcut.Equals(ShortcutBinding.empty))
1115+
{
1116+
evt.tooltip = mode;
1117+
}
1118+
else
1119+
{
1120+
evt.tooltip = mode + " (" + shortcut + ")";
1121+
}
1122+
1123+
evt.rect = (evt.target as VisualElement).worldBound;
1124+
evt.StopPropagation();
1125+
}
1126+
}
1127+
10921128
void BindAndTrackAutomaticTriggerProperties()
10931129
{
10941130
var automaticTriggerModeProperty = State.SerializedObject.FindProperty("m_AutomaticTriggerMode");
@@ -1321,4 +1357,19 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
13211357
}
13221358

13231359
#endregion
1360+
1361+
#region Shortcuts
1362+
1363+
[Shortcut("Audio/Play-stop Audio Random Container", typeof(AudioContainerWindow), KeyCode.P, ShortcutModifiers.Alt)]
1364+
static void Preview(ShortcutArguments args)
1365+
{
1366+
var audioContainerWindow = focusedWindow as AudioContainerWindow;
1367+
1368+
if (audioContainerWindow != null && audioContainerWindow.IsDisplayingTarget())
1369+
{
1370+
audioContainerWindow.OnPlayStopButtonClicked();
1371+
}
1372+
}
1373+
1374+
#endregion
13241375
}

Editor/Mono/BuildProfile/BuildProfileContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal BuildProfile activeProfile
5050
get
5151
{
5252
// Active Build profile may be deleted from the project.
53-
if (m_ActiveProfile != null)
53+
if (m_ActiveProfile != null && BuildProfileModuleUtil.IsModuleInstalled(m_ActiveProfile.moduleName, m_ActiveProfile.subtarget))
5454
return m_ActiveProfile;
5555

5656
m_ActiveProfile = null;

Editor/Mono/Categorize.cs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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 System;
6+
using System.Collections;
7+
using System.Collections.Generic;
8+
using System.Reflection;
9+
using UnityEngine.Categorization;
10+
using Unity.Collections;
11+
12+
namespace UnityEditor.Categorization
13+
{
14+
/* Sorting API that rely on DisplayCategory and DisplaySubCategory */
15+
16+
internal interface ICategorizable
17+
{
18+
Type type { get; }
19+
}
20+
21+
interface IOrdering
22+
{
23+
string name { get; }
24+
int order { get; }
25+
}
26+
27+
//Need to be a class to prevent loop definition with leaf that can cause issue when loading type through reflection
28+
internal class Category<T> : IEnumerable<T>, IOrdering
29+
where T : ICategorizable, IOrdering
30+
{
31+
public List<T> content { get; private set; }
32+
public string name { get; private set; }
33+
public int order { get; private set; }
34+
public Type type => content.Count > 0 ? content[0].type : null;
35+
public T this[int i] => content[i];
36+
public int count => content.Count;
37+
38+
public Category(string name, int order)
39+
{
40+
content = new();
41+
this.name = name;
42+
this.order = order;
43+
}
44+
45+
public void Add(T newElement, IComparer<T> comparer)
46+
=> content.AddSorted(newElement, comparer);
47+
48+
public IEnumerator<T> GetEnumerator() => content.GetEnumerator();
49+
IEnumerator IEnumerable.GetEnumerator() => content.GetEnumerator();
50+
}
51+
52+
internal struct LeafElement<T> : IOrdering, ICategorizable
53+
where T : ICategorizable
54+
{
55+
public T data { get; private set; }
56+
public static implicit operator T(LeafElement<T> leaftElement)
57+
=> leaftElement.data;
58+
59+
public string name { get; private set; }
60+
public int order { get; private set; }
61+
public Category<LeafElement<T>> parent { get; private set; }
62+
public Type type => typeof(T);
63+
64+
public LeafElement(T data, string name, int order, Category<LeafElement<T>> parent)
65+
{
66+
this.data = data;
67+
this.name = name;
68+
this.order = order;
69+
this.parent = parent;
70+
}
71+
}
72+
73+
internal static class CategorizeHelper
74+
{
75+
struct OrderingComparer<T> : IComparer<T>
76+
where T : IOrdering
77+
{
78+
public int Compare(T a, T b)
79+
{
80+
var order = a.order.CompareTo(b.order);
81+
if (order != 0)
82+
return order;
83+
return a.name.CompareTo(b.name);
84+
}
85+
}
86+
87+
internal static List<Category<LeafElement<T>>> SortByCategory<T>(this List<T> list)
88+
where T : ICategorizable
89+
{
90+
var categories = new Dictionary<string, Category<LeafElement<T>>>();
91+
var result = new List<Category<LeafElement<T>>>();
92+
var comparerLeaf = new OrderingComparer<LeafElement<T>>();
93+
var comparerCategory = new OrderingComparer<Category<LeafElement<T>>>();
94+
95+
foreach(var entry in list)
96+
{
97+
var type = entry.type;
98+
CategoryInfoAttribute categoryInfo = type.GetCustomAttribute<CategoryInfoAttribute>();
99+
ElementInfoAttribute displayInfo = type.GetCustomAttribute<ElementInfoAttribute>();
100+
int categoryOrder = categoryInfo?.Order ?? int.MaxValue;
101+
int inCategoryOrder = displayInfo?.Order ?? int.MaxValue;
102+
string categoryName = categoryInfo?.Name
103+
// Keep compatibility with previous used attribute for 23.3LTS
104+
?? type.GetCustomAttribute<System.ComponentModel.CategoryAttribute>()?.Category;
105+
string name = displayInfo?.Name ?? ObjectNames.NicifyVariableName(type.Name);
106+
categoryName ??= name;
107+
108+
Category<LeafElement<T>> category;
109+
if (!categories.TryGetValue(categoryName, out category))
110+
{
111+
category = new Category<LeafElement<T>>(categoryName, categoryOrder);
112+
categories[categoryName] = category;
113+
result.AddSorted(category, comparerCategory);
114+
}
115+
116+
category.Add(new LeafElement<T>(entry, name, inCategoryOrder, category), comparerLeaf);
117+
}
118+
119+
return result;
120+
}
121+
}
122+
}

Editor/Mono/Inspector/Core/PropertyEditor.cs

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class PropertyEditor : EditorWindow, IPropertyView, IHasCustomMenu
148148
internal static PropertyEditor FocusedPropertyEditor { get; private set; }
149149

150150
EditorElementUpdater m_EditorElementUpdater;
151+
IPreviewable m_cachedPreviewEditor;
151152

152153
public InspectorMode inspectorMode
153154
{
@@ -1132,44 +1133,38 @@ internal virtual void RebuildContentsContainers()
11321133
if (previewAndLabelElement != null && !hasFloatingPreviewWindow)
11331134
{
11341135
VisualElement previewItem = null;
1135-
CreatePreviewables();
1136-
IPreviewable[] editorsWithPreviews = GetEditorsWithPreviews(tracker.activeEditors);
1137-
m_cachedPreviewEditor = GetEditorThatControlsPreview(editorsWithPreviews);
1136+
CreatePreviewables();
1137+
IPreviewable[] editorsWithPreviews = GetEditorsWithPreviews(tracker.activeEditors);
1138+
m_cachedPreviewEditor = GetEditorThatControlsPreview(editorsWithPreviews);
11381139

1139-
if (m_cachedPreviewEditor != null && m_cachedPreviewEditor.HasPreviewGUI())
1140-
{
1141-
if (previewWindow == null)
1142-
previewWindow = new InspectorPreviewWindow();
1140+
if (m_cachedPreviewEditor != null && m_cachedPreviewEditor.HasPreviewGUI())
1141+
{
1142+
previewWindow = new InspectorPreviewWindow();
11431143

1144-
preview = m_SplitView.Q(s_PreviewContainer);
1145-
IStyle style = preview.style;
1146-
style.minHeight = m_PreviewMinHeight;
1147-
previewItem = m_cachedPreviewEditor.CreatePreview(previewWindow);
1144+
preview = m_SplitView.Q(s_PreviewContainer);
1145+
preview.style.minHeight = m_PreviewMinHeight;
11481146

1149-
if (previewItem != null)
1150-
{
1151-
// Temporary naming while in transition to UITK
1152-
InitUITKPreview();
1153-
}
1147+
previewItem = m_cachedPreviewEditor.CreatePreview(previewWindow);
11541148

1155-
// IMGUI fallback if no UITK preview found
1156-
if (previewItem == null)
1157-
{
1158-
var previewAndLabelsContainer =
1159-
CreateIMGUIContainer(DrawPreviewAndLabels, s_PreviewContainer);
1160-
m_PreviewResizer.SetContainer(previewAndLabelsContainer, kBottomToolbarHeight);
1161-
previewAndLabelElement.Add(previewAndLabelsContainer);
1149+
if (previewItem != null)
1150+
{
1151+
// Temporary naming while in transition to UITK
1152+
InitUITKPreview();
1153+
preview.Add(previewWindow);
1154+
}
1155+
else // IMGUI fallback if no UITK preview found
1156+
{
1157+
var previewAndLabelsContainer =
1158+
CreateIMGUIContainer(DrawPreviewAndLabels, s_PreviewContainer);
1159+
m_PreviewResizer.SetContainer(previewAndLabelsContainer, kBottomToolbarHeight);
1160+
previewAndLabelElement.Add(previewAndLabelsContainer);
11621161

1163-
if (preview == null)
1164-
m_SplitView.Add(previewAndLabelElement);
1165-
}
1166-
else
1167-
{
1168-
preview = m_SplitView.Q(s_PreviewContainer);
1169-
preview.Add(previewWindow);
1170-
}
1162+
if (preview == null)
1163+
m_SplitView.Add(previewAndLabelElement);
11711164
}
1165+
}
11721166
}
1167+
11731168
// Footer
11741169
if (previewAndLabelElement?.childCount == 0)
11751170
{
@@ -1269,8 +1264,6 @@ private void OnDraglineGeometryChange(VisualElement window, VisualElement dragli
12691264
dragline.style.marginRight = margin;
12701265
}
12711266

1272-
private IPreviewable m_cachedPreviewEditor;
1273-
12741267
internal void PrepareToolbar(InspectorPreviewWindow toolbar, bool isFloatingPreviewWindow = false)
12751268
{
12761269
IPreviewable[] editorsWithPreviews = GetEditorsWithPreviews(tracker.activeEditors);

Editor/Mono/Inspector/UnityEventDrawer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property)
279279
var header = new Label();
280280
header.text = GetHeaderText();
281281
header.tooltip = property.tooltip;
282+
BindingsStyleHelpers.RegisterRightClickMenu(header, property);
282283
header.AddToClassList(kHeaderClassName);
283284

284285
var listView = CreateListView(property);

0 commit comments

Comments
 (0)