Skip to content

Commit fca55ae

Browse files
author
Unity Technologies
committed
Unity 2018.3.5f1 C# reference source code
1 parent ccb1465 commit fca55ae

11 files changed

Lines changed: 121 additions & 15 deletions

File tree

‎Editor/Mono/Inspector/AdvancedDropdown/AdvancedDropdownWindow.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,14 @@ private void DrawList(AdvancedDropdownItem item)
336336
for (var i = 0; i < item.children.Count; i++)
337337
{
338338
var child = item.children[i];
339+
340+
// Select the first item when searching
341+
if (hasSearch && !item.selectionExists && item.selectedItem < 0)
342+
{
343+
item.selectedItem = 0;
344+
}
339345
bool selected = item.selectionExists && i == item.selectedItem;
346+
340347
gui.DrawItem(child, selected, hasSearch);
341348
var r = GUILayoutUtility.GetLastRect();
342349
if (selected)

‎Editor/Mono/MonoScript.bindings.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ internal void Init(string scriptContents, string className, string nameSpace, st
6262
[FreeFunction("MonoScript_Init")]
6363
private static extern void Init(MonoScript self, string scriptContents, string className, string nameSpace, string assemblyName, bool isEditorScript);
6464

65+
// *undocumented*
66+
[NativeName("GetAssemblyName")]
67+
internal extern string GetAssemblyName();
68+
6569
// *undocumented*
6670
[NativeName("GetNameSpace")]
6771
internal extern string GetNamespace();

‎Editor/Mono/PlayerSettingsSwitch.bindings.cs‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ public enum SupportedNpadStyle
135135
[NativeProperty("switchUseCPUProfiler", TargetType.Field)]
136136
extern public static bool useSwitchCPUProfiler { get; set; }
137137

138+
// System Memory (used for virtual memory mapping).
139+
[NativeProperty("switchSystemResourceMemory", TargetType.Field)]
140+
extern public static int systemResourceMemory { get; set; }
141+
138142
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
139143
extern public static int queueCommandMemory
140144
{
@@ -144,6 +148,67 @@ extern public static int queueCommandMemory
144148
set;
145149
}
146150

151+
[StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)]
152+
extern public static int defaultSwitchQueueCommandMemory { get; }
153+
154+
[StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)]
155+
extern public static int minimumSwitchQueueCommandMemory { get; }
156+
157+
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
158+
extern public static int queueControlMemory
159+
{
160+
[NativeMethod("GetSwitchQueueControlMemory")]
161+
get;
162+
[NativeMethod("SetSwitchQueueControlMemory")]
163+
set;
164+
}
165+
166+
[StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)]
167+
extern public static int defaultSwitchQueueControlMemory { get; }
168+
169+
[StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)]
170+
extern public static int minimumSwitchQueueControlMemory { get; }
171+
172+
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
173+
extern public static int queueComputeMemory
174+
{
175+
[NativeMethod("GetSwitchQueueComputeMemory")]
176+
get;
177+
[NativeMethod("SetSwitchQueueComputeMemory")]
178+
set;
179+
}
180+
181+
[StaticAccessor("PlayerSettings", StaticAccessorType.DoubleColon)]
182+
extern public static int defaultSwitchQueueComputeMemory { get; }
183+
184+
// GPU Pool information.
185+
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
186+
extern public static int NVNShaderPoolsGranularity
187+
{
188+
[NativeMethod("GetSwitchNVNShaderPoolsGranularity")]
189+
get;
190+
[NativeMethod("SetSwitchNVNShaderPoolsGranularity")]
191+
set;
192+
}
193+
194+
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
195+
extern public static int NVNDefaultPoolsGranularity
196+
{
197+
[NativeMethod("GetSwitchNVNDefaultPoolsGranularity")]
198+
get;
199+
[NativeMethod("SetSwitchNVNDefaultPoolsGranularity")]
200+
set;
201+
}
202+
203+
[StaticAccessor("GetPlayerSettings()", StaticAccessorType.Dot)]
204+
extern public static int NVNOtherPoolsGranularity
205+
{
206+
[NativeMethod("GetSwitchNVNOtherPoolsGranularity")]
207+
get;
208+
[NativeMethod("SetSwitchNVNOtherPoolsGranularity")]
209+
set;
210+
}
211+
147212
// Controls the behavior of Switch's auto-changing screen resolution
148213
[NativeProperty("switchScreenResolutionBehavior", TargetType.Field)]
149214
extern public static ScreenResolutionBehavior screenResolutionBehavior { get; set; }

