Skip to content

Commit

Permalink
Unity 6000.0.21f1 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Sep 24, 2024
1 parent 23bb6a2 commit a9c1652
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 146 deletions.
1 change: 1 addition & 0 deletions Editor/Mono/AssemblyInfo/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
[assembly: InternalsVisibleTo("Unity.Testing.VisualEffectGraph.EditorTests")]
[assembly: InternalsVisibleTo("Unity.VisualEffectGraph.EditorTests")]
[assembly: InternalsVisibleTo("Unity.RenderPipelines.Multiple_SRP.EditorTests")]
[assembly: InternalsVisibleTo("Unity.ShaderGraph.Editor")]

[assembly: InternalsVisibleTo("Unity.SceneTemplate.Editor")]
[assembly: InternalsVisibleTo("com.unity.purchasing.udp.Editor")]
Expand Down
8 changes: 6 additions & 2 deletions Editor/Mono/FileUtil.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ public static void ReplaceFile(string src, string dst)
public static void ReplaceDirectory(string src, string dst)
{
if (Directory.Exists(dst))
FileUtil.DeleteFileOrDirectory(dst);

{
bool succesfullyDeletedDirectory = FileUtil.DeleteFileOrDirectory(dst);
if (succesfullyDeletedDirectory == false)
throw new System.IO.IOException(string.Format(
"Failed to delete directory '{0}'.", dst));
}
FileUtil.CopyFileOrDirectory(src, dst);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2465,13 +2465,13 @@ private void OtherSectionRenderingGUI(BuildPlatform platform, ISettingEditorExte
using (new EditorGUI.DisabledScope(EditorApplication.isPlaying || Lightmapping.isRunning))
{
EditorGUI.BeginChangeCheck();
NormalMapEncoding oldEncoding = PlayerSettings.GetNormalMapEncoding(platform.namedBuildTarget);
var oldEncoding = PlayerSettings.GetNormalMapEncoding_Internal(m_CurrentTarget, platform.name);
NormalMapEncoding[] encodingValues = { NormalMapEncoding.XYZ, NormalMapEncoding.DXT5nm };
NormalMapEncoding newEncoding = BuildEnumPopup(SettingsContent.normalMapEncodingLabel, oldEncoding, encodingValues, SettingsContent.normalMapEncodingNames);
var newEncoding = BuildEnumPopup(SettingsContent.normalMapEncodingLabel, oldEncoding, encodingValues, SettingsContent.normalMapEncodingNames);
if (EditorGUI.EndChangeCheck() && newEncoding != oldEncoding)
{
PlayerSettings.SetNormalMapEncoding(platform.namedBuildTarget, newEncoding);
serializedObject.ApplyModifiedProperties();
PlayerSettings.SetNormalMapEncoding_Internal(m_CurrentTarget, platform.name, newEncoding);
m_OnTrackSerializedObjectValueChanged?.Invoke(serializedObject);
GUIUtility.ExitGUI();
}
}
Expand Down
6 changes: 6 additions & 0 deletions Editor/Mono/PlayerSettings.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,12 @@ internal static extern bool iosCopyPluginsCodeInsteadOfSymlink
[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
internal static extern void SetShaderChunkCountForPlatform_Internal(PlayerSettings instance, BuildTarget buildTarget, int chunkCount);

[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
internal static extern NormalMapEncoding GetNormalMapEncoding_Internal(PlayerSettings instance, string platform);

[StaticAccessor("PlayerSettingsBindings", StaticAccessorType.DoubleColon)]
internal static extern void SetNormalMapEncoding_Internal(PlayerSettings instance, string platform, NormalMapEncoding encoding);

/*
* Internal non-static getter/setters referenced when reading/writing to non-active player settings object.
*/
Expand Down
7 changes: 0 additions & 7 deletions Editor/Mono/Tools/EditorToolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ sealed class EditorToolManager : ScriptableSingleton<EditorToolManager>
[SerializeField]
Tool m_LastBuiltinTool = Tool.Move;

Type m_LastCustomContext;

[SerializeField]
EditorTool m_LastCustomTool;

Expand Down Expand Up @@ -100,9 +98,6 @@ internal static EditorToolContext activeToolContext
if (prev != null)
{
prev.Deactivate();

if (!(prev is GameObjectToolContext))
instance.m_LastCustomContext = prev.GetType();
}

ToolManager.ActiveContextWillChange();
Expand Down Expand Up @@ -495,8 +490,6 @@ internal EditorTool lastManipulationTool

internal static EditorTool lastCustomTool => instance.m_LastCustomTool;

internal static Type lastCustomContext => instance.m_LastCustomContext;

public static void RestorePreviousPersistentTool()
{
activeTool = instance.lastManipulationTool;
Expand Down
31 changes: 8 additions & 23 deletions Editor/Mono/Tools/ToolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,45 +163,30 @@ internal static IEnumerable<Type> allContextsExceptGameObject
}
}

internal static Type GetLastContextType()
{
var lastContext = EditorToolManager.lastCustomContext;
if (lastContext != null && lastContext != typeof(GameObjectToolContext))
return lastContext;

return allContextsExceptGameObject.FirstOrDefault();
}

[Shortcut("Tools/Enter GameObject Mode", typeof(ToolShortcutContext))]
internal static void ExitToolContext()
{
SetActiveContext<GameObjectToolContext>();
}

[Shortcut("Tools/Cycle Tool Modes", typeof(ToolShortcutContext))]
[Shortcut("Tools/Cycle Tool Modes", typeof(ToolShortcutContext), KeyCode.G)]
internal static void CycleToolContexts()
{
if (EditorToolUtility.toolContextsInProject < 2)
return;

var active = EditorToolManager.activeToolContext;

if (active is GameObjectToolContext && EditorToolManager.lastCustomContext != null)
{
var instance = allContextsExceptGameObject.FirstOrDefault(x => x == EditorToolManager.lastCustomContext);

if (instance != null)
{
SetActiveContext(instance);
return;
}
}

using var all = allContextsExceptGameObject.GetEnumerator();

if (!all.MoveNext())
return;

if (active is GameObjectToolContext)
{
SetActiveContext(all.Current);
return;
}

// Select the next available context after the active
while (all.Current != active.GetType())
{
Expand All @@ -219,7 +204,7 @@ internal static void CycleToolContexts()
if (all.MoveNext())
SetActiveContext(all.Current);
else
SetActiveContext(allContextsExceptGameObject.First());
SetActiveContext(typeof(GameObjectToolContext));
}
}
}
7 changes: 1 addition & 6 deletions Modules/EditorToolbar/Controls/ToolContextButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,7 @@ void RefreshActiveContext()
{
if (isGOToolContext)
{
var lastContextType = ToolManager.GetLastContextType();
// JIRA: UUM-16237. Use the content of the last context only if the current selection is associated with the same type of context.
if (ToolManager.allContextsExceptGameObject.Contains(lastContextType))
activeContextType = lastContextType;
else
activeContextType = ToolManager.allContextsExceptGameObject.FirstOrDefault();
activeContextType = ToolManager.allContextsExceptGameObject.FirstOrDefault();
}
else
activeContextType = ToolManager.activeContextType;
Expand Down
66 changes: 52 additions & 14 deletions Modules/GraphViewEditor/Elements/ElementResizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void OnMouseDown(MouseDownEvent e)
target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
e.StopPropagation();
target.CaptureMouse();
m_StartMouse = resizedBase.WorldToLocal(e.mousePosition);
m_StartMouse = e.mousePosition;
m_StartSize = new Vector2(resizedTarget.resolvedStyle.width, resizedTarget.resolvedStyle.height);
m_StartPosition = new Vector2(resizedTarget.resolvedStyle.left, resizedTarget.resolvedStyle.top);

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

VisualElement resizedTarget = resizedElement.parent;
VisualElement resizedBase = resizedTarget.parent;
var validResizeBase = resizedBase;
FindValidBaseElement(ref validResizeBase);

Vector2 mousePos = resizedBase.WorldToLocal(e.mousePosition);
Vector2 mousePos = e.mousePosition;
if (!m_DragStarted)
{
if (resizedTarget is IResizable)
Expand Down Expand Up @@ -149,27 +151,48 @@ void OnMouseMove(MouseMoveEvent e)
{
if ((direction & ResizerDirection.Right) != 0)
{
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));
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
var localZero = resizedBase.WorldToLocal(worldZero);
var localWidth = validResizeBase.layout.width / resizedTarget.worldTransform.lossyScale.x;
var newWidth = Mathf.Min(m_StartSize.x + (mousePos.x - m_StartMouse.x) / resizedTarget.worldTransform.lossyScale.x, this.m_MaxSize.x);
var newRight = Mathf.Clamp(resizedTarget.layout.xMin + newWidth, resizedTarget.layout.xMin + m_MinSize.x, localZero.x + localWidth);
resizedTarget.style.width = newRight - resizedTarget.layout.xMin;
}
else if ((direction & ResizerDirection.Left) != 0)
{
float delta = mousePos.x - m_StartMouse.x;
float previousLeft = resizedTarget.style.left.value.value;

resizedTarget.style.left = Mathf.Clamp(delta + m_StartPosition.x, 0, resizedTarget.layout.xMax - m_MinSize.x);
resizedTarget.style.width = resizedTarget.resolvedStyle.width + previousLeft - resizedTarget.style.left.value.value;
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
var localZero = resizedBase.WorldToLocal(worldZero);
var delta = (mousePos.x - m_StartMouse.x) / resizedTarget.worldTransform.lossyScale.x;
var newLeft = Mathf.Clamp(m_StartPosition.x + delta, localZero.x, localZero.x + validResizeBase.layout.width);
var newWidth = resizedTarget.layout.xMax - newLeft;
if (newWidth >= m_MinSize.x && newWidth <= m_MaxSize.x)
{
resizedTarget.style.left = newLeft;
resizedTarget.style.width = newWidth;
}
}
if ((direction & ResizerDirection.Bottom) != 0)
{
resizedTarget.style.height = Mathf.Min(m_MaxSize.y, Mathf.Max(m_MinSize.y, m_StartSize.y + mousePos.y - m_StartMouse.y));
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
var localZero = resizedBase.WorldToLocal(worldZero);
var localHeight = validResizeBase.layout.height / resizedTarget.worldTransform.lossyScale.x;
var newHeight = m_StartSize.y + (mousePos.y - m_StartMouse.y) / resizedTarget.worldTransform.lossyScale.x;
var newBottom = Mathf.Clamp(resizedTarget.layout.yMin + newHeight, resizedTarget.layout.yMin + m_MinSize.y, localZero.y + localHeight);
resizedTarget.style.height = newBottom - resizedTarget.layout.yMin;
}
else if ((direction & ResizerDirection.Top) != 0)
{
float delta = mousePos.y - m_StartMouse.y;
float previousTop = resizedTarget.style.top.value.value;

resizedTarget.style.top = Mathf.Clamp(delta + m_StartPosition.y, 0, m_StartSize.y - 1);
resizedTarget.style.height = resizedTarget.resolvedStyle.height + previousTop - resizedTarget.style.top.value.value;
var worldZero = validResizeBase.LocalToWorld(Vector2.zero);
var localZero = resizedBase.WorldToLocal(worldZero);
var localHeight = validResizeBase.layout.height / resizedTarget.worldTransform.lossyScale.x;
var delta = (mousePos.y - m_StartMouse.y) / resizedTarget.worldTransform.lossyScale.x;
var newTop = Mathf.Clamp(m_StartPosition.y + delta, localZero.y, localZero.y + localHeight);
var newHeight = resizedTarget.layout.yMax - newTop;
if (newHeight >= m_MinSize.y && newHeight <= m_MaxSize.y)
{
resizedTarget.style.top = newTop;
resizedTarget.style.height = newHeight;
}
}
}
e.StopPropagation();
Expand All @@ -195,5 +218,20 @@ void OnMouseUp(MouseUpEvent e)
m_Active = false;
}
}

