Skip to content

Commit e8c54a3

Browse files
author
Unity Technologies
committed
Unity 2020.1.0a16 C# reference source code
1 parent 2dce988 commit e8c54a3

File tree

184 files changed

+4862
-1922
lines changed

Some content is hidden

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

184 files changed

+4862
-1922
lines changed

Editor/Mono/Animation/AnimationWindow/AddCurvesPopupHierarchyGUI.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ internal class AddCurvesPopupHierarchyGUI : TreeViewGUI
1414
{
1515
public EditorWindow owner;
1616
public bool showPlusButton { get; set; }
17-
private GUIStyle plusButtonStyle = "OL Plus";
17+
private GUIStyle buttonStyle = "IconButton";
18+
private GUIContent plusIcon = EditorGUIUtility.TrIconContent("Toolbar Plus");
1819
private GUIStyle plusButtonBackgroundStyle = "Tag MenuItem";
1920
private GUIContent addPropertiesContent = EditorGUIUtility.TrTextContent("Add Properties");
2021
private const float plusButtonWidth = 17;
@@ -48,7 +49,7 @@ public override void OnRowGUI(Rect rowRect, TreeViewItem node, int row, bool sel
4849

4950
if (propertyPathMismatchWithHumanAvatar)
5051
{
51-
Rect iconRect = new Rect(rowRect.width - plusButtonWidth, rowRect.yMin, plusButtonWidth, plusButtonStyle.fixedHeight);
52+
Rect iconRect = new Rect(rowRect.width - plusButtonWidth, rowRect.yMin, plusButtonWidth, buttonStyle.fixedHeight);
5253
GUI.Label(iconRect, new GUIContent(warningIcon, "The Avatar definition does not match the property path. Please author using a hierarchy the Avatar was built with."), warningIconStyle);
5354
}
5455
}
@@ -60,14 +61,14 @@ private void DoAddCurveButton(Rect rowRect, TreeViewItem node)
6061
if (hierarchyNode == null || hierarchyNode.curveBindings == null || hierarchyNode.curveBindings.Length == 0)
6162
return;
6263

63-
Rect buttonRect = new Rect(rowRect.width - plusButtonWidth, rowRect.yMin, plusButtonWidth, plusButtonStyle.fixedHeight);
64+
Rect buttonRect = new Rect(rowRect.width - plusButtonWidth, rowRect.yMin, plusButtonWidth, buttonStyle.fixedHeight);
6465

6566
// TODO Make a style for add curves popup
6667
// Draw background behind plus button to prevent text overlapping
6768
GUI.Box(buttonRect, GUIContent.none, plusButtonBackgroundStyle);
6869

6970
// Check if the curve already exists and remove plus button
70-
if (GUI.Button(buttonRect, GUIContent.none, plusButtonStyle))
71+
if (GUI.Button(buttonRect, plusIcon, buttonStyle))
7172
{
7273
AddCurvesPopup.AddNewCurve(hierarchyNode);
7374

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,10 +753,11 @@ void SliderGUI()
753753
}
754754
min = shownXMin;
755755
max = shownXMin + shownXRange;
756+
float rectWidthWithinMargins = GetWidthInsideMargins(rect.width, true);
756757
if (min > area.xMin)
757-
min = Mathf.Min(min, max - rect.width / m_HScaleMax);
758+
min = Mathf.Min(min, max - rectWidthWithinMargins / m_HScaleMax);
758759
if (max < area.xMax)
759-
max = Mathf.Max(max, min + rect.width / m_HScaleMax);
760+
max = Mathf.Max(max, min + rectWidthWithinMargins / m_HScaleMax);
760761
SetShownHRangeInsideMargins(min, max);
761762
}
762763

