Skip to content

Commit a9c1652

Browse files
author
Unity Technologies
committed
Unity 6000.0.21f1 C# reference source code
1 parent 23bb6a2 commit a9c1652

File tree

25 files changed

+215
-146
lines changed

25 files changed

+215
-146
lines changed

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
[assembly: InternalsVisibleTo("Unity.Testing.VisualEffectGraph.EditorTests")]
143143
[assembly: InternalsVisibleTo("Unity.VisualEffectGraph.EditorTests")]
144144
[assembly: InternalsVisibleTo("Unity.RenderPipelines.Multiple_SRP.EditorTests")]
145+
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor")]
145146

146147
[assembly: InternalsVisibleTo("Unity.SceneTemplate.Editor")]
147148
[assembly: InternalsVisibleTo("com.unity.purchasing.udp.Editor")]

Editor/Mono/FileUtil.bindings.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,12 @@ public static void ReplaceFile(string src, string dst)
151151
public static void ReplaceDirectory(string src, string dst)
152152
{
153153
if (Directory.Exists(dst))
154-
FileUtil.DeleteFileOrDirectory(dst);
155-
154+
{
155+
bool succesfullyDeletedDirectory = FileUtil.DeleteFileOrDirectory(dst);
156+
if (succesfullyDeletedDirectory == false)
157+
throw new System.IO.IOException(string.Format(
158+
"Failed to delete directory '{0}'.", dst));
159+
}
156160
FileUtil.CopyFileOrDirectory(src, dst);
157161
}
158162

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,13 +2465,13 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte
24652465
using (new EditorGUI.DisabledScope(EditorApplication.isPlaying || Lightmapping.isRunning))
24662466
{
24672467
EditorGUI.BeginChangeCheck();
2468-
NormalMapEncoding oldEncoding = PlayerSettings.GetNormalMapEncoding(platform.namedBuildTarget);
2468+
var oldEncoding = PlayerSettings.GetNormalMapEncoding_Internal(m_CurrentTarget, platform.name);
24692469
NormalMapEncoding[] encodingValues = { NormalMapEncoding.XYZ, NormalMapEncoding.DXT5nm };
2470-
NormalMapEncoding newEncoding = BuildEnumPopup(SettingsContent.normalMapEncodingLabel, oldEncoding, encodingValues, SettingsContent.normalMapEncodingNames);
2470+
var newEncoding = BuildEnumPopup(SettingsContent.normalMapEncodingLabel, oldEncoding, encodingValues, SettingsContent.normalMapEncodingNames);
24712471
if (EditorGUI.EndChangeCheck() && newEncoding != oldEncoding)
24722472
{
2473-
PlayerSettings.SetNormalMapEncoding(platform.namedBuildTarget, newEncoding);
2474-
serializedObject.ApplyModifiedProperties();
2473+
PlayerSettings.SetNormalMapEncoding_Internal(m_CurrentTarget, platform.name, newEncoding);
2474+
m_OnTrackSerializedObjectValueChanged?.Invoke(serializedObject);
24752475
GUIUtility.ExitGUI();
24762476
}
24772477
}

