Skip to content

Commit 616cef5

Browse files
author
Unity Technologies
committed
Unity 2019.2.0a8 C# reference source code
1 parent befef62 commit 616cef5

File tree

90 files changed

+1133
-844
lines changed

Some content is hidden

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

90 files changed

+1133
-844
lines changed

Editor/Mono/AssemblyValidation.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ public static bool PluginCompatibleWithEditor(string path)
144144
return pluginImporter.GetCompatibleWithEditor();
145145
}
146146

147+
public static bool ShouldValidateReferences(string path)
148+
{
149+
var pluginImporter = AssetImporter.GetAtPath(path) as PluginImporter;
150+
151+
if (pluginImporter == null)
152+
return true;
153+
154+
return pluginImporter.ValidateReferences;
155+
}
156+
147157
public static void PrintAssemblyDefinitions(AssemblyDefinition[] assemblyDefinitions)
148158
{
149159
foreach (var assemblyDefinition in assemblyDefinitions)
@@ -233,6 +243,13 @@ public static void CheckAssemblyReferences(string[] assemblyPaths,
233243
if (errors[i].HasFlag(ErrorFlags.IncompatibleWithEditor))
234244
continue;
235245

246+
var assemblyPath = assemblyPaths[i];
247+
248+
// Check if "Validate References" option is enabled
249+
// in the PluginImporter
250+
if (!ShouldValidateReferences(assemblyPath))
251+
continue;
252+
236253
ResolveAndSetupReferences(i,
237254
errors,
238255
assemblyDefinitions,
@@ -327,7 +344,7 @@ public static void ResolveAndSetupReferences(int index,
327344
catch (AssemblyResolutionException)
328345
{
329346
errors[index].Add(ErrorFlags.UnresolvableReference,
330-
string.Format("Unable to resolve reference '{0}'. Is the assembly missing or incompatible with the current platform?",
347+
string.Format("Unable to resolve reference '{0}'. Is the assembly missing or incompatible with the current platform?\nReference validation can be disabled in the Plugin Inspector.",
331348
reference.Name));
332349
}
333350
}

Editor/Mono/Audio/Mixer/GUI/AudioMixersTreeView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ protected override void RenameEnded()
458458
ObjectNames.SetNameSmartWithInstanceID(instanceID, name);
459459
}
460460
}
461+
else if (isCreating)
462+
GetCreateAssetUtility().EndNewAssetCreationCanceled(name);
461463
}
462464

463465
override protected void ClearRenameAndNewItemState()

Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,22 @@ internal static string[] GetBuilderDefinedDefines(IIl2CppPlatformProvider il2cpp
218218
return defines.ToArray();
219219
}
220220

221-
internal static string[] GetBuildingIL2CPPArguments(IIl2CppPlatformProvider il2cppPlatformProvider, BuildTargetGroup buildTargetGroup)
221+
internal static string[] GetDebuggerIL2CPPArguments(IIl2CppPlatformProvider il2cppPlatformProvider, BuildTargetGroup buildTargetGroup)
222222
{
223-
// When changing this function, don't forget to change GetBuilderDefinedDefines!
224223
var arguments = new List<string>();
225-
var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);
226224

227225
if (EnableIL2CPPDebugger(il2cppPlatformProvider, buildTargetGroup))
228226
arguments.Add("--enable-debugger");
229227

228+
return arguments.ToArray();
229+
}
230+
231+
internal static string[] GetBuildingIL2CPPArguments(IIl2CppPlatformProvider il2cppPlatformProvider, BuildTargetGroup buildTargetGroup)
232+
{
233+
// When changing this function, don't forget to change GetBuilderDefinedDefines!
234+
var arguments = new List<string>();
235+
var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);
236+
230237
if (BuildPipeline.IsFeatureSupported("ENABLE_SCRIPTING_GC_WBARRIERS", il2cppPlatformProvider.target))
231238
{
232239
var hasGCBarrierValidation = PlayerSettings.gcWBarrierValidation;
@@ -415,6 +422,14 @@ private void ConvertPlayerDlltoCpp(string inputDirectory, string outputDirectory
415422
if (m_BuildForMonoRuntime)
416423
arguments.Add("--mono-runtime");
417424

425+
// Working around gcc bug 41091
426+
if (m_PlatformProvider.target == BuildTarget.StandaloneLinux ||
427+
m_PlatformProvider.target == BuildTarget.StandaloneLinux64 ||
428+
m_PlatformProvider.target == BuildTarget.StandaloneLinuxUniversal)
429+
{
430+
arguments.Add("--disable-aggressive-inlining");
431+
}
432+
418433
var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(m_PlatformProvider.target);
419434
var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup);
420435
arguments.Add(string.Format("--dotnetprofile=\"{0}\"", IL2CPPUtils.ApiCompatibilityLevelToDotNetProfileArgument(apiCompatibilityLevel)));
@@ -428,6 +443,7 @@ private void ConvertPlayerDlltoCpp(string inputDirectory, string outputDirectory
428443
arguments.AddRange(Il2CppNativeCodeBuilderUtils.AddBuilderArguments(il2CppNativeCodeBuilder, OutputFileRelativePath(), m_PlatformProvider.includePaths, m_PlatformProvider.libraryPaths, compilerConfiguration));
429444
}
430445

446+
arguments.AddRange(IL2CPPUtils.GetDebuggerIL2CPPArguments(m_PlatformProvider, buildTargetGroup));
431447
arguments.AddRange(IL2CPPUtils.GetBuildingIL2CPPArguments(m_PlatformProvider, buildTargetGroup));
432448
arguments.Add($"--map-file-parser={CommandLineFormatter.PrepareFileName(GetMapFileParserPath())}");
433449

Editor/Mono/BuildTargetGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public enum BuildTargetGroup
1515
// Unknown target.
1616
Unknown = 0,
1717

18-
// Mac/PC standalone target.
18+
// PC, Mac & Linux standalone target.
1919
Standalone = 1,
2020

2121
//*undocumented*

Editor/Mono/EditorApplication.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,7 @@ internal static extern string windowTitle
239239
}
240240

