Skip to content

Commit 59490f1

Browse files
author
Unity Technologies
committed
Unity 2020.2.0a10 C# reference source code
1 parent b376c3a commit 59490f1

File tree

182 files changed

+7095
-494
lines changed

Some content is hidden

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

182 files changed

+7095
-494
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/AssetPostprocessor.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ internal class PostprocessStack
223223
static string m_TextureProcessorsHashString = null;
224224
static string m_AudioProcessorsHashString = null;
225225
static string m_SpeedTreeProcessorsHashString = null;
226+
static string m_PrefabProcessorsHashString = null;
226227

227228
static Type[] GetCachedAssetPostprocessorClasses()
228229
{
@@ -564,6 +565,48 @@ static void PostprocessAudio(AudioClip clip, string pathName)
564565
CallPostProcessMethods("OnPostprocessAudio", args);
565566
}
566567

568+
[RequiredByNativeCode]
569+
static string GetPrefabProcessorsHashString()
570+
{
571+
if (m_PrefabProcessorsHashString != null)
572+
return m_PrefabProcessorsHashString;
573+
574+
var versionsByType = new SortedList<string, uint>();
575+
576+
foreach (var assetPostprocessorClass in GetCachedAssetPostprocessorClasses())
577+
{
578+
try
579+
{
580+
var inst = Activator.CreateInstance(assetPostprocessorClass) as AssetPostprocessor;
581+
var type = inst.GetType();
582+
bool hasPostProcessMethod = type.GetMethod("OnPostprocessPrefab", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
583+
uint version = inst.GetVersion();
584+
if (version != 0 && hasPostProcessMethod)
585+
{
586+
versionsByType.Add(type.FullName, version);
587+
}
588+
}
589+
catch (MissingMethodException)
590+
{
591+
LogPostProcessorMissingDefaultConstructor(assetPostprocessorClass);
592+
}
593+
catch (Exception e)
594+
{
595+
Debug.LogException(e);
596+
}
597+
}
598+
599+
m_PrefabProcessorsHashString = BuildHashString(versionsByType);
600+
return m_PrefabProcessorsHashString;
601+
}
602+
603+
[RequiredByNativeCode]
604+
static void PostprocessPrefab(GameObject prefabAssetRoot)
605+
{
606+
object[] args = { prefabAssetRoot };
607+
CallPostProcessMethods("OnPostprocessPrefab", args);
608+
}
609+
567610
[RequiredByNativeCode]
568611
static void PostprocessAssetbundleNameChanged(string assetPath, string prevoiusAssetBundleName, string newAssetBundleName)
569612
{

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/BuildPipeline.bindings.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Mono.Cecil;
1212
using UnityEditor.Scripting.ScriptCompilation;
1313
using System.Runtime.InteropServices;
14+
using UnityEngine.Scripting;
1415

1516
namespace UnityEditor
1617
{
@@ -201,6 +202,14 @@ internal struct BuildPlayerDataOptions
201202
public string[] extraScriptingDefines { get; set; }
202203
}
203204

205+
// Keep in sync with Runtime\Network\PlayerCommunicator\PlayerConnectionTypes.h
206+
public enum PlayerConnectionInitiateMode
207+
{
208+
None,
209+
PlayerConnectsToHost,
210+
PlayerListens
211+
}
212+
204213
// Lets you programmatically build players or AssetBundles which can be loaded from the web.
205214
[NativeHeader("Editor/Mono/BuildPipeline.bindings.h")]
206215
[StaticAccessor("BuildPipeline", StaticAccessorType.DoubleColon)]
@@ -606,5 +615,43 @@ internal static string[] GetReferencingPlayerAssembliesForDLL(string dllPath, st
606615
}
607616

608617
internal static extern string[] GetManagedPlayerDllPaths(string assembliesOutputPath);
618+
619+
[RequiredByNativeCode]
620+
public static PlayerConnectionInitiateMode GetPlayerConnectionInitiateMode(BuildTarget targetPlatform, BuildOptions buildOptions)
621+
{
622+
bool connectProfilerOnStartup = (buildOptions & BuildOptions.ConnectWithProfiler) != 0;
623+
624+
bool connect = (buildOptions & BuildOptions.ConnectToHost) != 0 || (connectProfilerOnStartup && DoesBuildTargetSupportPlayerConnectionPlayerToEditor(targetPlatform));
625+
return connect ? PlayerConnectionInitiateMode.PlayerConnectsToHost : PlayerConnectionInitiateMode.PlayerListens;
626+
}
627+
628+
[RequiredByNativeCode]
629+
private static bool DoesBuildTargetSupportPlayerConnectionPlayerToEditor(BuildTarget targetPlatform)
630+
{
631+
return
632+
// Android: support connection from player to Editor in both cases
633+
// connecting to 127.0.0.1 (when both Editor and Android are on localhost using USB cable)
634+
// connecting to <ip of machine where the Editor is running>, the Android and PC has to be on the same subnet
635+
// Update: Disabling this for now, even though player-to-editor works fine on Android, but there are zillion not centralized places in testing framework
636+
// where it assumes Android can only listen. You can still pass BuildOptions.ConnectToHost, to force player-to-editor connection. But AutoConnect Profiler option
637+
// will keep using Listen mode for now
638+
//targetPlatform == BuildTarget.Android ||
639+
// WebGL: only supports connecting from player to editor, so always use this when profiling is set up in WebGL.
640+
targetPlatform == BuildTarget.WebGL ||
641+
// WSA: When Editor and Windows Store Apps are running on the same device, only connection from Player-To-Editor works
642+
// Editor-To-Player doesn't work, seems something is wrong with listening. For ex.,
643+
// when player starts, it's starts listening to 10.37.1.227:55207, this is an ip of the machine the application is running on
644+
// On the same machine editor is running, and editor simply cannot connect. Tried http://www.nirsoft.net/utils/cports.html, and shows that there's no application listening to that port...
645+
// Update: This is actually mentioned in the docs https://msdn.microsoft.com/en-us/library/windows/apps/Hh780593.aspx -
646+
// 'Windows Runtime app can use an IP loopback only as the target address for a client network request. So a Windows Runtime app that uses a DatagramSocket or StreamSocketListener to listen on an IP loopback address is prevented from receiving any incoming packets.'
647+
// Note: if application is launched on another device, and starts lisenting, then the Editor will be able to connect
648+
targetPlatform == BuildTarget.WSAPlayer;
649+
}
650+
651+
[RequiredByNativeCode]
652+
private static bool DoesBuildTargetSupportPlayerConnectionListening(BuildTarget platform)
653+
{
654+
return platform != BuildTarget.WebGL;
655+
}
609656
}
610657
}

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/FileUtil.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private static void CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptio
115115
[FreeFunction("GetPathNameExtensionManaged")]
116116
internal static extern string GetPathExtension(string path);
117117

