Skip to content

Commit fb4e4bf

Browse files
author
Unity Technologies
committed
Unity 6000.1.6f1 C# reference source code
1 parent 11117a6 commit fb4e4bf

File tree

14 files changed

+191
-26
lines changed

14 files changed

+191
-26
lines changed

Editor/Mono/Modules/DefaultBuildProfileExtension.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,37 @@ SerializedProperty currentSetting
531531
return false;
532532
}
533533

534+
/// <summary>
535+
/// Helper method for rendering an IMGUI popup over an enum.
536+
/// </summary>
537+
protected bool ShowIMGUIPopupOption<T>
538+
(
539+
GUIContent label,
540+
T[] options,
541+
GUIContent[] optionString,
542+
T currentSetting,
543+
out T returnSettings
544+
) where T : Enum
545+
{
546+
using var vertical = new EditorGUILayout.VerticalScope();
547+
returnSettings = currentSetting;
548+
549+
// Find the index of the currently set value relative to the GUI layout
550+
var selectedIndex = Array.FindIndex(options,
551+
match => match.Equals(currentSetting));
552+
selectedIndex = selectedIndex < 0 ? 0 : selectedIndex;
553+
554+
EditorGUI.BeginChangeCheck();
555+
var newIndex = EditorGUILayout.Popup(label, selectedIndex, optionString);
556+
if (EditorGUI.EndChangeCheck())
557+
{
558+
returnSettings = options[newIndex];
559+
return true;
560+
}
561+
562+
return false;
563+
}
564+
534565
/// <summary>
535566
/// Helper method for rendering an IMGUI popup for GUIContent
536567
/// option values

Editor/Mono/Overlays/OverlayCanvas.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ internal OverlayContainer GetDockZoneContainer(DockZone zone)
282282
List<Overlay> m_Overlays = new List<Overlay>();
283283
List<Overlay> m_TransientOverlays = new();
284284

285+
internal static string k_DefaultPresetName = "Default";
285286
[SerializeField]
286-
string m_LastAppliedPresetName = "Default";
287+
string m_LastAppliedPresetName = k_DefaultPresetName;
287288

288289
[SerializeField]
289290
List<SaveData> m_SaveData = new List<SaveData>();
@@ -713,6 +714,11 @@ internal void CopySaveData(out SaveData[] saveData)
713714
saveData[i] = new SaveData(saveData[i]);
714715
}
715716

717+
internal void SetLastAppliedPresetName(string name)
718+
{
719+
m_LastAppliedPresetName = name;
720+
}
721+
716722
internal void ApplyPreset(IOverlayPreset preset)
717723
{
718724
if (!preset.CanApplyToWindow(containerWindow.GetType()))
@@ -722,7 +728,7 @@ internal void ApplyPreset(IOverlayPreset preset)
722728
return;
723729
}
724730

725-
m_LastAppliedPresetName = preset.name;
731+
SetLastAppliedPresetName(preset.name);
726732
ApplySaveData(preset.saveData);
727733
preset.ApplyCustomData(this);
728734
presetChanged?.Invoke();

Editor/Mono/Overlays/OverlayPresetManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ public static void GenerateMenu(IGenericMenu menu, string pathPrefix, EditorWind
391391
{
392392
menu.AddItem(L10n.Tr($"{pathPrefix}Delete Preset/{preset.name}"), false, () =>
393393
{
394-
DeletePreset(preset);
394+
DeletePreset(preset);
395+
window.overlayCanvas.SetLastAppliedPresetName(OverlayCanvas.k_DefaultPresetName);
396+
window.overlayCanvas.afterOverlaysInitialized.Invoke();
395397
});
396398
}
397399
}
@@ -405,6 +407,7 @@ public static void GenerateMenu(IGenericMenu menu, string pathPrefix, EditorWind
405407
{
406408
RevertPreferencesPresetsToDefault();
407409
ReloadAllPresets();
410+
window.overlayCanvas.ApplyPreset(GetDefaultPreset(window.GetType()));
408411
}
409412
});
410413
}

Editor/Mono/Tools/BuiltinTools.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,23 @@ static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, o
722722

