Skip to content

Commit d01ef2a

Browse files
author
Unity Technologies
committed
Unity 2020.1.0b10 C# reference source code
1 parent cfb3a31 commit d01ef2a

File tree

96 files changed

+1529
-746
lines changed

Some content is hidden

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

96 files changed

+1529
-746
lines changed

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ private void InitializeCurveEditor()
14001400
// Called once during initialization of m_State
14011401
private void InitializeHorizontalSplitter()
14021402
{
1403-
m_HorizontalSplitter = new SplitterState(new float[] { kHierarchyMinWidth, kHierarchyMinWidth * 3 }, new int[] { kHierarchyMinWidth, kHierarchyMinWidth }, null);
1403+
m_HorizontalSplitter = SplitterState.FromRelative(new float[] { kHierarchyMinWidth, kHierarchyMinWidth * 3 }, new float[] { kHierarchyMinWidth, kHierarchyMinWidth }, null);
14041404
m_HorizontalSplitter.realSizes[0] = kHierarchyMinWidth;
14051405
m_HorizontalSplitter.realSizes[1] = kHierarchyMinWidth;
14061406
}

Editor/Mono/Animation/AnimationWindow/MinMaxCurveEditorWindow.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void InitCurvePresets()
9696
if (m_CurvePresets == null)
9797
{
9898
AnimationCurve max = m_CurveEditor.animationCurves[0].curve;
99-
AnimationCurve min = m_CurveEditor.animationCurves.Length > 1 ? m_CurveEditor.animationCurves[1].curve : null;
99+
AnimationCurve min = m_CurveEditor.animationCurves.Length > 1 ? m_CurveEditor.animationCurves[1].curve : new AnimationCurve();
100100

101101
// Selection callback for library window
102102
System.Action<DoubleCurve> presetSelectedCallback = delegate(DoubleCurve presetCurve)
@@ -110,6 +110,9 @@ void InitCurvePresets()
110110
doubleCurve.maxCurve.postWrapMode = presetCurve.maxCurve.postWrapMode;
111111
doubleCurve.maxCurve.preWrapMode = presetCurve.maxCurve.preWrapMode;
112112

113+
m_MinCurve = doubleCurve.minCurve;
114+
m_MaxCurve = doubleCurve.maxCurve;
115+
113116
m_CurveEditor.SelectNone();
114117
RefreshShownCurves();
115118
SendEvent("CurveChanged", true);

Editor/Mono/AssemblyValidation.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections.Generic;
77
using System.Globalization;
8+
using System.IO;
89
using System.Runtime.InteropServices;
910
using Mono.Cecil;
1011
using UnityEditor.Scripting.ScriptCompilation;
@@ -392,10 +393,11 @@ public static void ResolveAndSetupReferences(int index,
392393
if (isSigned)
393394
{
394395
var definition = assemblyDefinitions[referenceAssemblyDefinitionIndex];
395-
if (definition.Name.Version.ToString() != reference.Version.ToString())
396+
397+
if (definition.Name.Version.ToString() != reference.Version.ToString() && !IsInSameFolder(assemblyDefinition, referenceAssemblyDefinition))
396398
{
397399
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}.");
400+
$"{assemblyDefinition.Name.Name} references strong named {reference.Name} in a different folder, versions has to match. Assembly references: {reference.Version} Found in project: {definition.Name.Version}.");
399401
}
400402
}
401403

@@ -413,6 +415,13 @@ public static void ResolveAndSetupReferences(int index,
413415
assemblyAndReferences[index].referenceIndicies = referenceIndieces.ToArray();
414416
}
415417

