Skip to content

Commit 5cdad00

Browse files
author
Unity Technologies
committed
Unity 2023.2.0a16 C# reference source code
1 parent da51b77 commit 5cdad00

File tree

150 files changed

+4421
-2629
lines changed

Some content is hidden

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

150 files changed

+4421
-2629
lines changed

Editor/Mono/AssetPipeline/TextureImporterEnums.cs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,28 @@ public enum TextureImporterFormat
3737
{
3838
Automatic = -1,
3939
// Choose a compressed format automatically.
40-
[System.Obsolete("Use textureCompression property instead")]
40+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
41+
[System.Obsolete("Enum member TextureImporterFormat.AutomaticCompressed is obsolete. Use the TextureImporter.textureCompression property instead.", true)]
4142
AutomaticCompressed = -1,
4243
// Choose a 16 bit format automatically.
43-
[System.Obsolete("Use textureCompression property instead")]
44+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
45+
[System.Obsolete("Enum member TextureImporterFormat.Automatic16bit is obsolete. Use TextureImporter.textureCompression property instead.", true)]
4446
Automatic16bit = -2,
4547
// Choose a Truecolor format automatically.
46-
[System.Obsolete("Use textureCompression property instead")]
48+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
49+
[System.Obsolete("Enum member TextureImporterFormat.AutomaticTruecolor is obsolete. Use the TextureImporter.textureCompression property instead.", true)]
4750
AutomaticTruecolor = -3,
4851
// Choose a Crunched format automatically.
49-
[System.Obsolete("Use crunchedCompression property instead")]
52+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
53+
[System.Obsolete("Enum member TextureImporterFormat.AutomaticCrunched is obsolete. Use the TextureImporter.crunchedCompression property instead.", true)]
5054
AutomaticCrunched = -5,
5155
// Choose an HDR format automatically.
52-
[System.Obsolete("HDR is handled automatically now")]
56+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
57+
[System.Obsolete("Enum member TextureImporterFormat.AutomaticHDR is obsolete. HDR is handled automatically now.", true)]
5358
AutomaticHDR = -6,
5459
// Choose a compresssed HDR format automatically.
55-
[System.Obsolete("HDR is handled automatically now")]
60+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
61+
[System.Obsolete("Enum member TextureImporterFormat.AutomaticCompressedHDR is obsolete. HDR is handled automatically now.", true)]
5662
AutomaticCompressedHDR = -7,
5763

5864
// DXT1 compressed texture format.
@@ -124,9 +130,11 @@ public enum TextureImporterFormat
124130
ETC_RGB4 = 34,
125131

126132
// ATC (Android) 4 bits/pixel compressed RGB texture format.
127-
[System.Obsolete("Use ETC_RGB4 (UnityUpgradable) -> ETC_RGB4")]
133+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
134+
[System.Obsolete("Enum member ATC_RGB4 is obsolete. Use ETC_RGB4 (UnityUpgradable) -> ETC_RGB4", true)]
128135
ATC_RGB4 = 35,
129-
[System.Obsolete("Use ETC2_RGBA8 (UnityUpgradable) -> ETC2_RGBA8")]
136+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
137+
[System.Obsolete("Enum member ATC_RGBA8 is obsolete. Use ETC2_RGBA8 (UnityUpgradable) -> ETC2_RGBA8", true)]
130138
ATC_RGBA8 = 36,
131139

132140
// EAC 4 bits/pixel compressed 16-bit R texture format
@@ -154,47 +162,49 @@ public enum TextureImporterFormat
154162
ASTC_12x12 = 53,
155163

156164
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
157-
[System.Obsolete("Use ASTC_4x4 (UnityUpgradable) -> ASTC_4x4")]
158-
ASTC_RGB_4x4 = 48,
165+
[System.Obsolete("Enum member ASTC_RGB_4x4 is obsolete. Use ASTC_4x4 (UnityUpgradable) -> ASTC_4x4", true)]
166+
ASTC_RGB_4x4 = -48,
159167
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
160-
[System.Obsolete("Use ASTC_5x5 (UnityUpgradable) -> ASTC_5x5")]
161-
ASTC_RGB_5x5 = 49,
168+
[System.Obsolete("Enum member ASTC_RGB_5x5 is obsolete. Use ASTC_5x5 (UnityUpgradable) -> ASTC_5x5", true)]
169+
ASTC_RGB_5x5 = -49,
162170
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
163-
[System.Obsolete("Use ASTC_6x6 (UnityUpgradable) -> ASTC_6x6")]
164-
ASTC_RGB_6x6 = 50,
171+
[System.Obsolete("Enum member ASTC_RGB_6x6 is obsolete. Use ASTC_6x6 (UnityUpgradable) -> ASTC_6x6", true)]
172+
ASTC_RGB_6x6 = -50,
165173
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
166-
[System.Obsolete("Use ASTC_8x8 (UnityUpgradable) -> ASTC_8x8")]
167-
ASTC_RGB_8x8 = 51,
174+
[System.Obsolete("Enum member ASTC_RGB_8x8 is obsolete. Use ASTC_8x8 (UnityUpgradable) -> ASTC_8x8", true)]
175+
ASTC_RGB_8x8 = -51,
168176
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
169-
[System.Obsolete("Use ASTC_10x10 (UnityUpgradable) -> ASTC_10x10")]
170-
ASTC_RGB_10x10 = 52,
177+
[System.Obsolete("Enum member ASTC_RGB_10x10 is obsolete. Use ASTC_10x10 (UnityUpgradable) -> ASTC_10x10", true)]
178+
ASTC_RGB_10x10 = -52,
171179
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
172-
[System.Obsolete("Use ASTC_12x12 (UnityUpgradable) -> ASTC_12x12")]
173-
ASTC_RGB_12x12 = 53,
180+
[System.Obsolete("Enum member ASTC_RGB_12x12 is obsolete. Use ASTC_12x12 (UnityUpgradable) -> ASTC_12x12", true)]
181+
ASTC_RGB_12x12 = -53,
174182
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
175-
[System.Obsolete("Use ASTC_4x4 (UnityUpgradable) -> ASTC_4x4")]
176-
ASTC_RGBA_4x4 = 54,
183+
[System.Obsolete("Enum member ASTC_RGBA_4x4 is obsolete. Use ASTC_4x4 (UnityUpgradable) -> ASTC_4x4", true)]
184+
ASTC_RGBA_4x4 = -54,
177185
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
178-
[System.Obsolete("Use ASTC_5x5 (UnityUpgradable) -> ASTC_5x5")]
179-
ASTC_RGBA_5x5 = 55,
186+
[System.Obsolete("Enum member ASTC_RGBA_5x5 is obsolete. Use ASTC_5x5 (UnityUpgradable) -> ASTC_5x5", true)]
187+
ASTC_RGBA_5x5 = -55,
180188
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
181-
[System.Obsolete("Use ASTC_6x6 (UnityUpgradable) -> ASTC_6x6")]
182-
ASTC_RGBA_6x6 = 56,
189+
[System.Obsolete("Enum member ASTC_RGBA_6x6 is obsolete. Use ASTC_6x6 (UnityUpgradable) -> ASTC_6x6", true)]
190+
ASTC_RGBA_6x6 = -56,
183191
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
184-
[System.Obsolete("Use ASTC_8x8 (UnityUpgradable) -> ASTC_8x8")]
185-
ASTC_RGBA_8x8 = 57,
192+
[System.Obsolete("Enum member ASTC_RGBA_8x8 is obsolete. Use ASTC_8x8 (UnityUpgradable) -> ASTC_8x8", true)]
193+
ASTC_RGBA_8x8 = -57,
186194
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
187-
[System.Obsolete("Use ASTC_10x10 (UnityUpgradable) -> ASTC_10x10")]
188-
ASTC_RGBA_10x10 = 58,
195+
[System.Obsolete("Enum member ASTC_RGBA_10x10 is obsolete. Use ASTC_10x10 (UnityUpgradable) -> ASTC_10x10", true)]
196+
ASTC_RGBA_10x10 = -58,
189197
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
190-
[System.Obsolete("Use ASTC_12x12 (UnityUpgradable) -> ASTC_12x12")]
191-
ASTC_RGBA_12x12 = 59,
198+
[System.Obsolete("Enum member ASTC_RGBA_12x12 is obsolete. Use ASTC_12x12 (UnityUpgradable) -> ASTC_12x12", true)]
199+
ASTC_RGBA_12x12 = -59,
192200

193201
// Nintendo 3DS-flavoured ETC
194-
[System.Obsolete("Nintendo 3DS is no longer supported.")]
195-
ETC_RGB4_3DS = 60,
196-
[System.Obsolete("Nintendo 3DS is no longer supported.")]
197-
ETC_RGBA8_3DS = 61,
202+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
203+
[System.Obsolete("Enum member ETC_RGB4_3DS is obsolete. Nintendo 3DS is no longer supported.", true)]
204+
ETC_RGB4_3DS = -60,
205+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
206+
[System.Obsolete("Enum member ETC_RGBA8_3DS is obsolete. Nintendo 3DS is no longer supported.", true)]
207+
ETC_RGBA8_3DS = -61,
198208

199209
// ETC1 crunched texture format.
200210
ETC_RGB4Crunched = 64,

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using UnityEditor.UIElements;
1111
using UnityEngine;
1212
using UnityEngine.Audio;
13+
using UnityEngine.Playables;
1314
using UnityEngine.Scripting;
1415
using UnityEngine.UIElements;
1516

@@ -155,17 +156,25 @@ void CreateGUI()
155156
rootVisualElement.Unbind();
156157
rootVisualElement.Clear();
157158

158-
if (m_State.AudioContainer == null)
159-
{
160-
return;
161-
}
162-
163159
var rootAsset = UIToolkitUtilities.LoadUxml("UXML/Audio/AudioRandomContainer.uxml");
164160
rootAsset.CloneTree(rootVisualElement);
165161

166162
var styleSheet = UIToolkitUtilities.LoadStyleSheet("StyleSheets/Audio/AudioRandomContainer.uss");
167163
rootVisualElement.styleSheets.Add(styleSheet);
168164

165+
var ARCelement = UIToolkitUtilities.GetChildByName<ScrollView>(rootVisualElement, "ARC_ScrollView");
166+
var day0Element = UIToolkitUtilities.GetChildByName<VisualElement>(rootVisualElement, "Day0");
167+
168+
169+
if (m_State.AudioContainer == null)
170+
{
171+
ARCelement.style.display = DisplayStyle.None;
172+
CreateDay0Bindings();
173+
return;
174+
}
175+
176+
day0Element.style.display = DisplayStyle.None;
177+
169178
CreateBindings();
170179
UpdateTransportButtonStates();
171180
}
@@ -175,6 +184,20 @@ void CreateGUI()
175184
}
176185
}
177186

