Skip to content

Commit c0e1b83

Browse files
author
Unity Technologies
committed
Unity 2023.2.0a14 C# reference source code
1 parent 0355e09 commit c0e1b83

File tree

430 files changed

+17445
-7019
lines changed

Some content is hidden

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

430 files changed

+17445
-7019
lines changed

Editor/Mono/Animation/AnimationWindow/AnimationWindowEventInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ private static void SetData(AnimationWindowEvent[] awEvents, AnimationWindowEven
582582
}
583583
}
584584

585-
[MenuItem("CONTEXT/AnimationWindowEvent/Reset")]
585+
[MenuItem("CONTEXT/AnimationWindowEvent/Reset", secondaryPriority = 7)]
586586
static void ResetValues(MenuCommand command)
587587
{
588588
AnimationWindowEvent awEvent = command.context as AnimationWindowEvent;

Editor/Mono/AssemblyValidation.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,34 @@ public static Error[] ValidateAssemblies(string[] assemblyPaths, bool enableLogg
138138
return errors;
139139
}
140140

141+
[RequiredByNativeCode]
142+
internal static Error[] ValidateRoslynAnalyzers(string[] analyzerPaths)
143+
{
144+
var readerParameters = new ReaderParameters
145+
{
146+
ReadingMode = ReadingMode.Deferred
147+
};
148+
List<Error> errors = new List<Error>();
149+
foreach(var analyzer in analyzerPaths)
150+
{
151+
using (var analyzerDefinition = AssemblyDefinition.ReadAssembly(analyzer, readerParameters))
152+
{
153+
var netstandardVersion = analyzerDefinition.MainModule.AssemblyReferences.Where(r => r.Name == "netstandard").FirstOrDefault();
154+
if (netstandardVersion != null && netstandardVersion.Version >= new Version(2, 1))
155+
{
156+
errors.Add(new Error
157+
{
158+
assemblyPath = analyzer,
159+
flags = ErrorFlags.ReferenceHasErrors,
160+
message = $"{analyzerDefinition.Name.Name} references {netstandardVersion}. A roslyn analyzer should reference netstandard version 2.0"
161+
});
162+
}
163+
164+
}
165+
}
166+
return errors.ToArray();
167+
}
168+
141169
[RequiredByNativeCode]
142170
public static Error[] ValidateAssemblyDefinitionFiles()
143171
{

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sealed class AudioContainerWindow : EditorWindow
3131
VisualElement m_PlayButtonImage;
3232
Button m_SkipButton;
3333
VisualElement m_SkipButtonImage;
34+
AudioLevelMeter m_Meter;
3435
Slider m_VolumeSlider;
3536
FloatField m_VolumeField;
3637
Button m_VolumeRandomizationButton;
@@ -205,6 +206,7 @@ void CreateBindings()
205206
m_PlayButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(rootVisualElement, "play-button-image");
206207
m_SkipButton = UIToolkitUtilities.GetChildByName<Button>(rootVisualElement, "skip-button");
207208
m_SkipButtonImage = UIToolkitUtilities.GetChildByName<VisualElement>(rootVisualElement, "skip-button-image");
209+
m_Meter = UIToolkitUtilities.GetChildByName<AudioLevelMeter>(rootVisualElement, "meter");
208210
m_VolumeSlider = UIToolkitUtilities.GetChildByName<Slider>(rootVisualElement, "volume-slider");
209211
m_VolumeField = UIToolkitUtilities.GetChildByName<FloatField>(rootVisualElement, "volume-field");
210212
m_VolumeRandomizationButton = UIToolkitUtilities.GetChildByName<Button>(rootVisualElement, "volume-randomization-button");
@@ -307,7 +309,6 @@ void CreateBindings()
307309

308310
m_ClipsListView.BindProperty(clipsProperty);
309311
m_ClipsListView.TrackPropertyValue(clipsProperty, OnAudioClipListChanged);
310-
m_ClipsListView.showBorder = true;
311312

312313
m_TriggerRadioButtonGroup.BindProperty(triggerProperty);
313314
m_PlaybackModeRadioButtonGroup.BindProperty(playbackModeProperty);
@@ -384,6 +385,23 @@ void OnEditorApplicationUpdate()
384385
EditorApplication.update -= OnEditorApplicationUpdate;
385386
}
386387

388+
private void Update()
389+
{
390+
if (m_Meter == null)
391+
{
392+
return;
393+
}
394+
395+
if (m_State != null)
396+
{
397+
m_Meter.Value = m_State.GetMeterValue();
398+
}
399+
else
400+
{
401+
m_Meter.Value = -80.0f;
402+
}
403+
}
404+
387405
void OnSerializedObjectChanged(SerializedObject obj)
388406
{
389407
SetTitle(m_State.IsDirty());

Editor/Mono/Audio/AudioContainerWindowState.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ void OnEditorPlayModeStateChanged(PlayModeStateChange state)
236236
}
237237
}
238238