418+
private static bool IsInSameFolder(AssemblyDefinition first, AssemblyDefinition second)
419+
{
420+
var firstAssemblyPath = Path.GetDirectoryName(first.MainModule.FileName);
421+
var secondAssemblyPath = Path.GetDirectoryName(second.MainModule.FileName);
422+
return firstAssemblyPath.Equals(secondAssemblyPath, StringComparison.Ordinal);
423+
}
424+
416425
private static bool IsSigned(AssemblyNameReference reference)
417426
{
418427
//Bug in Cecil where HasPublicKey is always false

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,20 @@ void Init()
184184

185185
if (m_LayoutStripsOnTop.m_VerticalSplitter == null || m_LayoutStripsOnTop.m_VerticalSplitter.realSizes.Length != 2)
186186
{
187-
m_LayoutStripsOnTop.m_VerticalSplitter = new SplitterState(new int[] { 65, 35 }, new int[] { 85, 105 }, null);
187+
m_LayoutStripsOnTop.m_VerticalSplitter = SplitterState.FromAbsolute(new float[] { 65, 35 }, new float[] { 85, 105 }, null);
188188
}
189189

190190
if (m_LayoutStripsOnTop.m_HorizontalSplitter == null || m_LayoutStripsOnTop.m_HorizontalSplitter.realSizes.Length != 4)
191-
m_LayoutStripsOnTop.m_HorizontalSplitter = new SplitterState(new int[] { 60, 60, 60, 60 }, new int[] { 85, 85, 85, 85 }, null);
191+
m_LayoutStripsOnTop.m_HorizontalSplitter = SplitterState.FromAbsolute(new float[] { 60, 60, 60, 60 }, new float[] { 85, 85, 85, 85 }, null);
192192

193193
if (m_LayoutStripsOnRight == null)
194194
m_LayoutStripsOnRight = new Layout();
195195

196196
if (m_LayoutStripsOnRight.m_HorizontalSplitter == null || m_LayoutStripsOnRight.m_HorizontalSplitter.realSizes.Length != 2)
197-
m_LayoutStripsOnRight.m_HorizontalSplitter = new SplitterState(new int[] { 30, 70 }, new int[] { 160, 160 }, null);
197+
m_LayoutStripsOnRight.m_HorizontalSplitter = SplitterState.FromAbsolute(new float[] { 30, 70 }, new float[] { 160, 160 }, null);
198198

199199
if (m_LayoutStripsOnRight.m_VerticalSplitter == null || m_LayoutStripsOnRight.m_VerticalSplitter.realSizes.Length != 4)
200-
m_LayoutStripsOnRight.m_VerticalSplitter = new SplitterState(new int[] { 60, 60, 60, 60 }, new int[] { 100, 85, 85, 85 }, null);
200+
m_LayoutStripsOnRight.m_VerticalSplitter = SplitterState.FromAbsolute(new float[] { 60, 60, 60, 60 }, new float[] { 100, 85, 85, 85 }, null);
201201

202202
if (m_AudioGroupTreeState == null)
203203
m_AudioGroupTreeState = new TreeViewState();

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Styles
2929
{
3030
public GUIContent invalidColorSpaceMessage = EditorGUIUtility.TrTextContent("In order to build a player, go to 'Player Settings...' to resolve the incompatibility between the Color Space and the current settings.", EditorGUIUtility.GetHelpIcon(MessageType.Warning));
3131
public GUIContent invalidLightmapEncodingMessage = EditorGUIUtility.TrTextContent("In order to build a player, go to 'Player Settings...' to resolve the incompatibility between the selected Lightmap Encoding and the current settings.", EditorGUIUtility.GetHelpIcon(MessageType.Warning));
32+
public GUIContent invalidVirtualTexturingSettingMessage = EditorGUIUtility.TrTextContent("Cannot build player because Virtual Texturing is enabled, but the target platform or graphics API does not support Virtual Texturing. Go to Player Settings to resolve the incompatibility.", EditorGUIUtility.GetHelpIcon(MessageType.Warning));
3233
public GUIContent compilingMessage = EditorGUIUtility.TrTextContent("Cannot build player while editor is importing assets or compiling scripts.", EditorGUIUtility.GetHelpIcon(MessageType.Warning));
3334
public GUIStyle title = EditorStyles.boldLabel;
3435
public GUIStyle evenRow = "CN EntryBackEven";
@@ -44,6 +45,7 @@ class Styles
4445
public GUIContent addOpenSource = EditorGUIUtility.TrTextContent("Add Open Scenes");
4546
public string noModuleLoaded = L10n.Tr("No {0} module loaded.");
4647
public GUIContent openDownloadPage = EditorGUIUtility.TrTextContent("Open Download Page");
48+
public GUIContent installModuleWithHub = EditorGUIUtility.TrTextContent("Install with Unity Hub");
4749
public string infoText = L10n.Tr("{0} is not included in your Unity Pro license. Your {0} build will include a Unity Personal Edition splash screen.\n\nYou must be eligible to use Unity Personal Edition to use this build option. Please refer to our EULA for further information.");
4850
public GUIContent eula = EditorGUIUtility.TrTextContent("Eula");
4951
public string addToYourPro = L10n.Tr("Add {0} to your Unity Pro license");
@@ -95,6 +97,8 @@ public GUIContent GetDownloadErrorForTarget(BuildTarget target)
9597

9698
static Styles styles = null;
9799

100+
static bool isEditorinstalledWithHub = IsEditorInstalledWithHub();
101+
98102
public static void ShowBuildPlayerWindow()
99103
{
100104
EditorUserBuildSettings.selectedBuildTargetGroup = EditorUserBuildSettings.activeBuildTargetGroup;
@@ -454,6 +458,28 @@ static bool IsLightmapEncodingValid(BuildPlatform platform)
454458
}
455459
}
456460

461+
static bool IsVirtualTexturingSettingsValid(BuildPlatform platform)
462+
{
463+
if (!PlayerSettings.GetVirtualTexturingSupportEnabled())
464+
{
465+
return true;
466+
}
467+
468+
if (!UnityEngine.Rendering.VirtualTexturingEditor.Building.IsPlatformSupportedForPlayer(platform.defaultTarget))
469+
{
470+
return false;
471+
}
472+
473+
GraphicsDeviceType[] gfxTypes = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget);
474+
bool supportedAPI = true;
475+
foreach (GraphicsDeviceType api in gfxTypes)
476+
{
477+
supportedAPI &= UnityEngine.Rendering.VirtualTexturingEditor.Building.IsRenderAPISupported(api, platform.defaultTarget, false);
478+
}
479+
480+
return supportedAPI;
481+
}
482+
457483
// Major.Minor.Micro followed by one of abxfp followed by an identifier, optionally suffixed with " (revisionhash)"
458484
static Regex s_VersionPattern = new Regex(@"(?<shortVersion>\d+\.\d+\.\d+(?<suffix>((?<alphabeta>[abx])|[fp])[^\s]*))( \((?<revision>[a-fA-F\d]+)\))?",
459485
RegexOptions.Compiled);
@@ -524,6 +550,26 @@ static public string GetPlaybackEngineDownloadURL(string moduleName)
524550
return string.Format("http://{0}.unity3d.com/{1}/{2}/{3}/UnitySetup-{4}-Support-for-Editor-{5}{6}", prefix, suffix, revision, folder, moduleName, shortVersion, extension);
525551
}
526552

