Skip to content

Commit c005868

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a11 C# reference source code
1 parent 258abdf commit c005868

File tree

215 files changed

+4690
-2987
lines changed

Some content is hidden

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

215 files changed

+4690
-2987
lines changed

Editor/Mono/Animation/AnimationUtility.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ internal static void SetEditorCurveNoSync(AnimationClip clip, EditorCurveBinding
270270
[NativeThrows]
271271
extern private static void Internal_SetEditorCurve([NotNull] AnimationClip clip, EditorCurveBinding binding, AnimationCurve curve, bool syncEditorCurves);
272272

273+
extern internal static bool IsDiscreteIntBinding(EditorCurveBinding binding);
274+
273275
extern internal static void SyncEditorCurves([NotNull] AnimationClip clip);
274276

275277
private static void Internal_InvokeOnCurveWasModified(AnimationClip clip, EditorCurveBinding binding, CurveModifiedType type)

Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyGUI.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
342342

343343
if (curve.valueType == typeof(bool))
344344
{
345-
value = GUI.Toggle(valueFieldRect, m_HierarchyItemValueControlIDs[row], (float)value != 0, GUIContent.none, EditorStyles.toggle) ? 1f : 0f;
345+
value = GUI.Toggle(valueFieldRect, m_HierarchyItemValueControlIDs[row], Convert.ToSingle(value) != 0f, GUIContent.none, EditorStyles.toggle) ? 1f : 0f;
346346
}
347347
else
348348
{
@@ -365,7 +365,7 @@ private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
365365
valueFieldRect,
366366
valueFieldDragRect,
367367
id,
368-
(int)value,
368+
Convert.ToInt32(value),
369369
EditorGUI.kIntFieldFormatString,
370370
m_AnimationSelectionTextField,
371371
true,
@@ -382,7 +382,7 @@ private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
382382
valueFieldRect,
383383
valueFieldDragRect,
384384
id,
385-
(float)value,
385+
Convert.ToSingle(value),
386386
"g5",
387387
m_AnimationSelectionTextField,
388388
true);
@@ -392,7 +392,8 @@ private void DoValueField(Rect rect, AnimationWindowHierarchyNode node, int row)
392392
Event.current.Use();
393393
}
394394

395-
if (float.IsInfinity((float)value) || float.IsNaN((float)value))
395+
var floatValue = Convert.ToSingle(value);
396+
if (float.IsInfinity(floatValue) || float.IsNaN(floatValue))
396397
value = 0f;
397398
}
398399
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowKeyframe.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ public Keyframe ToKeyframe()
167167
// case 1395978
168168
// Negative int values converted to float create NaN values. Limiting discrete int values to only positive values
169169
// until we rewrite the animation backend with dedicated int curves.
170-
floatValue = UnityEngine.Animations.DiscreteEvaluationAttributeUtilities.ConvertDiscreteIntToFloat(Math.Max((int)value, 0));
170+
floatValue = UnityEngine.Animations.DiscreteEvaluationAttributeUtilities.ConvertDiscreteIntToFloat(Math.Max(Convert.ToInt32(value), 0));
171171
}
172172
else
173173
{
174-
floatValue = (float)value;
174+
floatValue = Convert.ToSingle(value);
175175
}
176176