118-
[FreeFunction("DeletePathNameExtension")]
118+
[FreeFunction("DeletePathNameExtensionManaged")]
119119
internal static extern string GetPathWithoutExtension(string path);
120120

121121
[FreeFunction]

Editor/Mono/GUI/ColorPicker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ void DoColorSliders(float availableWidth)
743743
if (Event.current.type == EventType.Repaint)
744744
{
745745
var backgroundRect = rect;
746-
backgroundRect.xMin += EditorGUIUtility.labelWidth;
746+
backgroundRect.xMin += EditorGUIUtility.labelWidth + Styles.sliderBackground.padding.horizontal;
747747
backgroundRect.xMax -= EditorGUIUtility.fieldWidth + EditorGUI.kSpacing;
748748
backgroundRect = Styles.sliderBackground.padding.Remove(backgroundRect);
749749
var uvLayout = new Rect

Editor/Mono/GUI/DockArea.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ protected override void OldOnGUI()
328328

329329
Rect dockAreaRect = new Rect(0, 0, position.width, position.height);
330330
Rect containerWindowPosition = window.position;
331-
containerWindowPosition.width = Mathf.Ceil(containerWindowPosition.width);
332-
containerWindowPosition.height = Mathf.Ceil(containerWindowPosition.height);
331+
containerWindowPosition.width = GUIUtility.RoundToPixelGrid(containerWindowPosition.width);
332+
containerWindowPosition.height = GUIUtility.RoundToPixelGrid(containerWindowPosition.height);
333333

334334
DrawDockAreaBackground(dockAreaRect);
335335

@@ -1029,19 +1029,19 @@ internal RectOffset GetBorderSizeInternal()
10291029
return m_BorderSize;
10301030

10311031
Rect containerWindowPosition = window.position;
1032-
containerWindowPosition.width = Mathf.FloorToInt(containerWindowPosition.width);
1033-
containerWindowPosition.height = Mathf.FloorToInt(containerWindowPosition.height);
1032+
containerWindowPosition.width = GUIUtility.RoundToPixelGrid(containerWindowPosition.width);
1033+
containerWindowPosition.height = GUIUtility.RoundToPixelGrid(containerWindowPosition.height);
10341034

10351035
bool customBorder = floatingWindow && windowPosition.y == 0;
1036-
bool isBottomTab = windowPosition.yMax == containerWindowPosition.height;
1036+
bool isBottomTab = Mathf.Abs(windowPosition.yMax - containerWindowPosition.height) < 0.02f;
10371037

10381038
// Reset
10391039
m_BorderSize.left = m_BorderSize.right = m_BorderSize.top = m_BorderSize.bottom = 0;
10401040

10411041
Rect r = windowPosition;
10421042
if (r.xMin != 0)
10431043
m_BorderSize.left += (int)kSideBorders;
1044-
if (r.xMax != Mathf.FloorToInt(window.position.width))
1044+
if (Mathf.Abs(r.xMax - GUIUtility.RoundToPixelGrid(window.position.width)) > 0.02f)
10451045
m_BorderSize.right += (int)kSideBorders;
10461046

10471047
m_BorderSize.top = (int)kTabHeight + (customBorder ? kFloatingWindowTopBorderWidth : 0);

Editor/Mono/GUI/SplitView.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ public ExtraDropInfo(bool rootWindow, ViewEdge edge, int index)
7272

7373
void SetupSplitter()
7474
{
75-
int[] actualSizes = new int[children.Length];
76-
int[] minSizes = new int[children.Length];
75+
float[] actualSizes = new float[children.Length];
76+
float[] minSizes = new float[children.Length];
7777

7878
for (int j = 0; j < children.Length; j++)
7979
{
8080
View c = (View)children[j];
81-
actualSizes[j] = vertical ? (int)c.position.height : (int)c.position.width;
82-
minSizes[j] = (int)(vertical ? c.minSize.y : c.minSize.x);
81+
actualSizes[j] = GUIUtility.RoundToPixelGrid(vertical ? c.position.height : c.position.width);
82+
minSizes[j] = GUIUtility.RoundToPixelGrid(vertical ? c.minSize.y : c.minSize.x);
8383
}
8484

85-
splitState = new SplitterState(actualSizes, minSizes, null);
85+
splitState = SplitterState.FromAbsolute(actualSizes, minSizes, null);
8686
splitState.splitSize = 10;
8787
}
8888

@@ -93,8 +93,8 @@ void SetupRectsFromSplitter()
9393

9494
float cursor = 0;
9595

96-
int total = 0;
97-
foreach (int size in splitState.realSizes)
96+
float total = 0;
97+
foreach (float size in splitState.realSizes)
9898
{
9999
total += size;
100100
}
@@ -107,7 +107,7 @@ void SetupRectsFromSplitter()
107107
SavedGUIState state = SavedGUIState.Create();
108108

109109
for (int i = 0; i < children.Length; i++)
110-
cursor += PlaceView(i, cursor, Mathf.Round(splitState.realSizes[i] * scale));
110+
cursor += PlaceView(i, cursor, GUIUtility.RoundToPixelGrid(splitState.realSizes[i] * scale));
111111

112112
state.ApplyAndForget();
113113
}
@@ -156,16 +156,16 @@ internal override void Reflow()
156156