553+
static string GetUnityHubModuleDownloadURL(string moduleName)
554+
{
555+
string fullVersion = InternalEditorUtility.GetFullUnityVersion();
556+
string revision = "";
557+
string shortVersion = "";
558+
Match versionMatch = s_VersionPattern.Match(fullVersion);
559+
if (!versionMatch.Success || !versionMatch.Groups["shortVersion"].Success || !versionMatch.Groups["suffix"].Success)
560+
Debug.LogWarningFormat("Error parsing version '{0}'", fullVersion);
561+
562+
if (versionMatch.Groups["shortVersion"].Success)
563+
shortVersion = versionMatch.Groups["shortVersion"].Value;
564+
if (versionMatch.Groups["revision"].Success)
565+
revision = versionMatch.Groups["revision"].Value;
566+
567+
if (s_ModuleNames.ContainsKey(moduleName))
568+
moduleName = s_ModuleNames[moduleName];
569+
570+
return string.Format("unityhub://{0}/{1}/module={2}", shortVersion, revision, moduleName.ToLower());
571+
}
572+
527573
bool IsModuleNotInstalled(BuildTargetGroup buildTargetGroup, BuildTarget buildTarget)
528574
{
529575
bool licensed = BuildPipeline.LicenseCheck(buildTarget);
@@ -537,6 +583,21 @@ bool IsModuleNotInstalled(BuildTargetGroup buildTargetGroup, BuildTarget buildTa
537583
!IsAnyStandaloneModuleLoaded());
538584
}
539585