177177
var keyframe = new Keyframe(time, floatValue, inTangent, outTangent);

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static AnimationWindowKeyframe AddKeyframeToCurve(AnimationWindowCurve cu
280280
}
281281
else if (type == typeof(bool) || type == typeof(float) || type == typeof(int))
282282
{
283-
Keyframe tempKey = new Keyframe(time.time, (float)value);
283+
Keyframe tempKey = new Keyframe(time.time, Convert.ToSingle(value));
284284
if (type == typeof(bool))
285285
{
286286
AnimationUtility.SetKeyLeftTangentMode(ref tempKey, TangentMode.Constant);

Editor/Mono/Animation/EditorCurveBinding.bindings.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using UnityEngine.Playables;
99
using UnityEngine.Scripting.APIUpdating;
1010
using UnityEngine.Internal;
11+
using UnityEngine;
1112

1213
namespace UnityEditor
1314
{
@@ -128,6 +129,16 @@ static public EditorCurveBinding DiscreteCurve(string inPath, System.Type inType
128129
binding.m_isSerializeReferenceCurve = 0;
129130
binding.m_isUnknownCurve = 0;
130131

132+
if (!AnimationUtility.IsDiscreteIntBinding(binding))
133+
{
134+
Debug.LogWarning(
135+
$"Property [" + inPropertyName + "] is not a supported discrete curve binding. " +
136+
"Discrete curves only support [" + typeof(Enum) + "] and [" + typeof(int) + " with the `DiscreteEvaluation` attribute].");
137+
138+
binding.m_isDiscreteCurve = 0;
139+
binding.m_isUnknownCurve = 1;
140+
}
141+
131142
return binding;
132143
}
133144

Editor/Mono/AssetPipeline/TextureImporter.bindings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace UnityEditor
2121
public sealed partial class TextureImporter : AssetImporter
2222
{
2323
[FreeFunction]
24-
private static extern string GetFixedPlatformName(string platform);
24+
internal static extern string GetFixedPlatformName(string platform);
2525

2626
[Obsolete("textureFormat is no longer accessible at the TextureImporter level. For old 'simple' formats use the textureCompression property for the equivalent automatic choice (Uncompressed for TrueColor, Compressed and HQCommpressed for 16 bits). For platform specific formats use the [[PlatformTextureSettings]] API. Using this setter will setup various parameters to match the new automatic system as well as possible. Getter will return the last value set.")]
2727
public extern TextureImporterFormat textureFormat
@@ -103,7 +103,7 @@ public bool GetPlatformTextureSettings(string platform, out int maxTextureSize,
103103
// public API will always return a valid TextureImporterPlatformSettings, creating it based on the default one if it did not exist.
104104
public TextureImporterPlatformSettings GetPlatformTextureSettings(string platform)
105105
{
106-
// make sure we are converting the settings to use the proper BuildTargetGroupName to get them (the way it works on other importers)
106+
// make sure we are converting the settings to use the proper BuildTarget name to get them (the way it works on other importers)
107107
platform = GetFixedPlatformName(platform);
108108

109109
TextureImporterPlatformSettings dest = GetPlatformTextureSetting_Internal(platform);

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ sealed class AudioContainerWindow : EditorWindow
9494
bool m_IsInitializing;
9595
bool m_Day0ElementsInitialized;
9696
bool m_ContainerElementsInitialized;
97+
private bool m_ClipFieldProgressBarsAreCleared = true;
9798

9899
/// <summary>
99100
/// Holds the previous state of the list elements for undo/delete housekeeping
@@ -155,15 +156,21 @@ void OnDisable()
155156

156157
void Update()
157158
{
158-
UpdateClipFieldProgressBars();
159+
if (State.IsPlayingOrPaused()) { UpdateClipFieldProgressBars(); }
160+
else if (!m_ClipFieldProgressBarsAreCleared) { ClearClipFieldProgressBars(); }
159161

160-
if (m_Meter == null)
161-
return;
162-
163-
if (State != null)
164-
m_Meter.Value = State.GetMeterValue();
165-
else
166-
m_Meter.Value = -80.0f;
162+
if (m_Meter != null)
163+
{
164+
if (State.IsPlayingOrPaused())
165+
{
166+
if (State != null) { m_Meter.Value = State.GetMeterValue(); }
167+
else { m_Meter.Value = -80.0f; }
168+
}
169+
else
170+
{
171+
if (m_Meter.Value != -80.0f) { m_Meter.Value = -80.0f; }
172+
}
173+
}
167174
}
168175

169176
void OnBecameInvisible()
@@ -331,7 +338,7 @@ void InitializePreviewElements()
331338
m_SkipButton = UIToolkitUtilities.GetChildByName<Button>(m_ContainerRootVisualElement, "skip-button");
332339
m_SkipButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(m_ContainerRootVisualElement, "skip-button-image");
333340

334-
var skipIcon = UIToolkitUtilities.LoadIcon("icon_next");
341+
var skipIcon = UIToolkitUtilities.LoadIcon("Skip");
335342
m_SkipButtonImage.style.backgroundImage = new StyleBackground(skipIcon);
336343
}
337344

@@ -384,8 +391,8 @@ void UpdateTransportButtonStates()
384391

385392
var image =
386393
State.IsPlayingOrPaused()
387-
? UIToolkitUtilities.LoadIcon("icon_stop")
388-
: UIToolkitUtilities.LoadIcon("icon_play");
394+
? UIToolkitUtilities.LoadIcon("Stop")
395+
: UIToolkitUtilities.LoadIcon("Play");
389396

390397
m_PlayButtonImage.style.backgroundImage = new StyleBackground(image);
391398
}
@@ -915,6 +922,8 @@ void UpdateClipFieldProgressBars()
915922
foreach (var field in clipFields)
916923
if (field.Progress != 0.0f)
917924
field.Progress = 0.0f;
925+
926+
m_ClipFieldProgressBarsAreCleared = false;
918927
}
919928

920929
void ClearClipFieldProgressBars()
@@ -926,6 +935,8 @@ void ClearClipFieldProgressBars()
926935

927936
foreach (var field in clipFields)
928937
field.Progress = 0.0f;
938+
939+
m_ClipFieldProgressBarsAreCleared = true;
929940
}
930941

931942
void DoDelayedListRebuild()

Editor/Mono/Audio/AudioContainerWindowState.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ internal void UpdateTarget()
131131
newTarget = m_AudioContainer;
132132
}
133133

134-
if (m_TrackedSource == audioSource && m_AudioContainer == newTarget)
134+
if (m_TrackedSource == audioSource && m_AudioContainer == newTarget)
135135
return;
136-
136+
137137
Reset();
138138

139139
m_TrackedSource = audioSource;
@@ -144,26 +144,26 @@ internal void UpdateTarget()
144144

145145
TargetChanged?.Invoke(this, EventArgs.Empty);
146146

147-
if (m_TrackedSource == null)
147+
if (m_TrackedSource == null)
148148
return;
149-
149+
150150
var trackedSourceSO = new SerializedObject(m_TrackedSource);
151151
var trackedSourceResourceProperty = trackedSourceSO.FindProperty("m_Resource");
152152
m_ResourceTrackerElement.TrackPropertyValue(trackedSourceResourceProperty, OnResourceChanged);
153153
}
154154
void OnResourceChanged(SerializedProperty property)
155155
{
156156
var container = property.objectReferenceValue as AudioRandomContainer;
157-
157+
158158
if (m_AudioContainer == container)
159159
return;
160160

161161
Reset();
162162
m_AudioContainer = container;
163-
163+
164164
if (m_AudioContainer != null)
165165
TargetPath = AssetDatabase.GetAssetPath(m_AudioContainer);
166-
166+
167167
TargetChanged?.Invoke(this, EventArgs.Empty);
168168
}
169169