187+
void CreateDay0Bindings()
188+
{
189+
var day0Element = UIToolkitUtilities.GetChildByName<VisualElement>(rootVisualElement, "Day0");
190+
var createButtonLabel = UIToolkitUtilities.GetChildByName<Label>(day0Element, "CreateButtonLabel");
191+
var createButton = UIToolkitUtilities.GetChildByName<Button>(day0Element, "CreateButton");
192+
createButton.clicked += OnCreateButtonClicked;
193+
createButtonLabel.text = "Select an existing Audio Random Container asset in the project browser or create a new one using the button below.";
194+
}
195+
196+
static void OnCreateButtonClicked()
197+
{
198+
ProjectWindowUtil.CreateAudioRandomContainer();
199+
}
200+
178201
void OnPauseStateChanged(object sender, EventArgs e)
179202
{
180203
UpdateTransportButtonStates();
@@ -376,13 +399,59 @@ void CreateBindings()
376399
m_TimeRandomRangeTracker = AudioRandomRangeSliderTracker.Create(m_TimeSlider, m_State.AudioContainer.automaticTriggerTimeRandomizationRange);
377400

378401
EditorApplication.update += OnEditorApplicationUpdate;
402+
EditorApplication.update += OneTimeEditorApplicationUpdate;
379403
}
380404

