Skip to content

Commit 3d74e12

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a8 C# reference source code
1 parent 0e55b91 commit 3d74e12

File tree

94 files changed

+3188
-961
lines changed

Some content is hidden

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

94 files changed

+3188
-961
lines changed

Editor/Mono/Animation/TransitionPreview.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ private void ResampleTransition(AnimatorStateTransition transition, AvatarMask l
269269
AnimatorStateInfo currentState = m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(m_LayerIndex);
270270
m_LeftStateWeightA = currentState.normalizedTime;
271271
m_LeftStateTimeA = currentTime;
272-
while (!hasFinished && currentTime < maxDuration)
272+
while (!hasFinished)
273273
{
274274
m_AvatarPreview.Animator.Update(stepTime);
275275

@@ -284,7 +284,7 @@ private void ResampleTransition(AnimatorStateTransition transition, AvatarMask l
284284
hasStarted = true;
285285
}
286286

287-
if (hasTransitioned && currentTime >= maxDuration)
287+
if (hasTransitioned || currentTime >= maxDuration)
288288
{
289289
hasFinished = true;
290290
}
@@ -303,7 +303,7 @@ private void ResampleTransition(AnimatorStateTransition transition, AvatarMask l
303303
m_LeftStateTimeB = currentTime;
304304
}
305305

306-
if (hasTransitioned)
306+
if (hasTransitioned || hasFinished)
307307
{
308308
m_RightStateWeightB = currentState.normalizedTime;
309309
m_RightStateTimeB = currentTime;
@@ -329,6 +329,11 @@ private void ResampleTransition(AnimatorStateTransition transition, AvatarMask l
329329
float leftDuration = (m_LeftStateTimeB - m_LeftStateTimeA) / (m_LeftStateWeightB - m_LeftStateWeightA);
330330
float rightDuration = (m_RightStateTimeB - m_RightStateTimeA) / (m_RightStateWeightB - m_RightStateWeightA);
331331

332+
// Ensure step times make sense based on these timings
333+
// If step time is too small, the samping will take too long
334+
currentStateStepTime = Mathf.Max(currentStateStepTime, leftDuration / 600.0f);
335+
nextStateStepTime = Mathf.Max(nextStateStepTime, rightDuration / 600.0f);
336+
332337
if (m_MustSampleMotions)
333338
{
334339
// Do this as infrequently as possible

Editor/Mono/AssetPreviewUpdater.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@
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 UnityEngine;
76
using UnityEngine.Rendering;
87
using UnityEngine.Scripting;
9-
using Object = UnityEngine.Object;
108

119
namespace UnityEditor
1210
{
1311
internal static class AssetPreviewUpdater
1412
{
15-
static readonly Type[] s_InspectorsRequireFullPipelineInitialization = new[] { typeof(MaterialEditor), typeof(ModelInspector), typeof(GameObjectInspector) };
16-
1713
[RequiredByNativeCode]
1814
public static Texture2D CreatePreviewForAsset(Object obj, Object[] subAssets, string assetPath)
1915
{
@@ -37,30 +33,20 @@ public static Texture2D CreatePreview(Object obj, Object[] subAssets, string ass
3733
if (info.DeclaringType == typeof(Editor))
3834
return null;
3935

40-
4136
var editor = Editor.CreateEditor(obj);
42-
4337
if (editor == null)
4438
return null;
4539

4640
//Check that Render Pipeline is ready
41+
//Beware: AssetImportWorkers have their own Render Pipeline instance. Render Pipeline will be separately created for each one of them.
4742
var pipelineWasNotInitialized = !RenderPipelineManager.pipelineSwitchCompleted;
4843

49-
//We keep this call to initialize Render Pipeline when Render Pipeline is not ready
50-
var tex = editor.RenderStaticPreview(assetPath, subAssets, width, height);
44+
//We always keep this call to initialize Render Pipeline when Render Pipeline was not ready
45+
var previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);
5146

52-
//If Render Pipeline was not created before we will ignore the results and mark it dirty.
53-
if (pipelineWasNotInitialized)
54-
{
55-
for (int i = 0; i < s_InspectorsRequireFullPipelineInitialization.Length; i++)
56-
{
57-
if (type != s_InspectorsRequireFullPipelineInitialization[i])
58-
continue;
59-
EditorUtility.SetDirty(obj);
60-
Object.DestroyImmediate(editor);
61-
return null;
62-
}
63-
}
47+
//If after render our Render Pipeline is initialized we re-render to have a valid result
48+
if (pipelineWasNotInitialized && RenderPipelineManager.pipelineSwitchCompleted)
49+
previewTexture = editor.RenderStaticPreview(assetPath, subAssets, width, height);
6450

6551
// For debugging we write the preview to a file (keep)
6652
//{
@@ -71,8 +57,7 @@ public static Texture2D CreatePreview(Object obj, Object[] subAssets, string ass
7157
//}
7258

7359
Object.DestroyImmediate(editor);
74-
75-
return tex;
60+
return previewTexture;
7661
}
7762
}
7863
}

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ void OneTimeEditorApplicationUpdate()
310310
EditorApplication.update -= OneTimeEditorApplicationUpdate;
311311
}
312312

313+
static void InsertUnitFieldForFloatField(VisualElement field, string unit)
314+
{
315+
var floatInput = UIToolkitUtilities.GetChildByName<VisualElement>(field, "unity-text-input");
316+
var unitTextElement = new TextElement
317+
{
318+
name = "numeric-field-unit-label",
319+
text = unit
320+
};
321+
floatInput.Add(unitTextElement);
322+
}
323+
313324
#region Preview
314325

315326
void InitializePreviewElements()
@@ -406,14 +417,18 @@ void InitializeVolumeElements()
406417
var volumeRandomizationMinField = UIToolkitUtilities.GetChildByName<FloatField>(m_VolumeRandomizationRangeField, "unity-x-input");
407418
var volumeRandomizationMaxField = UIToolkitUtilities.GetChildByName<FloatField>(m_VolumeRandomizationRangeField, "unity-y-input");
408419

409-
m_VolumeField.formatString = "0.# dB";
420+
m_VolumeField.formatString = "0.#";
421+
InsertUnitFieldForFloatField(m_VolumeField, "dB");
410422
m_VolumeField.isDelayed = true;
411423
volumeRandomizationMinField.isDelayed = true;
412424
volumeRandomizationMinField.label = "";
413-
volumeRandomizationMinField.formatString = "0.# dB";
425+
volumeRandomizationMinField.formatString = "0.#";
426+
InsertUnitFieldForFloatField(volumeRandomizationMinField, "dB");
414427
volumeRandomizationMaxField.isDelayed = true;
415428
volumeRandomizationMaxField.label = "";
416-
volumeRandomizationMaxField.formatString = "0.# dB";
429+
volumeRandomizationMaxField.formatString = "0.#";
430+
InsertUnitFieldForFloatField(volumeRandomizationMaxField, "dB");
431+
417432
}
418433

419434
void SubscribeToVolumeCallbacksAndEvents()
@@ -508,14 +523,17 @@ void InitializePitchElements()
508523
var pitchRandomizationMinField = UIToolkitUtilities.GetChildByName<FloatField>(m_PitchRandomizationRangeField, "unity-x-input");
509524
var pitchRandomizationMaxField = UIToolkitUtilities.GetChildByName<FloatField>(m_PitchRandomizationRangeField, "unity-y-input");
510525

511-
m_PitchField.formatString = "0 ct";
526+
m_PitchField.formatString = "0";
527+
InsertUnitFieldForFloatField(m_PitchField, "ct");
512528
m_PitchField.isDelayed = true;
513529
pitchRandomizationMinField.isDelayed = true;
514530
pitchRandomizationMinField.label = "";
515-
pitchRandomizationMinField.formatString = "0 ct";
531+
pitchRandomizationMinField.formatString = "0";
532+
InsertUnitFieldForFloatField(pitchRandomizationMinField, "ct");
516533
pitchRandomizationMaxField.isDelayed = true;
517534
pitchRandomizationMaxField.label = "";
518-
pitchRandomizationMaxField.formatString = "0 ct";
535+
pitchRandomizationMaxField.formatString = "0";
536+
InsertUnitFieldForFloatField(pitchRandomizationMaxField, "ct");
519537
}
520538

521539
void SubscribeToPitchCallbacksAndEvents()
@@ -653,7 +671,10 @@ static void UpdateListElementName(Object element, Object clip = null)
653671

654672
static VisualElement OnMakeListItem()
655673
{
656-
return UIToolkitUtilities.LoadUxml("UXML/Audio/AudioContainerElement.uxml").Instantiate();
674+
var element = UIToolkitUtilities.LoadUxml("UXML/Audio/AudioContainerElement.uxml").Instantiate();
675+
var volumeField = UIToolkitUtilities.GetChildByName<FloatField>(element, "volume-field");
676+
InsertUnitFieldForFloatField(volumeField, "dB");
677+
return element;
657678
}
658679

659680
void OnBindListItem(VisualElement element, int index)
@@ -665,7 +686,7 @@ void OnBindListItem(VisualElement element, int index)
665686
var enabledToggle = UIToolkitUtilities.GetChildByName<Toggle>(element, "enabled-toggle");
666687
var audioClipField = UIToolkitUtilities.GetChildByName<AudioContainerElementClipField>(element, "audio-clip-field");
667688
var volumeField = UIToolkitUtilities.GetChildByName<FloatField>(element, "volume-field");
668-
volumeField.formatString = "0.# dB";
689+
volumeField.formatString = "0.#";
669690

670691
audioClipField.objectType = typeof(AudioClip);
671692

@@ -996,14 +1017,18 @@ void InitializeAutomaticTriggerElements()
9961017
m_AutomaticTriggerModeLabel = UIToolkitUtilities.GetChildByName<Label>(m_ContainerRootVisualElement, "automatic-trigger-mode-label");
9971018
m_LoopLabel = UIToolkitUtilities.GetChildByName<Label>(m_ContainerRootVisualElement, "loop-label");
9981019

999-
m_TimeField.formatString = "0.00 s";
1020+
m_TimeField.formatString = "0.00";
1021+
InsertUnitFieldForFloatField(m_TimeField, "s");
10001022
m_TimeField.isDelayed = true;
10011023
timeRandomizationMinField.isDelayed = true;
10021024
timeRandomizationMinField.label = "";
10031025
timeRandomizationMinField.formatString = "0.#";
1026+
InsertUnitFieldForFloatField(timeRandomizationMinField, "s");
10041027
timeRandomizationMaxField.isDelayed = true;
10051028
timeRandomizationMaxField.label = "";
10061029
timeRandomizationMaxField.formatString = "0.#";
1030+
InsertUnitFieldForFloatField(timeRandomizationMaxField, "s");
1031+
10071032
m_CountField.formatString = "0.#";
10081033
m_CountField.isDelayed = true;
10091034
countRandomizationMinField.isDelayed = true;
@@ -1151,6 +1176,11 @@ void OnCountRandomizationButtonClicked()
11511176

11521177
void OnUndoRedoPerformed()
11531178
{
1179+
if (m_ContainerRootVisualElement == null
1180+
|| m_ContainerRootVisualElement.style.display == DisplayStyle.None
1181+
|| State.AudioContainer == null)
1182+
return;
1183+
11541184
if (m_CachedElements.Count != State.AudioContainer.elements.Length)
11551185
{
11561186
// Force a list rebuild when the list size has increased or it will not render correctly

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,14 @@ static List<AudioMixerController> FindAllAudioMixerControllers()
238238
foreach (var prop in AssetDatabase.FindAllAssets(new SearchFilter() { classNames = new[] { "AudioMixerController" } }))
239239
{
240240
var controller = prop.pptrValue as AudioMixerController;
241+
241242
if (controller)
242-
result.Add(controller);
243+
{
244+
if (controller.IsInitialized())
245+
result.Add(controller);
246+
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.");
248+
}
243249
}
244250
return result;
245251
}
@@ -341,6 +347,12 @@ public void UndoRedoPerformed(in UndoRedoInfo info)
341347

342348
void OnMixerControllerChanged()
343349
{
350+
if (m_Controller != null && !m_Controller.IsInitialized())
351+
{
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.");
353+
return;
354+
}
355+
344356
if (m_Controller)
345357
m_Controller.ClearEventHandlers();
346358

@@ -369,9 +381,15 @@ void DetectControllerChange()
369381
AudioMixerController oldController = m_Controller;
370382
if (Selection.activeObject is AudioMixerController)
371383
m_Controller = Selection.activeObject as AudioMixerController;
384+
372385
if (m_Controller != oldController)
373386
{
374-
OnMixerControllerChanged();
387+
if (m_Controller.IsInitialized())
388+
OnMixerControllerChanged();
389+
else
390+
{
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.");
392+
}
375393
}
376394
}
377395

Editor/Mono/Audio/UIElements/AudioRandomRangeSliderTracker.cs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ class AudioRandomRangeSliderTracker : VisualElement
2020
Slider m_ParentSlider;
2121
float m_PreviousWidth;
2222
Vector2 m_Range = Vector2.zero;
23-
24-
public AudioRandomRangeSliderTracker()
25-
{
26-
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
27-
}
28-
23+
2924
internal static AudioRandomRangeSliderTracker Create(Slider parentSlider, Vector2 range)
3025
{
3126
var dragContainer = UIToolkitUtilities.GetChildByName<VisualElement>(parentSlider, "unity-drag-container");
@@ -36,41 +31,45 @@ internal static AudioRandomRangeSliderTracker Create(Slider parentSlider, Vector
3631
dragContainer.Insert(insertionIndex, templateContainer);
3732
var rangeTracker = UIToolkitUtilities.GetChildAtIndex<AudioRandomRangeSliderTracker>(templateContainer, 0);
3833
rangeTracker.m_ParentSlider = parentSlider;
34+
rangeTracker.m_ParentSlider.RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
3935
rangeTracker.SetRange(range);
4036
return rangeTracker;
4137
}
4238

4339
internal void SetRange(Vector2 range)
4440
{
4541
m_Range = range;
42+
var minValue = m_ParentSlider.value - Math.Abs(m_Range.x);
43+
minValue = Mathf.Clamp(minValue, m_ParentSlider.lowValue, m_ParentSlider.highValue);
44+
var maxValue = m_ParentSlider.value + Mathf.Abs(m_Range.y);
45+
maxValue = Mathf.Clamp(maxValue, m_ParentSlider.lowValue, m_ParentSlider.highValue);
4646

47-
if (Mathf.Approximately(parent.contentRect.width, 0) || m_Range == Vector2.zero)
47+
if (Mathf.Approximately(parent.contentRect.width, 0) || m_Range == Vector2.zero || Mathf.Approximately(minValue ,maxValue))
4848
{
49-
style.visibility = Visibility.Hidden;
49+
style.display = DisplayStyle.None;
5050
return;
5151
}
5252

53-
var minValue = m_ParentSlider.value - Math.Abs(m_Range.x);
54-
minValue = Mathf.Clamp(minValue, m_ParentSlider.lowValue, m_ParentSlider.highValue);
55-
var maxValue = m_ParentSlider.value + Mathf.Abs(m_Range.y);
56-
maxValue = Mathf.Clamp(maxValue, m_ParentSlider.lowValue, m_ParentSlider.highValue);
5753
var minValueDelta = minValue - m_ParentSlider.lowValue;
5854
var maxValueDelta = maxValue - m_ParentSlider.lowValue;
59-
var minValueFraction = minValueDelta / m_ParentSlider.range;
60-
var maxValueFraction = maxValueDelta / m_ParentSlider.range;
61-
style.marginLeft = minValueFraction * parent.contentRect.width;
62-
style.marginRight = parent.contentRect.width - (maxValueFraction * parent.contentRect.width);
63-
style.visibility = Visibility.Visible;
55+
56+
var pxPerVal = parent.contentRect.width / m_ParentSlider.range;
57+
var translate = style.translate.value;
58+
translate.x = pxPerVal * minValueDelta;
59+
style.translate = translate;
60+
style.width = (maxValueDelta - minValueDelta) * pxPerVal;
61+
style.display = DisplayStyle.Flex;
6462
}
6563

66-
void OnGeometryChanged(GeometryChangedEvent evt)
64+
static void OnGeometryChanged(GeometryChangedEvent evt)
6765
{
68-
if (Mathf.Approximately(m_PreviousWidth, parent.contentRect.width))
66+
var sliderTracker = UIToolkitUtilities.GetChildByClassName<AudioRandomRangeSliderTracker>(evt.elementTarget, "unity-audio-random-range-slider-tracker");
67+
if (Mathf.Approximately(sliderTracker.m_PreviousWidth, sliderTracker.parent.contentRect.width))
6968
{
7069
return;
7170
}
7271

73-
m_PreviousWidth = parent.contentRect.width;
74-
SetRange(m_Range);
72+
sliderTracker.m_PreviousWidth = sliderTracker.parent.contentRect.width;
73+
sliderTracker.SetRange(sliderTracker.m_Range);
7574
}
7675
}

Editor/Mono/Camera/EditorCameraUtils.bindings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
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+
using Unity.Collections;
7+
using Unity.Collections.LowLevel.Unsafe;
58
using UnityEngine;
69
using UnityEngine.Bindings;
710
using UnityEngine.Internal;
@@ -16,7 +19,19 @@ public static class EditorCameraUtils
1619
public static bool RenderToCubemap(this Camera camera, Texture target, int faceMask, StaticEditorFlags culledFlags)
1720
=> RenderToCubemapImpl(camera, target, faceMask, culledFlags) == 1;
1821

22+
public static unsafe void GetRenderersFilteringResults(ReadOnlySpan<int> rendererIDs, Span<bool> results)
23+
{
24+
if (rendererIDs.Length != results.Length)
25+
throw new ArgumentException("rendererIDs and results NativeArrays don't match in length.");
26+
27+
GetRenderersFilteringResultsImpl(rendererIDs, results);
28+
}
29+
1930
[FreeFunction("EditorCameraUtilsScripting::RenderToCubemap")]
2031
static extern int RenderToCubemapImpl(Camera camera, Texture target, [DefaultValue("63")] int faceMask, StaticEditorFlags culledFlags);
32+
33+
[FreeFunction("EditorCameraUtilsScripting::GetRenderersFilteringResults")]
34+
static extern unsafe void GetRenderersFilteringResultsImpl(ReadOnlySpan<int> rendererIDs, Span<bool> results);
35+
2136
}
2237
}

Editor/Mono/EditorApplication.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public static event Action<PlayModeStateChange> playModeStateChanged
267267
[Obsolete("Use EditorApplication.playModeStateChanged and/or EditorApplication.pauseStateChanged")]
268268
public static CallbackFunction playmodeStateChanged;
269269

270-
// Global key up/down event that was not handled by anyone
270+
// Global key up/down or mouse up/down/drag events that were not handled by anyone
271271
internal static CallbackFunction globalEventHandler;
272272

273273
// Returns true when the pressed keys are defined in the Trigger

Editor/Mono/EditorGUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6605,7 +6605,7 @@ public static void HelpBox(Rect position, GUIContent content)
66056605
if (content.image != null)
66066606
{
66076607
var labelRect = position;
6608-
int iconSize = content.image.width + EditorStyles.helpBox.padding.right;
6608+
int iconSize = (int) (content.image.width / EditorGUIUtility.pixelsPerPoint) + EditorStyles.helpBox.padding.right;
66096609
labelRect.x += iconSize;
66106610
labelRect.width -= iconSize;
66116611

Editor/Mono/EditorWindow.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ static public EditorWindow mouseOverWindow
437437
return null;
438438
}
439439
}
440-
441-
440+
442441
internal int GetNumTabs()
443442
{
444443
DockArea da = m_Parent as DockArea;

0 commit comments

Comments
 (0)