723723
Vector3 sizeBefore = inverseRotation * (origPos - scalePivot);
724724
Vector3 sizeAfter = inverseRotation * (newPos - scalePivot);
725+
726+
// Fix for UUM-102690. If difference is zero, we don't want to scale on that axis
727+
if (scaleFromPivot)
728+
{
729+
Vector3 diff = origPos - scalePivot;
730+
if (Mathf.Approximately(diff.x, 0f))
731+
{
732+
sizeBefore.x = 1f;
733+
sizeAfter.x = 1f;
734+
}
735+
if (Mathf.Approximately(diff.y, 0f))
736+
{
737+
sizeBefore.y = 1f;
738+
sizeAfter.y = 1f;
739+
}
740+
}
741+
725742
if (xHandle != 1)
726743
scale.x = sizeAfter.x / sizeBefore.x;
727744
if (yHandle != 1)
@@ -732,12 +749,6 @@ static Vector3 ResizeHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation, o
732749
float refScale = (xHandle == 1 ? scale.y : scale.x);
733750
scale = Vector3.one * refScale;
734751
}
735-
736-
if (uniformScaling)
737-
{
738-
float refScale = (xHandle == 1 ? scale.y : scale.x);
739-
scale = Vector3.one * refScale;
740-
}
741752
}
742753

743754
if (xHandle == 0)

Modules/BuildProfileEditor/BuildProfileEditor.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEditor.Modules;
77
using UnityEditor.Build.Profile.Elements;
88
using UnityEditor.UIElements;
9+
using UnityEngine;
910
using UnityEngine.UIElements;
1011

1112
namespace UnityEditor.Build.Profile
@@ -391,7 +392,21 @@ void AddScriptingDefineListView(VisualElement root)
391392

392393
var property = serializedObject.FindProperty("m_ScriptingDefines");
393394
m_PlayerScriptingDefinesFoldout.text = TrText.scriptingDefines;
394-
m_PlayerScriptingDefinesFoldout.tooltip = TrText.scriptingDefinesTooltip;
395+
396+
// Add tooltip to the foldout label
397+
var playerScriptingDefinesLabel = m_PlayerScriptingDefinesFoldout.Q<Label>();
398+
Vector2 tooltipPosition = new Vector2();
399+
playerScriptingDefinesLabel.RegisterCallback<MouseOverEvent>(evt =>
400+
{
401+
tooltipPosition = evt.mousePosition;
402+
});
403+
playerScriptingDefinesLabel.RegisterCallback<TooltipEvent>(evt =>
404+
{
405+
evt.tooltip = TrText.scriptingDefinesTooltip;
406+
evt.rect = new Rect(tooltipPosition.x, tooltipPosition.y, evt.rect.width, evt.rect.height);
407+
evt.StopPropagation();
408+
});
409+
395410
var listView = m_PlayerScriptingDefinesFoldout.Q<ListView>("scripting-defines-listview");
396411
var warningHelpbox = m_PlayerScriptingDefinesFoldout.Q<HelpBox>("scripting-defines-warning-help-box");
397412
warningHelpbox.text = TrText.scriptingDefinesWarningHelpbox;

Modules/EditorToolbar/ToolbarElements/OverlayMenu.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,24 @@ public OverlayPresetDropdown(EditorWindow targetWindow)
2121
m_TargetWindow = targetWindow;
2222
createMenuCallback = DropdownUtility.CreateDropdown;
2323
SetValueWithoutNotify(m_TargetWindow.overlayCanvas.lastAppliedPresetName);
24-
24+
RegisterCallback<AttachToPanelEvent>(OnAttachedToPanel);
25+
RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
26+
}
27+
28+
void OnAttachedToPanel(AttachToPanelEvent evt)
29+
{
30+
m_TargetWindow.overlayCanvas.afterOverlaysInitialized += RefreshPresetDisplayValue;
31+
}
32+
33+
void OnDetachFromPanel(DetachFromPanelEvent evt)
34+
{
35+
if (m_TargetWindow is not null && m_TargetWindow.overlayCanvas is not null)
36+
m_TargetWindow.overlayCanvas.afterOverlaysInitialized -= RefreshPresetDisplayValue;
37+
}
38+
39+
void RefreshPresetDisplayValue()
40+
{
41+
SetValueWithoutNotify(GetValueToDisplay());
2542
}
2643