Editor/Mono/PlayerSettings.bindings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,12 @@ internal static extern bool iosCopyPluginsCodeInsteadOfSymlink
18251825
[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
18261826
internal static extern void SetShaderChunkCountForPlatform_Internal(PlayerSettings instance, BuildTarget buildTarget, int chunkCount);
18271827

1828+
[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
1829+
internal static extern NormalMapEncoding GetNormalMapEncoding_Internal(PlayerSettings instance, string platform);
1830+
1831+
[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
1832+
internal static extern void SetNormalMapEncoding_Internal(PlayerSettings instance, string platform, NormalMapEncoding encoding);
1833+
18281834
/*
18291835
* Internal non-static getter/setters referenced when reading/writing to non-active player settings object.
18301836
*/

Editor/Mono/Tools/EditorToolManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ sealed class EditorToolManager : ScriptableSingleton<EditorToolManager>
2828
[SerializeField]
2929
Tool m_LastBuiltinTool = Tool.Move;
3030

31-
Type m_LastCustomContext;
32-
3331
[SerializeField]
3432
EditorTool m_LastCustomTool;
3533

@@ -100,9 +98,6 @@ internal static EditorToolContext activeToolContext
10098
if (prev != null)
10199
{
102100
prev.Deactivate();
103-
104-
if (!(prev is GameObjectToolContext))
105-
instance.m_LastCustomContext = prev.GetType();
106101
}
107102

108103
ToolManager.ActiveContextWillChange();
@@ -495,8 +490,6 @@ internal EditorTool lastManipulationTool
495490

496491
internal static EditorTool lastCustomTool => instance.m_LastCustomTool;
497492

498-
internal static Type lastCustomContext => instance.m_LastCustomContext;
499-
500493
public static void RestorePreviousPersistentTool()
501494
{
502495
activeTool = instance.lastManipulationTool;

Editor/Mono/Tools/ToolManager.cs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -163,45 +163,30 @@ internal static IEnumerable<Type> allContextsExceptGameObject
163163
}
164164
}
165165

166-
internal static Type GetLastContextType()
167-
{
168-
var lastContext = EditorToolManager.lastCustomContext;
169-
if (lastContext != null && lastContext != typeof(GameObjectToolContext))
170-
return lastContext;
171-
172-
return allContextsExceptGameObject.FirstOrDefault();
173-
}
174-
175166
[Shortcut("Tools/Enter GameObject Mode", typeof(ToolShortcutContext))]
176167
internal static void ExitToolContext()
177168
{
178169
SetActiveContext<GameObjectToolContext>();
179170
}
180171

181-
[Shortcut("Tools/Cycle Tool Modes", typeof(ToolShortcutContext))]
172+
[Shortcut("Tools/Cycle Tool Modes", typeof(ToolShortcutContext), KeyCode.G)]
182173
internal static void CycleToolContexts()
183174
{
184175
if (EditorToolUtility.toolContextsInProject < 2)
185176
return;
186177

187178
var active = EditorToolManager.activeToolContext;
188-
189-
if (active is GameObjectToolContext && EditorToolManager.lastCustomContext != null)
190-
{
191-
var instance = allContextsExceptGameObject.FirstOrDefault(x => x == EditorToolManager.lastCustomContext);
192-
193-
if (instance != null)
194-
{
195-
SetActiveContext(instance);
196-
return;
197-
}
198-
}
199-
200179
using var all = allContextsExceptGameObject.GetEnumerator();
201180

202181
if (!all.MoveNext())
203182
return;
204183

184+
if (active is GameObjectToolContext)
185+
{
186+
SetActiveContext(all.Current);
187+
return;
188+
}
189+
205190
// Select the next available context after the active
206191
while (all.Current != active.GetType())
207192
{
@@ -219,7 +204,7 @@ internal static void CycleToolContexts()
219204
if (all.MoveNext())
220205
SetActiveContext(all.Current);
221206
else
222-
SetActiveContext(allContextsExceptGameObject.First());
207+
SetActiveContext(typeof(GameObjectToolContext));
223208
}
224209
}
225210
}

Modules/EditorToolbar/Controls/ToolContextButton.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ void RefreshActiveContext()
105105
{
106106
if (isGOToolContext)
107107
{
108-
var lastContextType = ToolManager.GetLastContextType();
109-
// JIRA: UUM-16237. Use the content of the last context only if the current selection is associated with the same type of context.
110-
if (ToolManager.allContextsExceptGameObject.Contains(lastContextType))
111-
activeContextType = lastContextType;
112-
else
113-
activeContextType = ToolManager.allContextsExceptGameObject.FirstOrDefault();
108+
activeContextType = ToolManager.allContextsExceptGameObject.FirstOrDefault();
114109
}
115110
else
116111
activeContextType = ToolManager.activeContextType;

Modules/GraphViewEditor/Elements/ElementResizer.cs

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void OnMouseDown(MouseDownEvent e)
7979
target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
8080
e.StopPropagation();
8181
target.CaptureMouse();
82-
m_StartMouse = resizedBase.WorldToLocal(e.mousePosition);
82+
m_StartMouse = e.mousePosition;
8383
m_StartSize = new Vector2(resizedTarget.resolvedStyle.width, resizedTarget.resolvedStyle.height);
8484
m_StartPosition = new Vector2(resizedTarget.resolvedStyle.left, resizedTarget.resolvedStyle.top);
8585

@@ -104,8 +104,10 @@ void OnMouseMove(MouseMoveEvent e)
104104

105105
VisualElement resizedTarget = resizedElement.parent;
106106
VisualElement resizedBase = resizedTarget.parent;
107+
var validResizeBase = resizedBase;
108+
FindValidBaseElement(ref validResizeBase);
107109

108-
Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition);
110+
Vector2 mousePos = e.mousePosition;
109111
if (!m_DragStarted)
110112
{
111113
if (resizedTarget is IResizable)
@@ -149,27 +151,48 @@ void OnMouseMove(MouseMoveEvent e)
149151
{
150152
if ((direction & ResizerDirection.Right) != 0)
151153
{
152-
resizedTarget.style.width = Mathf.Clamp(m_StartSize.x + mousePos.x - m_StartMouse.x, m_MinSize.x, Mathf.Min(m_MaxSize.x, resizedBase.layout.xMax - resizedTarget.layout.xMin));
154+
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
155+
var localZero = resizedBase.WorldToLocal(worldZero);
156+
var localWidth = validResizeBase.layout.width / resizedTarget.worldTransform.lossyScale.x;
157+
var newWidth = Mathf.Min(m_StartSize.x + (mousePos.x - m_StartMouse.x) / resizedTarget.worldTransform.lossyScale.x, this.m_MaxSize.x);
158+
var newRight = Mathf.Clamp(resizedTarget.layout.xMin + newWidth, resizedTarget.layout.xMin + m_MinSize.x, localZero.x + localWidth);
159+
resizedTarget.style.width = newRight - resizedTarget.layout.xMin;
153160
}
154161
else if ((direction & ResizerDirection.Left) != 0)
155162
{
156-
float delta = mousePos.x - m_StartMouse.x;
157-
float previousLeft = resizedTarget.style.left.value.value;
158-
159-
resizedTarget.style.left = Mathf.Clamp(delta + m_StartPosition.x, 0, resizedTarget.layout.xMax - m_MinSize.x);
160-
resizedTarget.style.width = resizedTarget.resolvedStyle.width + previousLeft - resizedTarget.style.left.value.value;
163+
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
164+
var localZero = resizedBase.WorldToLocal(worldZero);
165+
var delta = (mousePos.x - m_StartMouse.x) / resizedTarget.worldTransform.lossyScale.x;
166+
var newLeft = Mathf.Clamp(m_StartPosition.x + delta, localZero.x, localZero.x + validResizeBase.layout.width);
167+
var newWidth = resizedTarget.layout.xMax - newLeft;
168+
if (newWidth >= m_MinSize.x && newWidth <= m_MaxSize.x)
169+
{
170+
resizedTarget.style.left = newLeft;
171+
resizedTarget.style.width = newWidth;
172+
}
161173
}
162174
if ((direction & ResizerDirection.Bottom) != 0)
163175
{
164-
resizedTarget.style.height = Mathf.Min(m_MaxSize.y, Mathf.Max(m_MinSize.y, m_StartSize.y + mousePos.y - m_StartMouse.y));
176+
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
177+
var localZero = resizedBase.WorldToLocal(worldZero);
178+
var localHeight = validResizeBase.layout.height / resizedTarget.worldTransform.lossyScale.x;
179+
var newHeight = m_StartSize.y + (mousePos.y - m_StartMouse.y) / resizedTarget.worldTransform.lossyScale.x;
180+
var newBottom = Mathf.Clamp(resizedTarget.layout.yMin + newHeight, resizedTarget.layout.yMin + m_MinSize.y, localZero.y + localHeight);
181+
resizedTarget.style.height = newBottom - resizedTarget.layout.yMin;
165182
}
166183
else if ((direction & ResizerDirection.Top) != 0)
167184
{
168-
float delta = mousePos.y - m_StartMouse.y;
169-
float previousTop = resizedTarget.style.top.value.value;
170-
171-
resizedTarget.style.top = Mathf.Clamp(delta + m_StartPosition.y, 0, m_StartSize.y - 1);
172-
resizedTarget.style.height = resizedTarget.resolvedStyle.height + previousTop - resizedTarget.style.top.value.value;
185+
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
186+
var localZero = resizedBase.WorldToLocal(worldZero);
187+
var localHeight = validResizeBase.layout.height / resizedTarget.worldTransform.lossyScale.x;
188+
var delta = (mousePos.y - m_StartMouse.y) / resizedTarget.worldTransform.lossyScale.x;
189+
var newTop = Mathf.Clamp(m_StartPosition.y + delta, localZero.y, localZero.y + localHeight);
190+
var newHeight = resizedTarget.layout.yMax - newTop;
191+
if (newHeight >= m_MinSize.y && newHeight <= m_MaxSize.y)
192+
{
193+
resizedTarget.style.top = newTop;
194+
resizedTarget.style.height = newHeight;
195+
}
173196
}
174197
}
175198
e.StopPropagation();
@@ -195,5 +218,20 @@ void OnMouseUp(MouseUpEvent e)
195218
m_Active = false;
196219
}
197220
}
221+
222+
void FindValidBaseElement(ref VisualElement resizedBase)
223+
{
224+
// For unknown reason, layers have zero height, which completely break resizing algorithm
225+
// So we look for a parent with proper dimension
226+
while (resizedBase.layout.width == 0 || resizedBase.layout.height == 0)
227+
{
228+
if (resizedBase.parent == null)
229+
{
230+
break;
231+
}
232+
233+
resizedBase = resizedBase.parent;
234+
}
235+
}
198236
}
199237
}