@@ -787,10 +788,11 @@ void SliderGUI()
787788
}
788789
min = -(shownYMin + shownYRange);
789790
max = -shownYMin;
791+
float rectHeightWithinMargins = GetHeightInsideMargins(rect.height, true);
790792
if (min > area.yMin)
791-
min = Mathf.Min(min, max - rect.height / m_VScaleMax);
793+
min = Mathf.Min(min, max - rectHeightWithinMargins / m_VScaleMax);
792794
if (max < area.yMax)
793-
max = Mathf.Max(max, min + rect.height / m_VScaleMax);
795+
max = Mathf.Max(max, min + rectHeightWithinMargins / m_VScaleMax);
794796
SetShownVRangeInsideMargins(min, max);
795797
}
796798
else
@@ -816,10 +818,11 @@ void SliderGUI()
816818
}
817819
min = shownYMin;
818820
max = shownYMin + shownYRange;
821+
float rectHeightWithinMargins = GetHeightInsideMargins(rect.height, true);
819822
if (min > area.yMin)
820-
min = Mathf.Min(min, max - rect.height / m_VScaleMax);
823+
min = Mathf.Min(min, max - rectHeightWithinMargins / m_VScaleMax);
821824
if (max < area.yMax)
822-
max = Mathf.Max(max, min + rect.height / m_VScaleMax);
825+
max = Mathf.Max(max, min + rectHeightWithinMargins / m_VScaleMax);
823826
SetShownVRangeInsideMargins(min, max);
824827
}
825828
}

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
[assembly: InternalsVisibleTo("Unity.2D.Tilemap.Editor")]
112112
[assembly: InternalsVisibleTo("Unity.2D.Tilemap.EditorTests")]
113113
[assembly: InternalsVisibleTo("Unity.PackageCleanConsoleTest.Editor")]
114+
[assembly: InternalsVisibleTo("Unity.UIElements")]
115+
[assembly: InternalsVisibleTo("Unity.UIElements.Editor")]
116+
[assembly: InternalsVisibleTo("Unity.UIElements.Tests")]
117+
[assembly: InternalsVisibleTo("Unity.UIElements.EditorTests")]
114118
[assembly: InternalsVisibleTo("Unity.SceneTemplate.Editor")]
115119

116120
[assembly: AssemblyIsEditorAssembly]

Editor/Mono/AssemblyValidation.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ public static void ResolveAndSetupReferences(int index,
388388
if (assemblyDefinitionNameToIndex.TryGetValue(referenceAssemblyDefinition.Name.Name,
389389
out referenceAssemblyDefinitionIndex))
390390
{
391+
bool isSigned = IsSigned(reference);
392+
if (isSigned)
393+
{
394+
var definition = assemblyDefinitions[referenceAssemblyDefinitionIndex];
395+
if (definition.Name.Version.ToString() != reference.Version.ToString())
396+
{
397+
errors[index].Add(ErrorFlags.UnresolvableReference,
398+
$"{assemblyDefinition.Name.Name} references strong named {reference.Name}, versions has to match. Assembly references: {reference.Version} Found in project: {definition.Name.Version}.");
399+
}
400+
}
401+
391402
referenceIndieces.Add(referenceAssemblyDefinitionIndex);
392403
}
393404
}
@@ -402,6 +413,19 @@ public static void ResolveAndSetupReferences(int index,
402413
assemblyAndReferences[index].referenceIndicies = referenceIndieces.ToArray();
403414
}
404415