381-
void OnEditorApplicationUpdate()
382-
{
405+
void OneTimeEditorApplicationUpdate()
406+
{
407+
// Setting this is a temp workaround for a UIToolKit bug
408+
// https://unity.slack.com/archives/C3414V4UV/p1681828689005249?thread_ts=1676901177.340799&cid=C3414V4UV
383409
m_ClipsListView.reorderable = true;
384410
m_ClipsListView.reorderMode = ListViewReorderMode.Animated;
385-
EditorApplication.update -= OnEditorApplicationUpdate;
411+
EditorApplication.update -= OneTimeEditorApplicationUpdate;
412+
}
413+
414+
void OnEditorApplicationUpdate()
415+
{
416+
UpdateClipFieldProgressBars();
417+
}
418+
419+
void UpdateClipFieldProgressBars()
420+
{
421+
var playables = m_State.GetActivePlayables();
422+
if (playables == null)
423+
{
424+
return;
425+
}
426+
427+
// Iterate over the ActivePlayables from the runtime and try and match them to the instance ID on the clip field.
428+
// if its a match, set the progress and remove the clip field to avoid overwriting the progress.
429+
var clipFields = m_ClipsListView.Query<AudioContainerElementClipField>().ToList();
430+
// We need to sort the active playables as the runtime does not guarantee order
431+
Array.Sort(playables, (x, y) => x.settings.scheduledTime.CompareTo(y.settings.scheduledTime));
432+
for (var i = playables.Length - 1; i >= 0; i--)
433+
{
434+
var playable = new AudioClipPlayable(playables[i].clipPlayableHandle);
435+
for (var j = clipFields.Count - 1; j >= 0; j--)
436+
{
437+
var field = clipFields[j];
438+
if (field.AssetElementInstanceID == playables[i].settings.element.GetInstanceID())
439+
{
440+
field.Progress = playable.GetClipPositionSec() / playable.GetClip().length;
441+
clipFields.RemoveAt(j);
442+
}
443+
}
444+
}
445+
446+
// Any clip fields that did not have a match with active playables should have their progress set to 0.
447+
foreach (var field in clipFields)
448+
{
449+
var clipField = field;
450+
if (clipField.Progress != 0.0f)
451+
{
452+
clipField.Progress = 0.0f;
453+
}
454+
}
386455
}
387456

388457
private void Update()
@@ -682,14 +751,16 @@ void OnBindListItem(VisualElement element, int index)
682751
var audioClipProperty = serializedObject.FindProperty("m_AudioClip");
683752
var volumeProperty = serializedObject.FindProperty("m_Volume");
684753

685-
var enabledToggle = (Toggle)element.Query<Toggle>("enabled-toggle");
686-
var audioClipField = (ObjectField)element.Query<ObjectField>("audio-clip-field");
687-
var volumeField = (FloatField)element.Query<FloatField>("volume-field");
754+
var enabledToggle = UIToolkitUtilities.GetChildByName<Toggle>(element, "enabled-toggle");
755+
var audioClipField = UIToolkitUtilities.GetChildByName<AudioContainerElementClipField>(element, "audio-clip-field");
756+
var volumeField = UIToolkitUtilities.GetChildByName<FloatField>(element, "volume-field");
688757
volumeField.formatString = "0.# dB";
689758

690759
audioClipField.objectType = typeof(AudioClip);
691760
audioClipField.RegisterCallback<DragPerformEvent>(evt => { evt.StopPropagation(); });
692761

762+
audioClipField.AssetElementInstanceID = listElement.GetInstanceID();
763+
693764
enabledToggle.BindProperty(enabledProperty);
694765
audioClipField.BindProperty(audioClipProperty);
695766
volumeField.BindProperty(volumeProperty);

Editor/Mono/Audio/AudioContainerWindowState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ internal bool IsReadyToPlay()
143143
return false;
144144
}
145145