void FindValidBaseElement(ref VisualElement resizedBase)
{
// For unknown reason, layers have zero height, which completely break resizing algorithm
// So we look for a parent with proper dimension
while (resizedBase.layout.width == 0 || resizedBase.layout.height == 0)
{
if (resizedBase.parent == null)
{
break;
}

resizedBase = resizedBase.parent;
}
}
}
}
34 changes: 28 additions & 6 deletions Modules/IMGUI/TextEditingUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ void InitKeyActions()
}
}


// Deletes previous text on the line
public bool DeleteLineBack()
{
Expand All @@ -353,6 +352,18 @@ public bool DeleteLineBack()
return true;
}

if (textHandle.useAdvancedText)
{
var start = textHandle.GetFirstCharacterIndexOnLine(cursorIndex);
if (start != cursorIndex)
{
text = text.Remove(start, stringCursorIndex - start);
cursorIndex = selectIndex = start;
return true;
}
return false;
}

var currentLineInfo = textHandle.GetLineInfoFromCharacterIndex(cursorIndex);
var startIndex = currentLineInfo.firstCharacterIndex;
var stringStartIndex = textHandle.GetCorrespondingStringIndex(startIndex);
Expand Down Expand Up @@ -422,7 +433,11 @@ public bool Delete()
}
else if (stringCursorIndex < text.Length)
{
var count = textHandle.textInfo.textElementInfo[cursorIndex].stringLength;
int count;
if (textHandle.useAdvancedText)
count = textHandle.NextCodePointIndex(cursorIndex) - cursorIndex;
else
count = textHandle.textInfo.textElementInfo[cursorIndex].stringLength;
text = text.Remove(stringCursorIndex, count);
return true;
}
Expand All @@ -442,10 +457,15 @@ public bool Backspace()
else if (cursorIndex > 0)
{
var startIndex = m_TextSelectingUtility.PreviousCodePointIndex(cursorIndex);
var count = textHandle.textInfo.textElementInfo[cursorIndex - 1].stringLength;
int count;
if (textHandle.useAdvancedText)
count = (char.IsSurrogate(text[cursorIndex - 1]) ? 2 : 1);
else
count = textHandle.textInfo.textElementInfo[cursorIndex - 1].stringLength;

text = text.Remove(stringCursorIndex - count, count);
cursorIndex = startIndex;
selectIndex = startIndex;
cursorIndex = textHandle.useAdvancedText ? Math.Max(0, cursorIndex - count) : startIndex;
selectIndex = textHandle.useAdvancedText ? Math.Max(0, selectIndex - count) : startIndex;
m_TextSelectingUtility.ClearCursorPos();
return true;
}
Expand Down Expand Up @@ -479,7 +499,8 @@ public void ReplaceSelection(string replace)
DeleteSelection();
text = text.Insert(stringCursorIndex, replace);