‎Editor/Mono/ScriptEditorUtility.cs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,26 @@ public static ScriptEditor GetScriptEditorFromPath(string path)
4949

5050
string filename = Path.GetFileName(Paths.UnifyDirectorySeparator(lowerCasePath)).Replace(" ", "");
5151

52-
// Visual Studio for Mac is based on MonoDevelop
53-
if (filename == "visualstudio.app")
54-
return ScriptEditor.MonoDevelop;
55-
5652
if (filename == "code.exe" || filename == "visualstudiocode.app" || filename == "vscode.app" || filename == "code.app" || filename == "code")
5753
return ScriptEditor.VisualStudioCode;
5854

5955
if (filename.StartsWith("rider"))
6056
return ScriptEditor.Rider;
6157

58+
// Visual Studio for Mac is based on MonoDevelop
59+
if (IsVisualStudioForMac(path))
60+
return ScriptEditor.MonoDevelop;
61+
6262
return ScriptEditor.Other;
6363
}
6464

65+
internal static bool IsVisualStudioForMac(string path)
66+
{
67+
var lowerCasePath = path.ToLower();
68+
var filename = Path.GetFileName(Paths.UnifyDirectorySeparator(lowerCasePath)).Replace(" ", "");
69+
return filename.StartsWith("visualstudio") && !filename.Contains("code") && filename.EndsWith(".app");
70+
}
71+
6572
public static string GetExternalScriptEditor()
6673
{
6774
var editor = EditorPrefs.GetString("kScriptsDefaultApp");
@@ -143,6 +150,7 @@ public static Dictionary<string, string> GetFoundScriptEditorPaths(RuntimePlatfo
143150
if (platform == RuntimePlatform.OSXEditor)
144151
{
145152
AddIfDirectoryExists("Visual Studio", "/Applications/Visual Studio.app", result);
153+
AddIfDirectoryExists("Visual Studio (Preview)", "/Applications/Visual Studio (Preview).app", result);
146154
}
147155

148156
foreach (var callback in k_PathCallbacks)

‎Editor/Mono/Scripting/ScriptCompilation/EditorBuildRules.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ public static ScriptAssembly[] GenerateChangedScriptAssemblies(GenerateChangedSc
419419

420420
assemblySourceFiles.Add(AssetPath.Combine(args.ProjectDirectory, dirtySourceFile));
421421

422+
if (targetAssembly.Language == null && targetAssembly.Type == TargetAssemblyType.Custom)
423+
targetAssembly.Language = scriptLanguage;
424+
422425
// If there are mixed languages in a custom script folder, mark the assembly to not be compiled.
423426
if (scriptLanguage != targetAssembly.Language)
424427
args.NotCompiledTargetAssemblies.Add(targetAssembly);

‎Editor/Mono/VisualStudioIntegration/UnityVSSupport.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private static bool IsVSForMac(string externalEditor, out Version vsfmVersion)
6464
{
6565
vsfmVersion = null;
6666

67-
if (!externalEditor.ToLower().EndsWith("visual studio.app"))
67+
if (!ScriptEditorUtility.IsVisualStudioForMac(externalEditor))
6868
return false;
6969

7070
// We need to extract the version used by VS for Mac

‎Modules/UIElements/Controls/TextInputFieldBase.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ internal void DrawWithTextSelectionAndCursor(IStylePainterInternal painter, stri
268268

269269
IStyle style = this.style;
270270

271-
float textScaling = TextNative.ComputeTextScaling(worldTransform);
271+
float textScaling = TextNative.ComputeTextScaling(worldTransform, GUIUtility.pixelsPerPoint);
272272

273273
var textParams = TextStylePainterParameters.GetDefault(this, text);
274274
textParams.text = " ";

‎Modules/UIElements/TextElement.cs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string te
7373
float measuredWidth = float.NaN;
7474
float measuredHeight = float.NaN;
7575

76-
// TODO: This scaling parameter should depend on the real scaling of the text (dpi scaling * world scaling)
77-
// because depending of its value, the glyphs may align on different pixels which can change the
78-
// measure. The resulting measure should then be divided by this scaling to obtain the local measure.
79-
float scaling = 1;
8076

8177
Font usedFont = ve.style.font;
8278
if (textToMeasure == null || usedFont == null)
8379
return new Vector2(measuredWidth, measuredHeight);
8480

81+
var elementScaling = ve.ComputeGlobalScale();
82+
83+
float pixelsPerPoint = (ve.elementPanel != null) ? ve.elementPanel.currentPixelsPerPoint : GUIUtility.pixelsPerPoint;
84+
float scaling = (elementScaling.x + elementScaling.y) * 0.5f * pixelsPerPoint;
85+
8586
if (widthMode == MeasureMode.Exactly)
8687
{
8788
measuredWidth = width;
@@ -95,7 +96,8 @@ internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string te
9596
textParams.wordWrap = false;
9697
textParams.richText = true;
9798

98-
measuredWidth = TextNative.ComputeTextWidth(textParams.GetTextNativeSettings(scaling));
99+
//we make sure to round up as yoga could decide to round down and text would start wrapping
100+
measuredWidth = Mathf.Ceil(TextNative.ComputeTextWidth(textParams.GetTextNativeSettings(scaling)));
99101

100102
if (widthMode == MeasureMode.AtMost)
101103
{
@@ -115,7 +117,7 @@ internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string te
115117
textParams.wordWrapWidth = measuredWidth;
116118
textParams.richText = true;
117119

118-
measuredHeight = TextNative.ComputeTextHeight(textParams.GetTextNativeSettings(scaling));
120+
measuredHeight = Mathf.Ceil(TextNative.ComputeTextHeight(textParams.GetTextNativeSettings(scaling)));
119121

120122
if (heightMode == MeasureMode.AtMost)
121123
{

‎Modules/UIElements/TextNative.bindings.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public static Vector2 GetOffset(TextNativeSettings settings, Rect screenRect)
101101
return DoGetOffset(settings, screenRect);
102102
}
103103

104-
public static float ComputeTextScaling(Matrix4x4 worldMatrix)
104+
public static float ComputeTextScaling(Matrix4x4 worldMatrix, float pixelsPerPoint)
105105
{
106106
var axisX = new Vector3(worldMatrix.m00, worldMatrix.m10, worldMatrix.m20);
107107
var axisY = new Vector3(worldMatrix.m01, worldMatrix.m11, worldMatrix.m21);
108108
float worldScale = (axisX.magnitude + axisY.magnitude) / 2;
109-
return worldScale * GUIUtility.pixelsPerPoint;
109+
return worldScale * pixelsPerPoint;
110110
}
111111

112112
[FreeFunction(Name = "TextNative::ComputeTextWidth")]

‎Modules/UIElements/VisualElement.cs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,26 @@ Vector3 ITransform.scale
194194
return;
195195
m_Scale = value;
196196
IncrementVersion(VersionChangeType.Transform);
197+
198+
// This will change how we measure text
199+
IncrementVersion(VersionChangeType.Layout);
197200
}
198201
}
199202

203+
internal Vector3 ComputeGlobalScale()
204+
{
205+
Vector3 result = m_Scale;
206+
207+
var ve = this.shadow.parent;
208+
209+
while (ve != null)
210+
{
211+
result.Scale(ve.m_Scale);
212+
ve = ve.shadow.parent;
213+
}
214+
return result;
215+
}
216+
200217
Matrix4x4 ITransform.matrix
201218
{
202219
get { return Matrix4x4.TRS(m_Position, m_Rotation, m_Scale); }

0 commit comments

Comments
 (0)