157157
for (int k = 0; k < children.Length - 1; k++)
158158
splitState.DoSplitter(k, k + 1, 0);
159-
splitState.RelativeToRealSizes(vertical ? Mathf.RoundToInt(position.height) : Mathf.RoundToInt(position.width));
159+
splitState.RelativeToRealSizes(vertical ? GUIUtility.RoundToPixelGrid(position.height) : GUIUtility.RoundToPixelGrid(position.width));
160160
SetupRectsFromSplitter();
161161
}
162162

163163
float PlaceView(int i, float pos, float size)
164164
{
165165
float width = position.width;
166166
float height = position.height;
167-
float roundPos = Mathf.Round(pos);
168-
float roundSize = Mathf.Round(size);
167+
float roundPos = GUIUtility.RoundToPixelGrid(pos);
168+
float roundSize = GUIUtility.RoundToPixelGrid(size);
169169
Rect newRect;
170170
if (vertical)
171171
{
@@ -672,7 +672,8 @@ public void SplitGUI(Event evt)
672672
case EventType.MouseDown:
673673
if (children.Length != 1) // is there a splitter
674674
{
675-
int cursor = vertical ? (int)children[0].position.y : (int)children[0].position.x;
675+
float cursor = vertical ? children[0].position.y : children[0].position.x;
676+
cursor = GUIUtility.RoundToPixelGrid(cursor);
676677

677678
for (int i = 0; i < children.Length - 1; i++)
678679
{
@@ -694,7 +695,7 @@ public void SplitGUI(Event evt)
694695

695696
if (GUIUtility.HitTest(splitterRect, evt))
696697
{
697-
splitState.splitterInitialOffset = (int)pos;
698+
splitState.splitterInitialOffset = GUIUtility.RoundToPixelGrid(pos);
698699
splitState.currentActiveSplitter = i;
699700
GUIUtility.hotControl = id;
700701
evt.Use();
@@ -708,11 +709,10 @@ public void SplitGUI(Event evt)
708709
case EventType.MouseDrag:
709710
if (children.Length > 1 && (GUIUtility.hotControl == id) && (splitState.currentActiveSplitter >= 0))
710711
{
711-
int diff = (int)pos - splitState.splitterInitialOffset;
712-
713-
if (diff != 0)
712+
float diff = GUIUtility.RoundToPixelGrid(pos) - splitState.splitterInitialOffset;
713+
if (Mathf.Abs(diff) > 0.01f)
714714
{
715-
splitState.splitterInitialOffset = (int)pos;
715+
splitState.splitterInitialOffset = GUIUtility.RoundToPixelGrid(pos);
716716
splitState.DoSplitter(splitState.currentActiveSplitter, splitState.currentActiveSplitter + 1, diff);
717717
}
718718

0 commit comments

Comments
 (0)