241241
internal static extern void CloseAndRelaunch(string[] arguments);
242+
243+
internal static extern void RequestCloseAndRelaunchWithCurrentArguments();
242244
}
243245
}

Editor/Mono/EditorGUI.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ public static void BeginChangeCheck()
353353
public static bool EndChangeCheck()
354354
{
355355
bool changed = GUI.changed;
356-
GUI.changed |= s_ChangedStack.Pop();
356+
if (s_ChangedStack.Count == 0)
357+
Debug.LogError("Change stack is empty, did you call BeginChangeCheck first?");
358+
else
359+
GUI.changed |= s_ChangedStack.Pop();
357360
return changed;
358361
}
359362

Editor/Mono/EditorWindow.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ internal void DrawNotification()
278278
if (Event.current.type != EventType.Repaint)
279279
return;
280280

281-
EditorStyles.notificationText.CalcMinMaxWidth(m_Notification, out m_NotificationSize.y, out m_NotificationSize.x);
282-
m_NotificationSize.y = EditorStyles.notificationText.CalcHeight(m_Notification, m_NotificationSize.x);
281+
m_NotificationSize = EditorStyles.notificationText.CalcSize(m_Notification);
283282

284283
Vector2 warningSize = m_NotificationSize;
285284
float targetWidth = position.width - EditorStyles.notificationText.margin.horizontal;
@@ -290,26 +289,20 @@ internal void DrawNotification()
290289
if (targetWidth < m_NotificationSize.x)
291290
{
292291
float scale = targetWidth / m_NotificationSize.x;
293-
warningSize.x *= scale;
294-
warningSize.y = EditorStyles.notificationText.CalcHeight(m_Notification, warningSize.x);
295292

296293
scaledNotificationText = new GUIStyle(EditorStyles.notificationText);
297294
scaledNotificationText.fontSize = Mathf.FloorToInt(scaledNotificationText.font.fontSize * scale);
295+
296+
warningSize = scaledNotificationText.CalcSize(m_Notification);
298297
}
299298

299+
warningSize.x += 1; //we'll give the text a little room to breathe to avoid word-wrapping issues with drop shadows
300+
300301
if (warningSize.y > targetHeight)
301302
warningSize.y = targetHeight;
302303