@@ -245,7 +245,7 @@ internal ActivePlayable[] GetActivePlayables()
245245

246246
internal float GetMeterValue()
247247
{
248-
return IsPlayingOrPaused() ? m_PreviewAudioSource.GetAudioRandomContainerRuntimeMeterValue() : -80f;
248+
return m_PreviewAudioSource.GetAudioRandomContainerRuntimeMeterValue();
249249
}
250250

251251
internal bool IsDirty()

Editor/Mono/Audio/Mixer/GUI/AudioMixerWindow.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,10 @@ static List<AudioMixerController> FindAllAudioMixerControllers()
241241

242242
if (controller)
243243
{
244-
if (controller.IsInitialized())
244+
if (controller.HasValidSnapshots())
245245
result.Add(controller);
246246
else
247-
Debug.LogError($"Can not display audio mixer window for '{controller.name}' as it has not been properly initialized. The mixer asset is possibly corrupted.");
247+
Debug.LogError($"Can not display audio mixer window for '{controller.name}' as it could not be properly initialized. The mixer asset is possibly corrupted.");
248248
}
249249
}
250250
return result;
@@ -347,9 +347,9 @@ public void UndoRedoPerformed(in UndoRedoInfo info)
347347

348348
void OnMixerControllerChanged()
349349
{
350-
if (m_Controller != null && !m_Controller.IsInitialized())
350+
if (m_Controller != null && !m_Controller.HasValidSnapshots())
351351
{
352-
Debug.LogError($"Can not display audio mixer window for '{m_Controller.name}' as it has not been properly initialized. The mixer asset is possibly corrupted.");
352+
Debug.LogError($"Can not display audio mixer window for '{m_Controller.name}' as it could not be properly initialized. The mixer asset is possibly corrupted.");
353353
return;
354354
}
355355

@@ -384,11 +384,11 @@ void DetectControllerChange()
384384

385385
if (m_Controller != oldController)
386386
{
387-
if (m_Controller.IsInitialized())
387+
if (m_Controller.HasValidSnapshots())
388388
OnMixerControllerChanged();
389389
else
390390
{
391-
Debug.LogError($"Can not display audio mixer window for '{m_Controller.name}' as it has not been properly initialized. The mixer asset is possibly corrupted.");
391+
Debug.LogError($"Can not display audio mixer window for '{m_Controller.name}' as it could not be properly initialized. The mixer asset is possibly corrupted.");
392392
}
393393
}
394394
}