239+
internal float GetMeterValue()
240+
{
241+
return m_PreviewAudioSource == null ? 0.0f : m_PreviewAudioSource.GetAudioRandomContainerRuntimeMeterValue();
242+
}
243+
239244
void OnSelectionChanged()
240245
{
241246
UpdateTarget();
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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 UnityEngine;
6+
using UnityEngine.UIElements;
7+
using Color = UnityEngine.Color;
8+
9+
namespace UnityEditor.Audio.UIElements
10+
{
11+
internal class AudioLevelMeter : VisualElement
12+
{
13+
public new class UxmlFactory : UxmlFactory<AudioLevelMeter, UxmlTraits> { }
14+
15+
public new class UxmlTraits : VisualElement.UxmlTraits { }
16+
17+
private float m_Value = -80.0f; // Value of the meter in dBFS.
18+
19+
public float Value
20+
{
21+
get
22+
{
23+
return m_Value;
24+
}
25+
26+
set
27+
{
28+
m_Value = value;
29+
MarkDirtyRepaint();
30+
}
31+
}
32+
33+
public AudioLevelMeter() : base()
34+
{
35+
generateVisualContent += GenerateVisualContent;
36+
37+
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
38+
}
39+
40+
private void OnGeometryChanged(GeometryChangedEvent evt)
41+
{
42+
MarkDirtyRepaint();
43+
}
44+
45+
private const float k_YellowStart = 11.0f / 14.0f;
46+
private const float k_RedStart = 13.0f / 14.0f;
47+
48+
private static float ConvertDBFSToMeterScale(float value)
49+
{
50+
// Converts dBFS to the non-linear scale that the meter uses.
51+
52+
switch (value)
53+
{
54+
case <= -80.0f: return 0.0f;
55+
case <= -30.0f: return value / (10.0f * 14.0f) + 80.0f / (10.0f * 14.0f) + 0.0f / 14.0f;
56+
case <= -24.0f: return value / ( 6.0f * 14.0f) + 30.0f / ( 6.0f * 14.0f) + 5.0f / 14.0f;
57+
case <= 0.0f: return value / ( 3.0f * 14.0f) + 24.0f / ( 3.0f * 14.0f) + 6.0f / 14.0f;
58+
default: return 1.0f;
59+
}
60+
}
61+
62+
private static Rect ShrinkRectBy(Rect rect, RectOffset offset)
63+
{
64+
var minX = rect.xMin + offset.left;
65+
var maxX = rect.xMax - offset.right;
66+
var minY = rect.yMin + offset.bottom;
67+
var maxY = rect.yMax - offset.top;
68+
69+
return new Rect(minX, minY, maxX - minX, maxY - minY);
70+
}
71+
72+
static void GenerateVisualContent(MeshGenerationContext context)
73+
{
74+
var painter2D = context.painter2D;
75+
76+
var value = ConvertDBFSToMeterScale((context.visualElement as AudioLevelMeter).m_Value);
77+
78+
var width = context.visualElement.contentRect.width;
79+
80+
var rect1 = context.visualElement.contentRect;
81+
82+
painter2D.fillColor = Color.gray;
83+
painter2D.BeginPath();
84+
painter2D.MoveTo(new Vector2(rect1.xMin, rect1.yMin));
85+
painter2D.LineTo(new Vector2(rect1.xMax, rect1.yMin));
86+
painter2D.LineTo(new Vector2(rect1.xMax, rect1.yMax));
87+
painter2D.LineTo(new Vector2(rect1.xMin, rect1.yMax));
88+
painter2D.ClosePath();
89+
painter2D.Fill();
90+
91+
if (value > 0)
92+
{
93+
var start = 0.0f;
94+
var end = width * Mathf.Min(value, k_YellowStart);
95+
var rect2 = ShrinkRectBy(context.visualElement.contentRect, new RectOffset((int) start, (int) (width - end), 0, 0));
96+
97+
painter2D.fillColor = Color.green;
98+
painter2D.BeginPath();
99+
painter2D.MoveTo(new Vector2(rect2.xMin, rect2.yMin));
100+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMin));
101+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMax));
102+
painter2D.LineTo(new Vector2(rect2.xMin, rect2.yMax));
103+
painter2D.ClosePath();
104+
painter2D.Fill();
105+
}
106+
107+
if (value > k_YellowStart)
108+
{
109+
var start = width * k_YellowStart;
110+
var end = width * Mathf.Min(value, k_RedStart);
111+
var rect2 = ShrinkRectBy(context.visualElement.contentRect, new RectOffset((int) start, (int) (width - end), 0, 0));
112+
113+
painter2D.fillColor = Color.yellow;
114+
painter2D.BeginPath();
115+
painter2D.MoveTo(new Vector2(rect2.xMin, rect2.yMin));
116+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMin));
117+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMax));
118+
painter2D.LineTo(new Vector2(rect2.xMin, rect2.yMax));
119+
painter2D.ClosePath();
120+
painter2D.Fill();
121+
}
122+
123+
if (value > k_RedStart)
124+
{
125+
var start = width * k_RedStart;
126+
var end = width * Mathf.Min(value, width);
127+
var rect2 = ShrinkRectBy(context.visualElement.contentRect, new RectOffset((int) start, (int) (width - end), 0, 0));
128+
129+
painter2D.fillColor = Color.red;
130+
painter2D.BeginPath();
131+
painter2D.MoveTo(new Vector2(rect2.xMin, rect2.yMin));
132+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMin));
133+
painter2D.LineTo(new Vector2(rect2.xMax, rect2.yMax));
134+
painter2D.LineTo(new Vector2(rect2.xMin, rect2.yMax));
135+
painter2D.ClosePath();
136+
painter2D.Fill();
137+
}
138+
}
139+
}
140+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 UnityEngine;
6+
using UnityEngine.UIElements;
7+
using Color = UnityEngine.Color;
8+
9+
namespace UnityEditor.Audio.UIElements
10+
{
11+
internal class Tickmarks : VisualElement
12+
{
13+
private interface Scale
14+
{
15+
int DivisionCount();
16+
string[] Labels();
17+
int[] SubDivisionCount();
18+
float[] LabelOffsets();
19+
}
20+
21+
private struct LargeScale : Scale
22+
{
23+
public int DivisionCount() { return 15; }
24+
public string[] Labels() { return new string[] { "80", "70", "60", "50", "40", "30", "24", "21", "18", "15", "12", "9", "6", "3", "0" }; }
25+
public int[] SubDivisionCount() { return new int[] { 4, 4, 4, 4, 4, 5, 2, 2, 2, 2, 2, 2, 2, 2 }; }
26+
public float[] LabelOffsets() { return new float[] { -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -3.5f, -3.5f, -3.5f, -3.5f }; }
27+
}
28+
29+
private struct CompactScale : Scale
30+
{
31+
public int DivisionCount() { return 8; }
32+
public string[] Labels() { return new string[] { "80", "60", "40", "24", "18", "12", "6", "0" }; }
33+
public int[] SubDivisionCount() { return new int[] { 4, 4, 3, 2, 2, 2, 2 }; }
34+
public float[] LabelOffsets() { return new float[] { -6, -6, -6, -6, -6, -6, -3.5f, -3.5f }; }
35+
}
36+
37+
private struct MiniScale : Scale
38+
{
39+
public int DivisionCount() { return 5; }
40+
public string[] Labels() { return new string[] { "80", "45", "21", "12", "0" }; }
41+
public int[] SubDivisionCount() { return new int[] { 6, 3, 2, 3 }; }
42+
public float[] LabelOffsets() { return new float[] { -6, -6, -6, -6, -3.5f }; }
43+
}
44+
45+
public new class UxmlFactory : UxmlFactory<Tickmarks, UxmlTraits> { }
46+
47+
public new class UxmlTraits : VisualElement.UxmlTraits { }
48+
49+
public Tickmarks() : base()
50+
{
51+
generateVisualContent += context => GenerateVisualContent(context);
52+
53+
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
54+
}
55+
56+
private void OnGeometryChanged(GeometryChangedEvent evt)
57+
{
58+
MarkDirtyRepaint();
59+
}
60+
61+
static void GenerateVisualContent(MeshGenerationContext context)
62+
{
63+
var painter2D = context.painter2D;
64+
65+
var contentRect = context.visualElement.contentRect;
66+
67+
Scale scale = contentRect.width > 350 ? new LargeScale() : (contentRect.width > 175 ? new CompactScale() : new MiniScale());
68+
69+
var gray = new Color(0.85f, 0.85f, 0.85f, 1.0f);
70+
71+
for (int index = 0; index < scale.DivisionCount(); index += 1)
72+
{
73+
var pos = contentRect.width * index / (scale.DivisionCount() - 1.0f);
74+
75+
var rect = new Rect(pos - 0.5f, 5.0f, 1.0f, 8.0f);
76+
77+
painter2D.fillColor = gray;
78+
painter2D.BeginPath();
79+
painter2D.MoveTo(new Vector2(rect.xMin, rect.yMin));
80+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMin));
81+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMax));
82+
painter2D.LineTo(new Vector2(rect.xMin, rect.yMax));
83+
painter2D.ClosePath();
84+
painter2D.Fill();
85+
}
86+
87+
for (int index = 0; index < scale.DivisionCount() - 1; index += 1)
88+
{
89+
var pos = contentRect.width * index / (scale.DivisionCount() - 1.0f);
90+
var spacing = contentRect.width / (scale.DivisionCount() - 1.0f);
91+
var subDivCount = scale.SubDivisionCount()[index];
92+
93+
for (int subIndex = 0; subIndex < subDivCount; subIndex++)
94+
{
95+
var rect = new Rect(pos - 0.5f + spacing * (subIndex + 1.0f) / (subDivCount + 1.0f), 5.0f, 1.0f, 4.0f);
96+
97+
painter2D.fillColor = gray;
98+
painter2D.BeginPath();
99+
painter2D.MoveTo(new Vector2(rect.xMin, rect.yMin));
100+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMin));
101+
painter2D.LineTo(new Vector2(rect.xMax, rect.yMax));
102+
painter2D.LineTo(new Vector2(rect.xMin, rect.yMax));
103+
painter2D.ClosePath();
104+
painter2D.Fill();
105+
}
106+
}
107+
108+
for (int index = 0; index < scale.DivisionCount(); index += 1)
109+
{
110+
var pos = contentRect.width * index / (scale.DivisionCount() - 1.0f);
111+
112+
var rect = new Rect(pos - 10.0f, 10, 20.0f, 20.0f);
113+
114+
context.DrawText(scale.Labels()[index], new Vector2(pos + scale.LabelOffsets()[index], 14.0f), 10.0f, gray);
115+
}
116+
}
117+
}
118+
}