303304
Rect r = new Rect((position.width - warningSize.x) * .5f, 20 + (position.height - 20 - warningSize.y) * .7f, warningSize.x, warningSize.y);
304305

305-
// Round notification coordinate & with to integers, so that text
306-
// shadow rendering(which is offset from base text) gets exactly
307-
// the same floating point results for text wrapping. Without this,
308-
// it can lead to tiny differences that make shadow be word - wrapped
309-
// differently from foreground text.
310-
r.x = Mathf.FloorToInt(r.x);
311-
r.width = Mathf.FloorToInt(r.width);
312-
313306
double time = EditorApplication.timeSinceStartup;
314307
if (time > m_FadeoutTime)
315308
GUI.color = new Color(1, 1, 1, 1 - (float)((time - m_FadeoutTime) / kWarningFadeoutTime));

Editor/Mono/GUI/AssetPopupBackend.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,34 @@ internal class AssetPopupBackend
3838
AssetPopup<T>(serializedProperty, label, fileExtension, "Default");
3939
}
4040

41-
// private
41+
private class DoCreateNewAsset : ProjectWindowCallback.EndNameEditAction
42+
{
43+
private SerializedProperty m_Property;
44+
45+
public void SetProperty(SerializedProperty property)
46+
{
47+
var so = new SerializedObject(property.serializedObject.targetObject);
48+
m_Property = so.FindProperty(property.propertyPath);
49+
}
50+
51+
public override void Action(int instanceId, string pathName, string resourceFile)
52+
{
53+
var obj = EditorUtility.InstanceIDToObject(instanceId);
54+
AssetDatabase.CreateAsset(obj, AssetDatabase.GenerateUniqueAssetPath(pathName));
55+
ProjectWindowUtil.FrameObjectInProjectWindow(instanceId);
56+
m_Property.objectReferenceValue = obj;
57+
m_Property.serializedObject.ApplyModifiedProperties();
58+
m_Property.serializedObject.Dispose();
59+
m_Property.Dispose();
60+
}
61+
62+
public override void Cancelled(int instanceId, string pathName, string resourceFile)
63+
{
64+
Selection.activeObject = m_Property.serializedObject.targetObject;
65+
m_Property.serializedObject.Dispose();
66+
m_Property.Dispose();
67+
}
68+
}
4269

4370
static void ShowAssetsPopupMenu<T>(Rect buttonRect, string typeName, SerializedProperty serializedProperty, string fileExtension, string defaultFieldName) where T : Object, new()
4471
{
@@ -94,9 +121,9 @@ internal class AssetPopupBackend
94121
gm.AddItem(EditorGUIUtility.TrTextContent("Create New..."), false, delegate
95122
{
96123
var newAsset = Activator.CreateInstance<T>();
97-
ProjectWindowUtil.CreateAsset(newAsset, "New " + typeName + "." + fileExtension);
98-
serializedProperty.objectReferenceValue = newAsset;
99-
serializedProperty.m_SerializedObject.ApplyModifiedProperties();
124+
var doCreate = ScriptableObject.CreateInstance<DoCreateNewAsset>();
125+
doCreate.SetProperty(serializedProperty);
126+
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(newAsset.GetInstanceID(), doCreate, "New " + typeName + "." + fileExtension, AssetPreview.GetMiniThumbnail(newAsset), null);
100127
});
101128

102129
gm.DropDown(buttonRect);

Editor/Mono/GUI/CreateAssetUtility.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ public void EndNewAssetCreation(string name)
119119
string resourceFile = m_ResourceFile;
120120
Clear(); // Ensure clear if anything goes bad in EndNameEditAction and gui is exited.
121121

122-
ProjectWindowUtil.EndNameEditAction(endAction, instanceID, path, resourceFile);
122+
ProjectWindowUtil.EndNameEditAction(endAction, instanceID, path, resourceFile, true);
123+
}
124+
125+
public void EndNewAssetCreationCanceled(string name)
126+
{
127+
string path = folder + "/" + name + extension;
128+
ProjectWindowUtil.EndNameEditAction(m_EndAction, m_InstanceID, path, m_ResourceFile, false);
123129
}
124130

125131
public bool IsCreatingNewAsset()