586+
static bool IsEditorInstalledWithHub()
587+
{
588+
var applicationFolderPath = Directory.GetParent(EditorApplication.applicationPath).FullName;
589+
var path = "";
590+
591+
if (Application.platform == RuntimePlatform.OSXEditor)
592+
path = Path.Combine(applicationFolderPath, "modules.json");
593+
else if (Application.platform == RuntimePlatform.WindowsEditor)
594+
path = Path.Combine(Directory.GetParent(applicationFolderPath).FullName, "modules.json");
595+
else if (Application.platform == RuntimePlatform.LinuxEditor)
596+
path = Path.Combine(Directory.GetParent(applicationFolderPath).FullName, "modules.json");
597+
598+
return System.IO.File.Exists(path);
599+
}
600+
540601
void ShowBuildTargetSettings()
541602
{
542603
EditorGUIUtility.labelWidth = Mathf.Min(180, (position.width - 265) * 0.47f);
@@ -572,10 +633,23 @@ void ShowBuildTargetSettings()
572633
if (IsModuleNotInstalled(buildTargetGroup, buildTarget))
573634
{
574635
GUILayout.Label(EditorGUIUtility.TextContent(string.Format(styles.noModuleLoaded, BuildPlatforms.instance.GetModuleDisplayName(buildTargetGroup, buildTarget))));
575-
if (GUILayout.Button(styles.openDownloadPage, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
636+
string url = "";
637+
638+
if (!isEditorinstalledWithHub || (moduleName == "PS4" || moduleName == "XboxOne"))
639+
{
640+
if (GUILayout.Button(styles.openDownloadPage, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
641+
{
642+
url = GetPlaybackEngineDownloadURL(moduleName);
643+
Help.BrowseURL(url);
644+
}
645+
}
646+
else
576647
{
577-
string url = GetPlaybackEngineDownloadURL(moduleName);
578-
Help.BrowseURL(url);
648+
if (GUILayout.Button(styles.installModuleWithHub, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
649+
{
650+
url = GetUnityHubModuleDownloadURL(moduleName);
651+
Help.BrowseURL(url);
652+
}
579653
}
580654
GUIBuildButtons(false, false, false, platform);
581655
return;
@@ -855,6 +929,12 @@ private static void GUIBuildButtons(IBuildWindowExtension buildWindowExtension,
855929
enableBuildButton = false;
856930
EditorGUILayout.HelpBox(styles.invalidLightmapEncodingMessage);
857931
}
932+
else if (!IsVirtualTexturingSettingsValid(platform) && enableBuildButton && enableBuildAndRunButton)
933+
{
934+
enableBuildAndRunButton = false;
935+
enableBuildButton = false;
936+
EditorGUILayout.HelpBox(styles.invalidVirtualTexturingSettingMessage);
937+
}
858938

859939
if (EditorApplication.isCompiling || EditorApplication.isUpdating)
860940
{

Editor/Mono/ConsoleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static void UpdateLogStyleFixedHeights()
128128

129129
Vector2 m_TextScroll = Vector2.zero;
130130

131-
SplitterState spl = new SplitterState(new float[] {70, 30}, new int[] {32, 32}, null);
131+
SplitterState spl = SplitterState.FromRelative(new float[] {70, 30}, new float[] {32, 32}, null);
132132

133133
static bool ms_LoadedIcons = false;
134134
static internal Texture2D iconInfo, iconWarn, iconError;

Editor/Mono/ContainerWindow.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
119119

120120
// Fit window to screen - needs to be done after bringing the window live
121121
position = FitWindowRectToScreen(m_PixelRect, true, false);
122-
rootView.position = new Rect(0, 0, Mathf.Ceil(m_PixelRect.width), Mathf.Ceil(m_PixelRect.height));
122+
rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width), GUIUtility.RoundToPixelGrid(m_PixelRect.height));
123123
rootView.Reflow();
124124
}
125125

@@ -165,7 +165,7 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
165165

166166
// Fit window to screen - needs to be done after bringing the window live
167167
position = FitWindowRectToScreen(m_PixelRect, true, useMousePos);
168-
rootView.position = new Rect(0, 0, Mathf.Ceil(m_PixelRect.width), Mathf.Ceil(m_PixelRect.height));
168+
rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width), GUIUtility.RoundToPixelGrid(m_PixelRect.height));
169169

170170
rootView.Reflow();
171171

@@ -322,7 +322,13 @@ internal void OnResize()
322322
{
323323
if (rootView == null)
324324
return;
325-
rootView.position = new Rect(0, 0, Mathf.Ceil(position.width), Mathf.Ceil(position.height));
325+
326+
// Depending on the context, GUIUtility.pixelsPerPoint isn't reliable at this point, so we must not round.
327+
// Anyway the backend is responsible of providing a window size that is aligned with the pixel grid, so it
328+
// shouldn't be necessary. In the past position.width and position.height were rounded. When moving a window
329+
// from a monitor that had a given scaling to another monitor with a different scaling, this could cause the
330+
// original pixelsPerPoint to be used. As a result, black borders could appear for the first frame.
331+
rootView.position = new Rect(0, 0, position.width, position.height);
326332

327333
// save position
328334
Save();

Editor/Mono/EditorGUI.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5807,9 +5807,11 @@ public static Rect PrefixLabel(Rect totalPosition, int id, GUIContent label, GUI
58075807

58085808
internal static bool UseVTMaterial(Texture texture)
58095809
{
5810+
if (PlayerSettings.GetVirtualTexturingSupportEnabled() == false)
5811+
return false;
58105812
Texture2D tex2d = texture as Texture2D;
58115813
int tileSize = VirtualTexturing.EditorHelpers.tileSize;
5812-
return PlayerSettings.GetVirtualTexturingSupportEnabled() && tex2d != null && tex2d.vtOnly && tex2d.width > tileSize && tex2d.height > tileSize;
5814+
return tex2d != null && tex2d.vtOnly && tex2d.width > tileSize && tex2d.height > tileSize;
58135815
}
58145816

58155817
internal static Rect MultiFieldPrefixLabel(Rect totalPosition, int id, GUIContent label, int columns)

Editor/Mono/EditorResources.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5+
//#define DEBUG_EDITOR_RESOURCES // ONLY NEEDED BY STYLING DEVS AND DESIGNERS.
6+
57
using System;
68
using System.Collections.Generic;
79
using System.IO;
@@ -114,12 +116,14 @@ public static FontDef CreateSystemFont(string fontName)
114116
public partial class EditorResources
115117
{
116118
private const string k_PrefsUserFontKey = "user_editor_font";
119+
const string k_GlobalStyleCatalogCacheFilePath = "Library/Style.catalog";
120+
117121
private static StyleCatalog s_StyleCatalog;
118122
private static bool s_RefreshGlobalStyleCatalog = false;
119123

120124
static class Constants
121125
{
122-
public static bool isDarkTheme = EditorGUIUtility.isProSkin;
126+
public static bool isDarkTheme => EditorGUIUtility.isProSkin;
123127
}
124128

125129
// Global editor styles
@@ -313,7 +317,7 @@ internal static void BuildCatalog()
313317

314318
bool rebuildCatalog = true;
315319
string catalogHash = ComputeCatalogHash(paths);
316-
const string k_GlobalStyleCatalogCacheFilePath = "Library/Style.catalog";
320+
317321
if (!forceRebuild && File.Exists(k_GlobalStyleCatalogCacheFilePath))
318322
{
319323
using (var cacheCatalogStream = new FileStream(k_GlobalStyleCatalogCacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
@@ -387,22 +391,6 @@ internal static List<GUIStyle> GetExtendedStylesFromSkin(GUISkin skin)
387391
return extendedStyles;
388392
}
389393

390-
/* ONLY NEEDED BY STYLING DEVS AND DESIGNERS.
391-
[MenuItem("Theme/Refresh Styles &r", priority = 420)]
392-
internal static void RefreshStyles()
393-
{
394-
Unsupported.ClearSkinCache();
395-
EditorUtility.RequestScriptReload();
396-
InternalEditorUtility.RepaintAllViews();
397-
Debug.Log($"Style refreshed {DateTime.Now}");
398-
}
399-
400-
[MenuItem("Theme/Switch Theme And Repaint", priority = 420)]
401-
internal static void SwitchTheme()
402-
{
403-
AssetPreview.ClearTemporaryAssetPreviews();
404-
InternalEditorUtility.SwitchSkinAndRepaintAllViews();
405-
}*/
406394

407395
private static void UpdateGUIStyleProperties(string name, GUIStyle style)
408396
{

0 commit comments

Comments
 (0)