146+
internal ActivePlayable[] GetActivePlayables()
147+
{
148+
return m_PreviewAudioSource == null ? null : m_PreviewAudioSource.containerActivePlayables;
149+
}
150+
146151
internal void UpdateTarget()
147152
{
148153
AudioRandomContainer newTarget = null;
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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 UnityEditor.UIElements;
7+
using UnityEngine;
8+
using UnityEngine.Scripting;
9+
using UnityEngine.UIElements;
10+
11+
namespace UnityEditor.Audio.UIElements;
12+
13+
class AudioContainerElementClipField : ObjectField
14+
{
15+
[Preserve]
16+
public new class UxmlFactory : UxmlFactory<AudioContainerElementClipField, UxmlTraits> { }
17+
18+
[Preserve]
19+
public new class UxmlTraits : ObjectField.UxmlTraits { }
20+
public int AssetElementInstanceID { get; set; }
21+
public double Progress
22+
{
23+
get => m_Progress;
24+
25+
set
26+
{
27+
m_Progress = value;
28+
MarkDirtyRepaint();
29+
}
30+
}
31+
32+
float m_ObjectFieldBorderWidth;
33+
float m_ObjectSelectorWidth;
34+
Color m_ProgressBarColor;
35+
Color m_ProgressBarBackgroundColor;
36+
double m_Progress;
37+
38+
static readonly CustomStyleProperty<Color> s_ProgressBarColorProperty = new("--progress-bar-color");
39+
static readonly CustomStyleProperty<Color> s_ProgressBarBackgroundColorProperty = new("--progress-bar-background");
40+
41+
public AudioContainerElementClipField()
42+
{
43+
generateVisualContent += GenerateVisualContent;
44+
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
45+
RegisterCallback<CustomStyleResolvedEvent>(CustomStylesResolved);
46+
}
47+
48+
static void CustomStylesResolved(CustomStyleResolvedEvent evt)
49+
{
50+
AudioContainerElementClipField element = (AudioContainerElementClipField)evt.currentTarget;
51+
element.UpdateCustomStyles();
52+
}
53+
54+
void UpdateCustomStyles()
55+
{
56+
if (customStyle.TryGetValue(s_ProgressBarColorProperty, out var progressColor))
57+
{
58+
m_ProgressBarColor = progressColor;
59+
}
60+
61+
if (customStyle.TryGetValue(s_ProgressBarBackgroundColorProperty, out var progressBackgroundColor))
62+
{
63+
m_ProgressBarBackgroundColor = progressBackgroundColor;
64+
}
65+
}
66+
67+
void OnGeometryChanged(GeometryChangedEvent evt)
68+
{
69+
CacheChildSettings();
70+
MarkDirtyRepaint();
71+
}
72+
73+
void CacheChildSettings()
74+
{
75+
var objField = UIToolkitUtilities.GetChildByClassName<VisualElement>(this, "unity-object-field__input");
76+
var col = objField.resolvedStyle.backgroundColor;
77+
col.a = 0;
78+
objField.style.backgroundColor = col;
79+
m_ObjectFieldBorderWidth = objField.resolvedStyle.borderBottomWidth;
80+
81+
var selector = UIToolkitUtilities.GetChildByClassName<VisualElement>(this, "unity-object-field__selector");
82+
m_ObjectSelectorWidth = selector.boundingBox.width;
83+
}
84+
85+
static void GenerateVisualContent(MeshGenerationContext context)
86+
{
87+
var element = context.visualElement as AudioContainerElementClipField;
88+
var painter2D = context.painter2D;
89+
var rect = context.visualElement.contentRect;
90+
rect.yMax -= element.m_ObjectFieldBorderWidth;
91+
rect.yMin += element.m_ObjectFieldBorderWidth;
92+
rect.xMin += element.m_ObjectFieldBorderWidth;
93+
94+
var progress = element.m_Progress;
95+
var progressMaxX = (float)(((rect.xMax - element.m_ObjectSelectorWidth) - rect.xMin) * progress);
96+
painter2D.fillColor = element.m_ProgressBarColor;
97+
painter2D.BeginPath();
98+
painter2D.MoveTo(new Vector2(rect.xMin, rect.yMin));
99+
painter2D.LineTo(new Vector2(progressMaxX, rect.yMin));
100+
painter2D.LineTo(new Vector2(progressMaxX, rect.yMax));
101+
painter2D.LineTo(new Vector2(rect.xMin, rect.yMax));
102+
painter2D.ClosePath();
103+
painter2D.Fill();
104+
105+
// redraw background
106+
painter2D.fillColor = element.m_ProgressBarBackgroundColor;
107+
painter2D.BeginPath();
108+
painter2D.MoveTo(new Vector2(progressMaxX, rect.yMin));
109+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMin));
110+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMax));
111+
painter2D.LineTo(new Vector2(progressMaxX, rect.yMax));
112+
painter2D.ClosePath();
113+
painter2D.Fill();
114+
115+
}
116+
}

0 commit comments

Comments
 (0)