Editor/Mono/GUI/FoldoutHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static bool BeginFoldoutHeaderGroup(Rect position, bool foldout, GUIConte
4545
// Removing the default margin for inspectors
4646
if (EditorGUIUtility.hierarchyMode)
4747
{
48-
position.xMin -= EditorStyles.inspectorDefaultMargins.padding.left;
48+
position.xMin -= EditorStyles.inspectorDefaultMargins.padding.left - EditorStyles.inspectorDefaultMargins.padding.right;
4949
}
5050

5151
if (style == null)

Editor/Mono/GUI/RenameOverlay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal class RenameOverlay
5454
string k_RenameOverlayFocusName = "RenameOverlayField";
5555

5656
// property interface
57-
public string name { get {return m_Name; }}
57+
public string name { get {return m_Name; } internal set { m_Name = value; } }
5858
public string originalName { get {return m_OriginalName; }}
5959
public bool userAcceptedRename { get {return m_UserAcceptedRename; }}
6060
public int userData { get {return m_UserData; }}

Editor/Mono/GUI/TreeView/AssetsTreeViewGUI.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ override protected void RenameEnded()
8282
ObjectNames.SetNameSmartWithInstanceID(instanceID, name);
8383
}
8484
}
85+
else if (isCreating)
86+
GetCreateAssetUtility().EndNewAssetCreationCanceled(name);
8587
}
8688

8789
override protected void SyncFakeItem()

Editor/Mono/GUI/TreeView/TreeViewController.cs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -527,28 +527,18 @@ public void OnGUI(Rect rect, int keyboardControlID)
527527
EndNameEditing(true);
528528
}
529529

530-
// Grab keyboard focus if requested or if we have a mousedown in entire rect
531-
if (m_GrabKeyboardFocus || (evt.type == EventType.MouseDown && m_TotalRect.Contains(evt.mousePosition)))
530+
// Grab keyboard focus if requested
531+
if (m_GrabKeyboardFocus)
532532
{
533533
m_GrabKeyboardFocus = false;
534534
GUIUtility.keyboardControl = m_KeyboardControlID;
535-
m_AllowRenameOnMouseUp = true;
536535
Repaint(); // Ensure repaint so we can show we have keyboard focus
537536
}
538537

539-
bool hasFocus = HasFocus();
540-
541-
// Detect got focus (ignore layout event which might get fired infront of mousedown)
542-
if (hasFocus != m_HadFocusLastEvent && evt.type != EventType.Layout)
538+
bool isMouseDownInTotalRect = evt.type == EventType.MouseDown && m_TotalRect.Contains(evt.mousePosition);
539+
if (isMouseDownInTotalRect)
543540
{
544-
m_HadFocusLastEvent = hasFocus;
545-
546-
// We got focus this event
547-
if (hasFocus)
548-
{
549-
if (evt.type == EventType.MouseDown)
550-
m_AllowRenameOnMouseUp = false; // If we got focus by mouse down then we do not want to begin renaming if clicking on an already selected item
551-
}
541+
m_AllowRenameOnMouseUp = true; // reset value (can be changed later in this event if the TreeView gets focus)
552542
}
553543

554544
// Might change expanded state so call before InitIfNeeded (delayed collapse until animation is done)
@@ -605,7 +595,7 @@ public void OnGUI(Rect rect, int keyboardControlID)
605595
int numVisibleRows = lastRow - firstRow + 1;
606596
float rowWidth = Mathf.Max(GUIClip.visibleRect.width, m_ContentRect.width);
607597

608-
IterateVisibleItems(firstRow, numVisibleRows, rowWidth, hasFocus);
598+
IterateVisibleItems(firstRow, numVisibleRows, rowWidth, HasFocus());
609599
}
610600

611601
// Call before gui.EndRowGUI() so stuff we render in EndRowGUI does not end up
@@ -623,6 +613,9 @@ public void OnGUI(Rect rect, int keyboardControlID)
623613
HandleUnusedEvents();
624614
KeyboardGUI();
625615

616+
// Call after iterating rows since selecting a row takes keyboard focus
617+
HandleTreeViewGotFocus(isMouseDownInTotalRect);
618+
626619
// Prevent controlID inconsistency for the controls following this tree view: We use the hint parameter of GetControlID to
627620
// fast forward to a fixed entry in the id list so the following controls always start from there regardless of the rows that have been
628621
// culled.
@@ -632,6 +625,26 @@ public void OnGUI(Rect rect, int keyboardControlID)
632625
hoveredItem = null;
633626
}
634627

