Skip to content

Commit 724ff72

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a14 C# reference source code
1 parent d0e1a5b commit 724ff72

File tree

146 files changed

+3314
-1287
lines changed

Some content is hidden

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

146 files changed

+3314
-1287
lines changed

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 47 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@ sealed class AudioContainerWindow : EditorWindow
2727
internal readonly AudioContainerWindowState State = new();
2828

2929
/// <summary>
30-
/// Holds the added list elements in the list interaction callbacks
30+
/// Holds the added list elements in the list interaction callbacks.
31+
/// Only used locally in these methods, but it's a global member to avoid GC.
3132
/// </summary>
3233
readonly List<AudioContainerElement> m_AddedElements = new();
3334

35+
readonly string k_EmptyGuidString = Guid.Empty.ToString("N");
36+
3437
VisualElement m_ContainerRootVisualElement;
3538
VisualElement m_Day0RootVisualElement;
3639

3740
// Preview section
3841
Label m_AssetNameLabel;
39-
Button m_PlayButton;
40-
VisualElement m_PlayButtonImage;
42+
Button m_PlayStopButton;
43+
VisualElement m_PlayStopButtonImage;
4144
Button m_SkipButton;
4245
VisualElement m_SkipButtonImage;
4346

@@ -94,7 +97,7 @@ sealed class AudioContainerWindow : EditorWindow
9497
bool m_IsInitializing;
9598
bool m_Day0ElementsInitialized;
9699
bool m_ContainerElementsInitialized;
97-
private bool m_ClipFieldProgressBarsAreCleared = true;
100+
bool m_ClipFieldProgressBarsAreCleared = true;
98101

99102
/// <summary>
100103
/// Holds the previous state of the list elements for undo/delete housekeeping
@@ -117,8 +120,6 @@ void OnEnable()
117120
{
118121
Instance = this;
119122

120-
Undo.undoRedoPerformed += OnUndoRedoPerformed;
121-
122123
State.TargetChanged += OnTargetChanged;
123124
State.TransportStateChanged += OnTransportStateChanged;
124125
State.EditorPauseStateChanged += EditorPauseStateChanged;
@@ -143,13 +144,14 @@ void OnDisable()
143144
UnsubscribeFromClipListCallbacksAndEvents();
144145
UnsubscribeFromAutomaticTriggerCallbacksAndEvents();
145146

146-
Undo.undoRedoPerformed -= OnUndoRedoPerformed;
147+
EditorApplication.update -= OneTimeEditorApplicationUpdate;
147148

148149
State.TargetChanged -= OnTargetChanged;
149150
State.TransportStateChanged -= OnTransportStateChanged;
150151
State.EditorPauseStateChanged -= EditorPauseStateChanged;
151152

152153
State.OnDestroy();
154+
153155
m_CachedElements.Clear();
154156
m_AddedElements.Clear();
155157
}
@@ -333,8 +335,8 @@ static void InsertUnitFieldForFloatField(VisualElement field, string unit)
333335
void InitializePreviewElements()
334336
{
335337
m_AssetNameLabel = UIToolkitUtilities.GetChildByName<Label>(m_ContainerRootVisualElement, "asset-name-label");
336-
m_PlayButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "play-button");
337-
m_PlayButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "play-button-image");
338+
m_PlayStopButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "play-button");
339+
m_PlayStopButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "play-button-image");
338340
m_SkipButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "skip-button");
339341
m_SkipButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "skip-button-image");
340342

@@ -344,17 +346,17 @@ void InitializePreviewElements()
344346

345347
void SubscribeToPreviewCallbacksAndEvents()
346348
{
347-
m_PlayButton.clicked += OnPlayStopButtonClicked;
349+
m_PlayStopButton.clicked += OnPlayStopButtonClicked;
348350
m_SkipButton.clicked += OnSkipButtonClicked;
349351
}
350352

351353
void UnsubscribeFromPreviewCallbacksAndEvents()
352354
{
353-
if (m_PlayButton != null)
354-
m_PlayButton.clicked -= OnPlayStopButtonClicked;
355+
if (m_PlayStopButton != null)
356+
m_PlayStopButton.clicked -= OnPlayStopButtonClicked;
355357

356-
if (m_PlayButton != null)
357-
m_PlayButton.clicked -= OnSkipButtonClicked;
358+
if (m_SkipButton != null)
359+
m_SkipButton.clicked -= OnSkipButtonClicked;
358360
}
359361