2744
internal override void AddMenuItems(IGenericMenu menu)
@@ -220,6 +237,7 @@ public override VisualElement CreatePanelContent()
220237
{
221238
VisualElement content = new VisualElement();
222239
content.style.minWidth = 160;
240+
content.style.maxWidth = 300;
223241
m_Toolbar = null;
224242

225243
if (isPopup)

Modules/TextCoreFontEngine/Managed/FontEngine.bindings.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public enum FontEngineError
114114
[UsedByNativeCode]
115115
public enum GlyphRenderMode
116116
{
117+
DEFAULT = 0x0, // Selects either SDFAA or COLOR based on the font face.
118+
117119
SMOOTH_HINTED = GlyphRasterModes.RASTER_MODE_HINTED | GlyphRasterModes.RASTER_MODE_8BIT | GlyphRasterModes.RASTER_MODE_BITMAP | GlyphRasterModes.RASTER_MODE_1X,
118120
SMOOTH = GlyphRasterModes.RASTER_MODE_NO_HINTING | GlyphRasterModes.RASTER_MODE_8BIT | GlyphRasterModes.RASTER_MODE_BITMAP | GlyphRasterModes.RASTER_MODE_1X,
119121

@@ -132,6 +134,23 @@ public enum GlyphRenderMode
132134
SDFAA = GlyphRasterModes.RASTER_MODE_NO_HINTING | GlyphRasterModes.RASTER_MODE_8BIT | GlyphRasterModes.RASTER_MODE_SDFAA | GlyphRasterModes.RASTER_MODE_1X,
133135
}
134136

137+
// This enum needs to match GlyphRenderMode, except for DEFAULT being removed.
138+
internal enum GlyphRenderModeUI
139+
{
140+
SMOOTH_HINTED = GlyphRenderMode.SMOOTH_HINTED,
141+
SMOOTH = GlyphRenderMode.SMOOTH,
142+
COLOR_HINTED = GlyphRenderMode.COLOR_HINTED,
143+
COLOR = GlyphRenderMode.COLOR,
144+
RASTER_HINTED = GlyphRenderMode.RASTER_HINTED,
145+
RASTER = GlyphRenderMode.RASTER,
146+
SDF = GlyphRenderMode.SDF,
147+
SDF8 = GlyphRenderMode.SDF8,
148+
SDF16 = GlyphRenderMode.SDF16,
149+
SDF32 = GlyphRenderMode.SDF32,
150+
SDFAA_HINTED = GlyphRenderMode.SDFAA_HINTED,
151+
SDFAA = GlyphRenderMode.SDFAA
152+
}
153+
135154
/// <summary>
136155
/// The modes available when packing glyphs into an atlas texture.
137156
/// </summary>
@@ -488,6 +507,9 @@ public static string[] GetSystemFontNames()
488507
[NativeMethod(Name = "TextCore::FontEngine::GetSystemFontReferences", IsThreadSafe = true, IsFreeFunction = true)]
489508
internal static extern FontReference[] GetSystemFontReferences();
490509

510+
[VisibleToOtherModules("UnityEngine.TextCoreTextEngineModule")]
511+
internal static extern bool IsColorFontFace();
512+
491513

492514
/// <summary>
493515
/// Try finding and returning a reference to a system font for the given family name and style.

Modules/TextCoreTextEngine/Managed/TextAssets/FontAsset.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ public static FontAsset CreateFontAsset(string familyName, string styleName, int
617617
internal static FontAsset? CreateFontAssetInternal(string familyName, string styleName, int pointSize = 90)
618618
{
619619
if (FontEngine.TryGetSystemFontReference(familyName, styleName, out FontReference fontRef))
620-
return CreateFontAsset(fontRef.filePath, fontRef.faceIndex, pointSize, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.DynamicOS, true);
620+
return CreateFontAsset(fontRef.filePath, fontRef.faceIndex, pointSize, 9, GlyphRenderMode.DEFAULT, 1024, 1024, AtlasPopulationMode.DynamicOS, true);
621621
return null;
622622
}
623623

@@ -683,7 +683,7 @@ static FontAsset CreateFontAssetFromFamilyName(string familyName, int pointSize
683683
FontAsset fontAsset = null;
684684

685685
if (FontEngine.TryGetSystemFontReference(familyName, null, out FontReference fontRef))
686-
fontAsset = CreateFontAsset(fontRef.filePath, fontRef.faceIndex, pointSize, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.DynamicOS, true);
686+
fontAsset = CreateFontAsset(fontRef.filePath, fontRef.faceIndex, pointSize, 9, GlyphRenderMode.DEFAULT, 1024, 1024, AtlasPopulationMode.DynamicOS, true);
687687

688688
if (fontAsset == null)
689689
return null;
@@ -723,7 +723,8 @@ static FontAsset CreateFontAsset(string fontFilePath, int faceIndex, int samplin
723723
var fontAsset = CreateFontAssetInstance(null, atlasPadding, renderMode, atlasWidth, atlasHeight, atlasPopulationMode, enableMultiAtlasSupport);
724724

725725
// Set font file path
726-
fontAsset.m_SourceFontFilePath = fontFilePath;
726+
if (fontAsset)
727+
fontAsset.m_SourceFontFilePath = fontFilePath;
727728

728729
return fontAsset;
729730
}
@@ -795,6 +796,11 @@ static FontAsset CreateFontAssetInstance(Font font, int atlasPadding, GlyphRende
795796
fontAsset.m_Version = "1.1.0";
796797
fontAsset.faceInfo = FontEngine.GetFaceInfo();
797798

799+
if (renderMode == GlyphRenderMode.DEFAULT)
800+
{
801+
renderMode = FontEngine.IsColorFontFace() ? GlyphRenderMode.COLOR : GlyphRenderMode.SDFAA;
802+
}
803+
798804
if (atlasPopulationMode == AtlasPopulationMode.Dynamic && font != null)
799805
{
800806
fontAsset.sourceFontFile = font;
@@ -829,9 +835,19 @@ static FontAsset CreateFontAssetInstance(Font font, int atlasPadding, GlyphRende
829835
packingModifier = 0;
830836

831837
if (texFormat == TextureFormat.Alpha8)
832-
tmpMaterial = new Material(TextShaderUtilities.ShaderRef_MobileBitmap);
838+
{
839+
if (TextShaderUtilities.ShaderRef_MobileBitmap)
840+
tmpMaterial = new Material(TextShaderUtilities.ShaderRef_MobileBitmap);
841+
else
842+
return null;
843+
}
833844
else
834-
tmpMaterial = new Material(TextShaderUtilities.ShaderRef_Sprite);
845+
{
846+
if (TextShaderUtilities.ShaderRef_Sprite)
847+
tmpMaterial = new Material(TextShaderUtilities.ShaderRef_Sprite);
848+
else
849+
return null;
850+
}
835851

836852
//tmp_material.name = texture.name + " Material";
837853
tmpMaterial.SetTexture(TextShaderUtilities.ID_MainTex, texture);

Modules/TextCoreTextEngine/Managed/TextAssets/FontAsset/FontAssetFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ static void ProcessFallbackFonts(FontAsset resultFontAsset, FontAsset baseFontAs
104104
return null;
105105

106106
FontAsset? fontAsset = null;
107-
fontAsset = FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.SDFAA, 1024, 1024, AtlasPopulationMode.Dynamic, true);
107+
108+
fontAsset = FontAsset.CreateFontAsset(font, 90, 9, GlyphRenderMode.DEFAULT, 1024, 1024, AtlasPopulationMode.Dynamic, true);
108109

109110
if (fontAsset != null)
110111
SetupFontAssetSettings(fontAsset);

Modules/TextCoreTextEngine/Managed/TextShaderUtilities.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ public static class TextShaderUtilities
139139
private static float m_clamp = 1.0f;
140140
public static bool isInitialized = false;
141141

142+
[VisibleToOtherModules("UnityEngine.UIElementsModule")]
143+
internal static readonly string k_SDFText = "Hidden/TextCore/Distance Field SSD";
144+
[VisibleToOtherModules("UnityEngine.UIElementsModule")]
145+
internal static readonly string k_BitmapText = "Hidden/Internal-GUITextureClipText";
146+
[VisibleToOtherModules("UnityEngine.UIElementsModule")]
147+
internal static readonly string k_SpriteText = "Hidden/TextCore/Sprite";
148+
142149

143150
/// <summary>
144151
/// Returns a reference to the mobile distance field shader.
@@ -149,7 +156,7 @@ internal static Shader ShaderRef_MobileSDF
149156
get
150157
{
151158
if (((System.Object)k_ShaderRef_MobileSDF) == null)
152-
k_ShaderRef_MobileSDF = Shader.Find("Hidden/TextCore/Distance Field SSD");
159+
k_ShaderRef_MobileSDF = Shader.Find(k_SDFText);
153160

154161
return k_ShaderRef_MobileSDF;
155162
}
@@ -164,7 +171,7 @@ internal static Shader ShaderRef_MobileBitmap
164171
get
165172
{
166173
if (k_ShaderRef_MobileBitmap == null)
167-
k_ShaderRef_MobileBitmap = Shader.Find("Hidden/Internal-GUITextureClipText");
174+
k_ShaderRef_MobileBitmap = Shader.Find(k_BitmapText);
168175

169176
return k_ShaderRef_MobileBitmap;
170177
}
@@ -181,7 +188,7 @@ internal static Shader ShaderRef_Sprite
181188
k_ShaderRef_Sprite = Shader.Find("Text/Sprite");
182189

183190
if (k_ShaderRef_Sprite == null)
184-
k_ShaderRef_Sprite = Shader.Find("Hidden/TextCore/Sprite");
191+
k_ShaderRef_Sprite = Shader.Find(k_SpriteText);
185192
}
186193
return k_ShaderRef_Sprite;
187194
}

0 commit comments

Comments
 (0)