Modules/IMGUI/TextEditingUtilities.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void InitKeyActions()
341341
}
342342
}
343343

344-
345344
// Deletes previous text on the line
346345
public bool DeleteLineBack()
347346
{
@@ -353,6 +352,18 @@ public bool DeleteLineBack()
353352
return true;
354353
}
355354

355+
if (textHandle.useAdvancedText)
356+
{
357+
var start = textHandle.GetFirstCharacterIndexOnLine(cursorIndex);
358+
if (start != cursorIndex)
359+
{
360+
text = text.Remove(start, stringCursorIndex - start);
361+
cursorIndex = selectIndex = start;
362+
return true;
363+
}
364+
return false;
365+
}
366+
356367
var currentLineInfo = textHandle.GetLineInfoFromCharacterIndex(cursorIndex);
357368
var startIndex = currentLineInfo.firstCharacterIndex;
358369
var stringStartIndex = textHandle.GetCorrespondingStringIndex(startIndex);
@@ -422,7 +433,11 @@ public bool Delete()
422433
}
423434
else if (stringCursorIndex < text.Length)
424435
{
425-
var count = textHandle.textInfo.textElementInfo[cursorIndex].stringLength;
436+
int count;
437+
if (textHandle.useAdvancedText)
438+
count = textHandle.NextCodePointIndex(cursorIndex) - cursorIndex;
439+
else
440+
count = textHandle.textInfo.textElementInfo[cursorIndex].stringLength;
426441
text = text.Remove(stringCursorIndex, count);
427442
return true;
428443
}
@@ -442,10 +457,15 @@ public bool Backspace()
442457
else if (cursorIndex > 0)
443458
{
444459
var startIndex = m_TextSelectingUtility.PreviousCodePointIndex(cursorIndex);
445-
var count = textHandle.textInfo.textElementInfo[cursorIndex - 1].stringLength;
460+
int count;
461+
if (textHandle.useAdvancedText)
462+
count = (char.IsSurrogate(text[cursorIndex - 1]) ? 2 : 1);
463+
else
464+
count = textHandle.textInfo.textElementInfo[cursorIndex - 1].stringLength;
465+
446466
text = text.Remove(stringCursorIndex - count, count);
447-
cursorIndex = startIndex;
448-
selectIndex = startIndex;
467+
cursorIndex = textHandle.useAdvancedText ? Math.Max(0, cursorIndex - count) : startIndex;
468+
selectIndex = textHandle.useAdvancedText ? Math.Max(0, selectIndex - count) : startIndex;
449469
m_TextSelectingUtility.ClearCursorPos();
450470
return true;
451471
}
@@ -479,7 +499,8 @@ public void ReplaceSelection(string replace)
479499
DeleteSelection();
480500
text = text.Insert(stringCursorIndex, replace);
481501