360362
void BindAndTrackPreviewProperties()
@@ -386,15 +388,15 @@ void UpdateTransportButtonStates()
386388
{
387389
var editorIsPaused = EditorApplication.isPaused;
388390

389-
m_PlayButton?.SetEnabled(State.IsReadyToPlay() && !editorIsPaused);
391+
m_PlayStopButton?.SetEnabled(State.IsReadyToPlay() && !editorIsPaused);
390392
m_SkipButton?.SetEnabled(State.IsPlayingOrPaused() && State.AudioContainer.triggerMode == AudioRandomContainerTriggerMode.Automatic && !editorIsPaused);
391393

392394
var image =
393395
State.IsPlayingOrPaused()
394396
? UIToolkitUtilities.LoadIcon("Stop")
395397
: UIToolkitUtilities.LoadIcon("Play");
396398

397-
m_PlayButtonImage.style.backgroundImage = new StyleBackground(image);
399+
m_PlayStopButtonImage.style.backgroundImage = new StyleBackground(image);
398400
}
399401

400402
void OnTransportStateChanged(object sender, EventArgs e)
@@ -435,7 +437,6 @@ void InitializeVolumeElements()
435437
volumeRandomizationMaxField.label = "";
436438
volumeRandomizationMaxField.formatString = "0.#";
437439
InsertUnitFieldForFloatField(volumeRandomizationMaxField, "dB");
438-
439440
}
440441

441442
void SubscribeToVolumeCallbacksAndEvents()
@@ -794,18 +795,16 @@ void OnListItemsAdded(IEnumerable<int> indices)
794795

795796
m_AddedElements.Clear();
796797

797-
var undoName = "Add AudioContainerElement";
798+
var undoName = $"Add {nameof(AudioRandomContainer)} element";
798799

799800
if (indicesArray.Length > 1)
800801
{
801802
undoName = $"{undoName}s";
802803
}
803804

804805
Undo.SetCurrentGroupName(undoName);
805-
SetTitle();
806+
806807
m_AddedElements.Clear();
807-
// Force a list rebuild when the list size has changed or it will not render correctly
808-
EditorApplication.update += DoDelayedListRebuild;
809808
}
810809

811810
void OnListItemsRemoved(IEnumerable<int> indices)
@@ -826,27 +825,25 @@ void OnListItemsRemoved(IEnumerable<int> indices)
826825

827826
State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);
828827

829-
var undoName = "Remove AudioContainerElement";
828+
var undoName = $"Remove {nameof(AudioRandomContainer)} element";
830829

831830
if (indicesArray.Length > 1)
832831
{
833832
undoName = $"{undoName}s";
834833
}
835834

836835
Undo.SetCurrentGroupName(undoName);
837-
SetTitle();
838-
// Force a list rebuild when the list size has changed or it will not render correctly
839-
EditorApplication.update += DoDelayedListRebuild;
840836
}
841837

842838
void OnItemListIndexChanged(int oldIndex, int newIndex)
843839
{
840+
Undo.SetCurrentGroupName($"Reorder {nameof(AudioRandomContainer)} list");
844841
State.AudioContainer.NotifyObservers(AudioRandomContainer.ChangeEventType.List);
845842
}
846843

847844
void OnAudioClipDrag(List<AudioClip> audioClips)
848845
{
849-
var undoName = "Add AudioContainerElement";
846+
var undoName = $"Add {nameof(AudioRandomContainer)} element";
850847

851848
if (audioClips.Count > 1)
852849
undoName = $"{undoName}s";
@@ -875,17 +872,36 @@ void OnAudioClipDrag(List<AudioClip> audioClips)
875872
Undo.RegisterCreatedObjectUndo(element, "Create AudioContainerElement");
876873

877874
m_AddedElements.Clear();
878-
879-
SetTitle();
880875
Undo.SetCurrentGroupName(undoName);
881-
// Force a list rebuild when the list size has changed or it will not render correctly
882-
EditorApplication.update += DoDelayedListRebuild;
883876
}
884877

885878
void OnAudioClipListChanged(SerializedProperty property)
886879
{
887-
UpdateTransportButtonStates();
880+
// Do manual fixup of orphaned subassets after a possible undo of item removal
881+
// because the undo system does not play nice with RegisterCreatedObjectUndo.
882+
if (m_CachedElements.Count < State.AudioContainer.elements.Length)
883+
{
884+
var elements = State.AudioContainer.elements;
885+
886+
foreach (var elm in elements)
887+
{
888+
AssetDatabase.TryGetGUIDAndLocalFileIdentifier(elm, out var guid, out var localId);
889+
890+
// An empty asset GUID means the subasset has lost the reference
891+
// to the main asset after an undo of item removal, so re-add it manually.
892+
if (guid.Equals(k_EmptyGuidString))
893+
AssetDatabase.AddObjectToAsset(elm, State.AudioContainer);
894+
}
895+
}
896+
897+
// Update the cached list of elements
888898
m_CachedElements = State.AudioContainer.elements.ToList();
899+
900+
// Force a list rebuild when the list has changed or it will not always render correctly
901+
m_ClipsListView.Rebuild();
902+
903+
UpdateTransportButtonStates();
904+
SetTitle();
889905
}
890906