var newIndex = cursorIndexNoValidation + new StringInfo(replace).LengthInTextElements;
int length = textHandle.useAdvancedText ? replace.Length : new StringInfo(replace).LengthInTextElements;
var newIndex = cursorIndexNoValidation + length;
cursorIndexNoValidation = newIndex;
selectIndexNoValidation = newIndex;
m_TextSelectingUtility.ClearCursorPos();
Expand Down Expand Up @@ -538,6 +559,7 @@ public bool Cut()
m_TextSelectingUtility.Copy();
return DeleteSelection();
}

public bool Paste()
{
RestoreCursorState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,8 @@ public void Remove(MenuDropdownItem item)

public void ShowInputDropdown(InputDropdownArgs args)
{
var rect = GUIUtility.GUIToScreenRect(worldBound);

// GUIToScreenRect calculates screen space coordinates in relation to contextual menu
// which is the last active view. Since we know the exact offset of contextual menu in
// relation to package manager we can compensate this by subtracting contextual menu origin.
rect.y -= worldBound.yMax;

var dropdown = new GenericInputDropdown(m_ResourceLoader, PackageManagerWindow.instance, args) { position = rect };
var position = PackageManagerWindow.instance.CalculateDropdownPosition(this);
var dropdown = new GenericInputDropdown(m_ResourceLoader, PackageManagerWindow.instance, args) { position = position };
DropdownContainer.ShowDropdown(dropdown);
}
}
Expand Down
9 changes: 0 additions & 9 deletions Modules/PackageManagerUI/Editor/UI/DropdownContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,5 @@ public static void ShowDropdown(DropdownContent content)
instance.ShowAsDropDown(content.position, content.windowSize);
content.OnDropdownShown();
}

static void ShowDropdownContainer()
{
instance.ShowAsDropDown(instance.m_Content.position, instance.m_Content.windowSize);
instance.m_Content.OnDropdownShown();

// 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
EditorApplication.delayCall -= ShowDropdownContainer;
}
}
}
Loading

0 comments on commit a9c1652

Please sign in to comment.