Editor/Mono/CodeEditor/CodeEditorProjectSync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void PostprocessSyncProject(
3636
CodeEditor.Editor.CurrentCodeEditor.SyncIfNeeded(addedAssets, deletedAssets, movedAssets, movedFromAssetPaths, importedAssets);
3737
}
3838

39-
[MenuItem("Assets/Open C# Project")]
39+
[MenuItem("Assets/Open C# Project", secondaryPriority = 1)]
4040
static void SyncAndOpenSolution()
4141
{
4242
// Ensure that the mono islands are up-to-date

Editor/Mono/Commands/GOCreationCommands.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ internal static void Place(GameObject go, GameObject parent, bool ignoreSceneVie
8080
Selection.activeGameObject = go;
8181
}
8282

83-
[MenuItem("GameObject/Create Empty %#n", priority = 0)]
83+
[MenuItem("GameObject/Create Empty %#n", priority = 0, secondaryPriority = 1)]
8484
static void CreateEmpty(MenuCommand menuCommand)
8585
{
8686
var parent = menuCommand.context as GameObject;
8787
Place(ObjectFactory.CreateGameObject("GameObject"), parent);
8888
}
8989

90-
[MenuItem("GameObject/Create Empty Child &#n", priority = 0)]
90+
[MenuItem("GameObject/Create Empty Child &#n", priority = 0, secondaryPriority = 2)]
9191
static void CreateEmptyChild(MenuCommand menuCommand)
9292
{
9393
var parent = menuCommand.context as GameObject;
@@ -109,7 +109,7 @@ static void CreateEmptyChild(MenuCommand menuCommand)
109109
}
110110

111111
// Avoiding executing this method per-object, by adding menu item manually in SceneHierarchy
112-
[MenuItem("GameObject/Create Empty Parent %#g", priority = 0)]
112+
[MenuItem("GameObject/Create Empty Parent %#g", priority = 0, secondaryPriority = 3)]
113113
internal static void CreateEmptyParent()
114114
{
115115
Transform[] selected = Selection.transforms;

0 commit comments

Comments
 (0)