891907
void UpdateClipFieldProgressBars()
@@ -939,12 +955,6 @@ void ClearClipFieldProgressBars()
939955
m_ClipFieldProgressBarsAreCleared = true;
940956
}
941957

942-
void DoDelayedListRebuild()
943-
{
944-
m_ClipsListView.Rebuild();
945-
EditorApplication.update -= DoDelayedListRebuild;
946-
}
947-
948958
#endregion
949959

950960
#region TriggerAndPlaybackMode
@@ -1185,24 +1195,6 @@ void OnCountRandomizationButtonClicked()
11851195

11861196
#region GlobalEditorCallbackHandlers
11871197

1188-
void OnUndoRedoPerformed()
1189-
{
1190-
if (m_ContainerRootVisualElement == null
1191-
|| m_ContainerRootVisualElement.style.display == DisplayStyle.None
1192-
|| State.AudioContainer == null)
1193-
return;
1194-
1195-
if (m_CachedElements.Count != State.AudioContainer.elements.Length)
1196-
{
1197-
// Force a list rebuild when the list size has increased or it will not render correctly
1198-
// if (m_CachedElements.Count < State.AudioContainer.elements.Length)
1199-
m_ClipsListView.Rebuild();
1200-
1201-
SetTitle();
1202-
m_CachedElements = State.AudioContainer.elements.ToList();
1203-
}
1204-
}
1205-
12061198
void OnWillSaveAssets(IEnumerable<string> paths)
12071199
{
12081200
if (State.AudioContainer == null)

Editor/Mono/Audio/AudioContainerWindowState.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,41 @@ internal void UpdateTarget()
132132
}
133133

134134
if (m_TrackedSource == audioSource && m_AudioContainer == newTarget)
135+
{
135136
return;
137+
}
138+
139+
var targetChanged = newTarget != m_AudioContainer;
140+
var trackedSourceChanged = audioSource != m_TrackedSource;
136141

137142
Reset();
138143

139144
m_TrackedSource = audioSource;
140145
m_AudioContainer = newTarget;
141146

142147
if (m_AudioContainer != null)
148+
{
143149
TargetPath = AssetDatabase.GetAssetPath(m_AudioContainer);
150+
}
144151

145-
TargetChanged?.Invoke(this, EventArgs.Empty);
152+
if (targetChanged)
153+
{
154+
TargetChanged?.Invoke(this, EventArgs.Empty);
155+
}
146156

147-
if (m_TrackedSource == null)
148-
return;
157+
if (trackedSourceChanged)
158+
{
159+
m_ResourceTrackerElement.Unbind();
149160

150-
var trackedSourceSO = new SerializedObject(m_TrackedSource);
151-
var trackedSourceResourceProperty = trackedSourceSO.FindProperty("m_Resource");
152-
m_ResourceTrackerElement.TrackPropertyValue(trackedSourceResourceProperty, OnResourceChanged);
161+
if (m_TrackedSource != null)
162+
{
163+
var trackedSourceSO = new SerializedObject(m_TrackedSource);
164+
var trackedSourceResourceProperty = trackedSourceSO.FindProperty("m_Resource");
165+
m_ResourceTrackerElement.TrackPropertyValue(trackedSourceResourceProperty, OnResourceChanged);
166+
}
167+
}
153168
}
169+
154170
void OnResourceChanged(SerializedProperty property)
155171
{
156172
var container = property.objectReferenceValue as AudioRandomContainer;

Editor/Mono/BuildProfile/BuildProfile.cs

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

5-
using System;
65
using System.Runtime.InteropServices;
76
using UnityEngine;
87
using UnityEngine.Bindings;
@@ -21,7 +20,7 @@ internal sealed partial class BuildProfile : ScriptableObject
2120
/// <summary>
2221
/// Build Target used to fetch module and build profile extension.
2322
/// </summary>
24-
[SerializeField] BuildTarget m_BuildTarget;
23+
[SerializeField] BuildTarget m_BuildTarget = BuildTarget.NoTarget;
2524
public BuildTarget buildTarget
2625
{
2726
get => m_BuildTarget;
@@ -57,5 +56,15 @@ public BuildProfilePlatformSettingsBase platformBuildProfile
5756
get => m_PlatformBuildProfile;
5857
internal set => m_PlatformBuildProfile = value;
5958
}
59+
60+
void OnEnable()
61+
{
62+
// Check if the platform support module has been installed,
63+
// and try to set an uninitialized platform settings.
64+
if (platformBuildProfile == null)
65+
TryCreatePlatformSettings();
66+
67+
onBuildProfileEnable?.Invoke(this);
68+
}
6069
}
6170
}

0 commit comments

Comments
 (0)