Editor/Mono/Audio/UIElements/Tickmarks.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,51 @@ private struct MiniScale : Scale
4949
public Tickmarks() : base()
5050
{
5151
generateVisualContent += context => GenerateVisualContent(context);
52-
5352
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
53+
RegisterCallback<CustomStyleResolvedEvent>(CustomStylesResolved);
54+
}
55+
56+
private static void CustomStylesResolved(CustomStyleResolvedEvent evt)
57+
{
58+
Tickmarks element = (Tickmarks)evt.currentTarget;
59+
element.GetColorsFromStylesheet();
60+
}
61+
62+
private static readonly CustomStyleProperty<Color> s_TickmarkColorProperty = new("--tickmark-color");
63+
64+
private Color m_TickmarkColor;
65+
66+
private void GetColorsFromStylesheet()
67+
{
68+
if (customStyle.TryGetValue(s_TickmarkColorProperty, out var tickmarkColor))
69+
{
70+
m_TickmarkColor = tickmarkColor;
71+
}
5472
}
5573

5674
private void OnGeometryChanged(GeometryChangedEvent evt)
5775
{
5876
MarkDirtyRepaint();
5977
}
6078

61-
static void GenerateVisualContent(MeshGenerationContext context)
79+
private static void GenerateVisualContent(MeshGenerationContext context)
6280
{
6381
var painter2D = context.painter2D;
6482

6583
var contentRect = context.visualElement.contentRect;
6684

6785
Scale scale = contentRect.width > 350 ? new LargeScale() : (contentRect.width > 175 ? new CompactScale() : new MiniScale());
6886

69-
var gray = new Color(0.85f, 0.85f, 0.85f, 1.0f);
87+
var tickmarkColor = (context.visualElement as Tickmarks).m_TickmarkColor;
88+
var textColor = tickmarkColor.RGBMultiplied(1.2f); // Compensate for a bug in UI Toolkit which causes MeshGenerationContext.DrawText to render text lighter than the color that you provide.
7089

7190
for (int index = 0; index < scale.DivisionCount(); index += 1)
7291
{
7392
var pos = contentRect.width * index / (scale.DivisionCount() - 1.0f);
7493

7594
var rect = new Rect(pos - 0.5f, 5.0f, 1.0f, 8.0f);
7695

77-
painter2D.fillColor = gray;
96+
painter2D.fillColor = tickmarkColor;
7897
painter2D.BeginPath();
7998
painter2D.MoveTo(new Vector2(rect.xMin, rect.yMin));
8099
painter2D.LineTo(new Vector2(rect.xMax, rect.yMin));
@@ -94,7 +113,7 @@ static void GenerateVisualContent(MeshGenerationContext context)
94113
{
95114
var rect = new Rect(pos - 0.5f + spacing * (subIndex + 1.0f) / (subDivCount + 1.0f), 5.0f, 1.0f, 4.0f);
96115

97-
painter2D.fillColor = gray;
116+
painter2D.fillColor = tickmarkColor;
98117
painter2D.BeginPath();
99118
painter2D.MoveTo(new Vector2(rect.xMin, rect.yMin));
100119
painter2D.LineTo(new Vector2(rect.xMax, rect.yMin));
@@ -111,7 +130,7 @@ static void GenerateVisualContent(MeshGenerationContext context)
111130

112131
var rect = new Rect(pos - 10.0f, 10, 20.0f, 20.0f);
113132

114-
context.DrawText(scale.Labels()[index], new Vector2(pos + scale.LabelOffsets()[index], 14.0f), 10.0f, gray);
133+
context.DrawText(scale.Labels()[index], new Vector2(pos + scale.LabelOffsets()[index], 14.0f), 10.0f, textColor);
115134
}
116135
}
117136
}

0 commit comments

Comments
 (0)