416+
private static bool IsSigned(AssemblyNameReference reference)
417+
{
418+
//Bug in Cecil where HasPublicKey is always false
419+
foreach (var publicTokenByte in reference.PublicKeyToken)
420+
{
421+
if (publicTokenByte != 0)
422+
{
423+
return true;
424+
}
425+
}
426+
return false;
427+
}
428+
405429
public static AssemblyNameReference[] GetAssemblyNameReferences(AssemblyDefinition assemblyDefinition)
406430
{
407431
List<AssemblyNameReference> result = new List<AssemblyNameReference>

Editor/Mono/ContainerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ private void DragTitleBar(Rect titleBarRect)
471471
// If the mouse is inside the title bar rect, we say that we're the hot control
472472
if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
473473
{
474-
if (Application.platform == RuntimePlatform.WindowsEditor)
474+
if (Application.platform != RuntimePlatform.LinuxEditor)
475475
{
476476
Event.current.Use();
477477
m_DraggingNativeTitleBarCaption = true;

Editor/Mono/EditorApplication.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public static void DirtyHierarchyWindowSorting()
179179

180180
public static event Action quitting;
181181

182-
public static event Action delayCall;
182+
public static CallbackFunction delayCall;
183183

184184
// Each time an object is (or a group of objects are) created, renamed, parented, unparented or destroyed this callback is raised.
185185
public static event Action hierarchyChanged;
@@ -319,7 +319,7 @@ static void Internal_CallUpdateFunctions()
319319

320320
static void Internal_CallDelayFunctions()
321321
{
322-
var delay = delayCall;
322+
CallbackFunction delay = delayCall;
323323
delayCall = null;
324324

325325
if (delay != null)

Editor/Mono/EditorGUI.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ internal static Rect GetInspectorTitleBarObjectFoldoutRenderRect(Rect rect)
13901390

13911391
internal static Rect GetInspectorTitleBarObjectFoldoutRenderRect(Rect rect, GUIStyle baseStyle)
13921392
{
1393-
return new Rect(rect.x + EditorStyles.foldout.margin.left + 1f, rect.y + (rect.height - kInspTitlebarFoldoutIconWidth) / 2 + (baseStyle != null ? baseStyle.padding.top : 0), kInspTitlebarFoldoutIconWidth, kInspTitlebarFoldoutIconWidth);
1393+
return new Rect(rect.x + EditorStyles.titlebarFoldout.margin.left + 1f, rect.y + (rect.height - kInspTitlebarFoldoutIconWidth) / 2 + (baseStyle != null ? baseStyle.padding.top : 0), kInspTitlebarFoldoutIconWidth, kInspTitlebarFoldoutIconWidth);
13941394
}
13951395

13961396
[SuppressMessage("ReSharper", "RedundantCast.0")]
@@ -1559,7 +1559,7 @@ private static void DoObjectFoldoutInternal(bool foldout, Rect renderRect, int i
15591559
{
15601560
case EventType.Repaint:
15611561
bool isPressed = GUIUtility.hotControl == id;
1562-
EditorStyles.foldout.Draw(renderRect, isPressed, isPressed, foldout, false);
1562+
EditorStyles.titlebarFoldout.Draw(renderRect, isPressed, isPressed, foldout, false);
15631563
break;
15641564
}
15651565

@@ -5325,7 +5325,7 @@ internal static bool ToggleTitlebar(Rect position, GUIContent label, bool foldou
53255325

53265326
GUIStyle baseStyle = EditorStyles.inspectorTitlebar;
53275327
GUIStyle textStyle = EditorStyles.inspectorTitlebarText;
5328-
GUIStyle foldoutStyle = EditorStyles.foldout;
5328+
GUIStyle foldoutStyle = EditorStyles.titlebarFoldout;
53295329

53305330
Rect toggleRect = new Rect(position.x + baseStyle.padding.left, position.y + baseStyle.padding.top, kInspTitlebarIconWidth, kInspTitlebarIconWidth);
53315331
Rect textRect = new Rect(toggleRect.xMax + kInspTitlebarSpacing, toggleRect.y, 200, kInspTitlebarIconWidth);
@@ -5373,7 +5373,7 @@ internal static bool FoldoutTitlebar(Rect position, GUIContent label, bool foldo
53735373

53745374
break;
53755375
case EventType.Repaint:
5376-
GUIStyle foldoutStyle = EditorStyles.foldout;
5376+
GUIStyle foldoutStyle = EditorStyles.titlebarFoldout;
53775377
Rect textRect =
53785378
new Rect(
53795379
position.x + baseStyle.padding.left +

Editor/Mono/EditorGUIUtility.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static void RenderGameViewCameras(RenderTexture target, int targetDisplay
156156
private static extern Texture2D FindTextureByName(string name);
157157
private static extern Texture2D FindTextureByType([NotNull] Type type);
158158
private static extern string GetObjectNameWithInfo(Object obj);
159-
private static extern string GetTypeNameWithInfo(string typeName);
159+
private static extern string GetTypeNameWithInfo(string typeName, int instanceID);
160160
private static extern void Internal_SetupEventValues(object evt);
161161
private static extern Vector2 Internal_GetIconSize();
162162
private static extern bool Internal_GetKeyboardRect(int id, out Rect rect);

Editor/Mono/EditorGUIUtility.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,11 @@ internal static void Internal_SwitchSkin()
799799

800800
// Return a GUIContent object with the name and icon of an Object.
801801
public static GUIContent ObjectContent(UnityObject obj, Type type)
802+
{
803+
return ObjectContent(obj, type, ReferenceEquals(obj, null) ? 0 : obj.GetInstanceID());
804+
}
805+
806+
internal static GUIContent ObjectContent(UnityObject obj, Type type, int instanceID)
802807
{
803808
if (obj)
804809
{
@@ -807,7 +812,7 @@ public static GUIContent ObjectContent(UnityObject obj, Type type)
807812
}
808813
else if (type != null)
809814
{
810-
s_ObjectContent.text = GetTypeNameWithInfo(type.Name);
815+
s_ObjectContent.text = GetTypeNameWithInfo(type.Name, instanceID);
811816
s_ObjectContent.image = AssetPreview.GetMiniTypeThumbnail(type);
812817
}
813818
else

Editor/Mono/EditorSettings.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ internal static extern string Internal_ProjectGenerationUserExtensions
256256
public static extern bool serializeInlineMappingsOnOneLine { get; set; }
257257

258258
[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
259-
public static extern AssetPipelineMode assetPipelineMode { get; set; }
259+
public static extern AssetPipelineMode assetPipelineMode { get; }
260260

261261
[StaticAccessor("GetEditorSettings()", StaticAccessorType.Dot)]
262262
public static extern CacheServerMode cacheServerMode { get; set; }

Editor/Mono/EditorUserBuildSettings.bindings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ public static extern bool switchNVNShaderDebugging
630630
}
631631

632632
// Enable debug validation of NVN drawcalls
633+
[Obsolete("switchNVNDrawValidation is deprecated, use switchNVNDrawValidation_Heavy instead.")]
633634
public static bool switchNVNDrawValidation
634635
{
635636
get { return switchNVNDrawValidation_Heavy; }

Editor/Mono/EditorWindow.cs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SerializableJsonDictionary = UnityEditor.UIElements.SerializableJsonDictionary;
1313
using UnityEngine.UIElements;
1414
using UnityEditor.UIElements;
15+
using Object = System.Object;
1516

1617
namespace UnityEditor
1718
{
@@ -44,34 +45,9 @@ public partial class EditorWindow : ScriptableObject
4445
[HideInInspector]
4546
internal Rect m_Pos = new Rect(0, 0, 320, 550);
4647

47-
private VisualElement m_RootVisualElement;
48-
public VisualElement rootVisualElement
49-
{
50-
get
51-
{
52-
if (m_RootVisualElement != null)
53-
return m_RootVisualElement;
48+
public VisualElement rootVisualElement => this.GetRootVisualElement();
5449

55-
m_RootVisualElement = CreateRoot();
56-
return m_RootVisualElement;
57-
}
58-
}
59-
60-
static VisualElement CreateRoot()
61-
{
62-
var name = "rootVisualContainer";
63-
var root = new VisualElement()
64-
{
65-
name = VisualElementUtils.GetUniqueName(name),
66-
pickingMode = PickingMode.Ignore, // do not eat events so IMGUI gets them
67-
viewDataKey = name,
68-
renderHints = RenderHints.ClipWithScissors
69-
};
70-
root.pseudoStates |= PseudoStates.Root;
71-
UIElements.UIElementsEditorUtility.AddDefaultEditorStyleSheets(root);
72-
root.style.overflow = UnityEngine.UIElements.Overflow.Hidden;
73-
return root;
74-
}
50+
internal System.Object uiRootElement { get; set; }
7551

7652
[HideInInspector]
7753
[SerializeField]
@@ -619,11 +595,12 @@ public void ShowModal()
619595
ContainerWindow.s_Modal = true;
620596

621597
SavedGUIState guiState = SavedGUIState.Create();
622-
m_Parent.visualTree.panel.dispatcher?.PushDispatcherContext();
598+
// TODO need to promote this outside of UIE
599+
UnityEngine.UIElements.EventDispatcher.editorDispatcher.PushDispatcherContext();
623600

624601
MakeModal(m_Parent.window);
625602

626-
m_Parent.visualTree.panel.dispatcher?.PopDispatcherContext();
603+
UnityEngine.UIElements.EventDispatcher.editorDispatcher.PopDispatcherContext();
627604
guiState.ApplyAndForget();
628605
}
629606
finally
@@ -1073,19 +1050,6 @@ public Rect position
10731050
}
10741051
}
10751052

1076-
private void RefreshStylesAfterExternalEvent()
1077-
{
1078-
var panel = m_Parent.visualTree.elementPanel;
1079-
if (panel == null)
1080-
return;
1081-
1082-
var updater = panel.GetUpdater(VisualTreeUpdatePhase.Bindings) as VisualTreeBindingsUpdater;
1083-
if (updater == null)
1084-
return;
1085-
1086-
updater.PollElementsWithBindings((e, b) => BindingExtensions.HandleStyleUpdate(e));
1087-
}
1088-
10891053
// Sends an Event to a window.
10901054
public bool SendEvent(Event e)
10911055
{
@@ -1106,16 +1070,11 @@ private void __internalAwake()
11061070

11071071
private void OnEnableINTERNAL()
11081072
{
1109-
AnimationMode.onAnimationRecordingStart += RefreshStylesAfterExternalEvent;
1110-
AnimationMode.onAnimationRecordingStop += RefreshStylesAfterExternalEvent;
11111073
}
11121074

11131075
private void OnDisableINTERNAL()
11141076
{
11151077
SaveViewDataToDisk();
1116-
1117-
AnimationMode.onAnimationRecordingStart -= RefreshStylesAfterExternalEvent;
1118-
AnimationMode.onAnimationRecordingStop -= RefreshStylesAfterExternalEvent;
11191078
}
11201079

11211080
// Internal stuff:
@@ -1171,6 +1130,44 @@ public static int GetAntiAliasing(this EditorWindow window)
11711130
{
11721131
return window.antiAliasing;
11731132
}
1133+
1134+
internal static VisualElement GetRootVisualElement(this EditorWindow window)
1135+
{
1136+
object rootElement = window.uiRootElement;
1137+
1138+
if (rootElement == null)
1139+
{
1140+
var root = CreateRoot();
1141+
window.uiRootElement = root;
1142+
return root;
1143+
}
1144+
1145+
var result = rootElement as VisualElement;
1146+
1147+
if (result == null)
1148+
{
1149+
Debug.Log($"An editor window can only use one UIElements version at a time. Root element of type \"{rootElement.GetType().AssemblyQualifiedName}\" was already created and assigned to this EditorWindow.");
1150+
return null;
1151+
}
1152+
1153+
return result;
1154+
}
1155+
1156+
private static VisualElement CreateRoot()
1157+
{
1158+
var name = "rootVisualContainer";
1159+
var root = new VisualElement()
1160+
{
1161+
name = VisualElementUtils.GetUniqueName(name),
1162+
pickingMode = PickingMode.Ignore, // do not eat events so IMGUI gets them
1163+
viewDataKey = name,
1164+
renderHints = RenderHints.ClipWithScissors
1165+
};
1166+
root.pseudoStates |= PseudoStates.Root;
1167+
UIElementsEditorUtility.AddDefaultEditorStyleSheets(root);
1168+
root.style.overflow = UnityEngine.UIElements.Overflow.Hidden;
1169+
return root;
1170+
}
11741171
}
11751172
}
11761173
} //namespace

0 commit comments

Comments
 (0)