628+
void HandleTreeViewGotFocus(bool isMouseDownInTotalRect)
629+
{
630+
if (Event.current.type == EventType.Layout)
631+
return;
632+
633+
// Detect if TreeView got keyboard focus (ignore layout event which gets fired infront of mousedown)
634+
bool hasFocus = HasFocus();
635+
if (hasFocus != m_HadFocusLastEvent)
636+
{
637+
m_HadFocusLastEvent = hasFocus;
638+
639+
if (hasFocus && isMouseDownInTotalRect)
640+
{
641+
// If we got focus this event by mouse down then we do not want to begin renaming
642+
// if clicking on an already selected item in the up coming MouseUp event.
643+
m_AllowRenameOnMouseUp = false;
644+
}
645+
}
646+
}
647+
635648
void IterateVisibleItems(int firstRow, int numVisibleRows, float rowWidth, bool hasFocus)
636649
{
637650
// We stop iterating items if datasource state changes while iterating its items.
@@ -830,11 +843,18 @@ void HandleUnusedEvents()
830843
break;
831844

832845
case EventType.MouseDown:
833-
if (deselectOnUnhandledMouseDown && Event.current.button == 0 && m_TotalRect.Contains(Event.current.mousePosition) && state.selectedIDs.Count > 0)
846+
bool containsMouse = m_TotalRect.Contains(Event.current.mousePosition);
847+
if (containsMouse)
848+
{
849+
GUIUtility.keyboardControl = m_KeyboardControlID;
850+
Repaint();
851+
}
852+
if (deselectOnUnhandledMouseDown && containsMouse && Event.current.button == 0 && state.selectedIDs.Count > 0)
834853
{
835854
SetSelection(new int[0], false);
836855
NotifyListenersThatSelectionChanged();
837856
}
857+
838858
break;
839859
case EventType.ContextClick:
840860
if (m_TotalRect.Contains(Event.current.mousePosition))

Editor/Mono/GUI/WindowLayout.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
namespace UnityEditor
2323
{
24-
internal class WindowLayout
24+
[InitializeOnLoad]
25+
internal static class WindowLayout
2526
{
2627
private const string kMaximizeRestoreFile = "CurrentMaximizeLayout.dwlt";
2728
private const string kLastLayoutName = "LastLayout.dwlt";

Editor/Mono/ImportSettings/TextureImporterInspector.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,12 @@ private void SpriteGUI(TextureInspectorGUIElement guiElements)
948948
m_ShowGenericSpriteSettings.target = (m_SpriteMode.intValue != 0);
949949
if (EditorGUILayout.BeginFadeGroup(m_ShowGenericSpriteSettings.faded))
950950
{
951-
EditorGUILayout.PropertyField(m_SpritePackingTag, s_Styles.spritePackingTag);
951+
if (EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOn ||
952+
EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnly)
953+
{
954+
EditorGUILayout.PropertyField(m_SpritePackingTag, s_Styles.spritePackingTag);
955+
}
956+
952957
EditorGUILayout.PropertyField(m_SpritePixelsToUnits, s_Styles.spritePixelsPerUnit);
953958

954959
m_ShowSpriteMeshTypeOption.target = ShouldShowSpriteMeshTypeOption();

Editor/Mono/Inspector/Avatar/AvatarSetupTool.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,16 @@ private static void SetupHumanSkeleton(GameObject modelPrefab, ref HumanBone[] h
631631
{
632632
BoneWrapper bone = humanBones[i];
633633
if (mapping.ContainsKey(i))
634+
{
634635
humanBoneMappings.Add(
635636
new HumanBone()
636637
{
637638
boneName = mapping[i].name,
638639
humanName = bone.humanBoneName,
639640
limit = new HumanLimit() { useDefaultValues = true }
640641
});
642+
humanBones[i].bone = mapping[i];
643+
}
641644
}
642645
humanBoneMappingArray = humanBoneMappings.ToArray();
643646
SimpleProfiler.End();

0 commit comments

Comments
 (0)