482-
var newIndex = cursorIndexNoValidation + new StringInfo(replace).LengthInTextElements;
502+
int length = textHandle.useAdvancedText ? replace.Length : new StringInfo(replace).LengthInTextElements;
503+
var newIndex = cursorIndexNoValidation + length;
483504
cursorIndexNoValidation = newIndex;
484505
selectIndexNoValidation = newIndex;
485506
m_TextSelectingUtility.ClearCursorPos();
@@ -538,6 +559,7 @@ public bool Cut()
538559
m_TextSelectingUtility.Copy();
539560
return DeleteSelection();
540561
}
562+
541563
public bool Paste()
542564
{
543565
RestoreCursorState();

Modules/PackageManagerUI/Editor/Extensions/ExtendableToolbarMenu.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,8 @@ public void Remove(MenuDropdownItem item)
9292

9393
public void ShowInputDropdown(InputDropdownArgs args)
9494
{
95-
var rect = GUIUtility.GUIToScreenRect(worldBound);
96-
97-
// GUIToScreenRect calculates screen space coordinates in relation to contextual menu
98-
// which is the last active view. Since we know the exact offset of contextual menu in
99-
// relation to package manager we can compensate this by subtracting contextual menu origin.
100-
rect.y -= worldBound.yMax;
101-
102-
var dropdown = new GenericInputDropdown(m_ResourceLoader, PackageManagerWindow.instance, args) { position = rect };
95+
var position = PackageManagerWindow.instance.CalculateDropdownPosition(this);
96+
var dropdown = new GenericInputDropdown(m_ResourceLoader, PackageManagerWindow.instance, args) { position = position };
10397
DropdownContainer.ShowDropdown(dropdown);
10498
}
10599
}

Modules/PackageManagerUI/Editor/UI/DropdownContainer.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,5 @@ public static void ShowDropdown(DropdownContent content)
4040
instance.ShowAsDropDown(content.position, content.windowSize);
4141
content.OnDropdownShown();
4242
}
43-
44-
static void ShowDropdownContainer()
45-
{
46-
instance.ShowAsDropDown(instance.m_Content.position, instance.m_Content.windowSize);
47-
instance.m_Content.OnDropdownShown();
48-
49-
// Make sure delayCall has no chance to execute twice or more for the same menu. We had some issues like this in UI Elements tests suite
50-
EditorApplication.delayCall -= ShowDropdownContainer;
51-
}
5243
}
5344
}

0 commit comments

Comments
 (0)