Skip to content

Commit 6b8303f

Browse files
author
Unity Technologies
committed
Unity 2021.1.0a4 C# reference source code
1 parent 034434b commit 6b8303f

File tree

89 files changed

+4299
-1350
lines changed

Some content is hidden

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

89 files changed

+4299
-1350
lines changed

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ private void LinkOptionsOnGUI()
857857
{
858858
m_State.linkedWithSequencer = false;
859859
m_State.selection = null;
860+
m_State.overrideControlInterface = null;
860861

861862
// Layout has changed, bail out now.
862863
EditorGUIUtility.ExitGUI();

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ private void SetAllowExceed(ref float rangeEnd, ref bool allowExceed, float valu
8888
private float m_MinWidth = 0.05f;
8989
private const float kMinHeight = 0.05f;
9090

91+
private const float k_ScrollStepSize = 10f; // mirrors GUI scrollstepsize as there is no global const for this.
92+
9193
public float minWidth
9294
{
9395
get { return m_MinWidth; }
@@ -712,7 +714,11 @@ public void HandleZoomAndPanEvents(Rect area)
712714
break;
713715
case EventType.ScrollWheel:
714716
if (!area.Contains(Event.current.mousePosition))
717+
{
718+
HandleScrolling(area);
715719
break;
720+
}
721+
716722
if (m_IgnoreScrollWheelUntilClicked && GUIUtility.keyboardControl != id)
717723
break;
718724

@@ -725,6 +731,24 @@ public void HandleZoomAndPanEvents(Rect area)
725731
GUILayout.EndArea();
726732
}
727733

734+
void HandleScrolling(Rect area)
735+
{
736+
if (m_MinimalGUI)
737+
return;
738+
if (m_VSlider && new Rect(area.x + area.width, area.y + GUI.skin.verticalScrollbarUpButton.fixedHeight, vSliderWidth, area.height - (GUI.skin.verticalScrollbarDownButton.fixedHeight + hSliderHeight)).Contains(Event.current.mousePosition))
739+
{
740+
SetTransform(new Vector2(m_Translation.x, m_Translation.y - (Event.current.delta.y * k_ScrollStepSize)), m_Scale);
741+
Event.current.Use();
742+
return;
743+
}
744+
745+
if (m_HSlider && new Rect(area.x + GUI.skin.horizontalScrollbarLeftButton.fixedWidth, area.y + area.height, area.width - (GUI.skin.horizontalScrollbarRightButton.fixedWidth + vSliderWidth), hSliderHeight).Contains(Event.current.mousePosition))
746+
{
747+
SetTransform(new Vector2(m_Translation.x + (Event.current.delta.y * k_ScrollStepSize), m_Translation.y), m_Scale);
748+
Event.current.Use();
749+
}
750+
}
751+
728752
public void EndViewGUI()
729753
{
730754
if (m_MinimalGUI && Event.current.type == EventType.Repaint)

Editor/Mono/Annotation/AnnotationWindow.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ namespace UnityEditor
99
{
1010
internal class AnnotationWindow : EditorWindow
1111
{
12+
private static SavedBool s_ShowTerrainDebugWarnings = new SavedBool("Terrain.ShowDebugWarnings", true);
13+
14+
public static bool ShowTerrainDebugWarnings
15+
{
16+
get => s_ShowTerrainDebugWarnings.value;
17+
set => s_ShowTerrainDebugWarnings.value = value;
18+
}
19+
1220
class Styles
1321
{
1422
public GUIStyle toggle = "Toggle";
@@ -45,6 +53,7 @@ private enum EnabledState
4553
}
4654

4755
const float kWindowWidth = 270;
56+
const float kLabelWidth = 150;
4857
const float scrollBarWidth = 14;
4958
const float listElementHeight = 18;
5059
float iconSize = 16;
@@ -70,6 +79,7 @@ private enum EnabledState
7079
GUIContent iconToggleContent = EditorGUIUtility.TrTextContent("", "Show/Hide Icon");
7180
GUIContent iconSelectContent = EditorGUIUtility.TrTextContent("", "Select Icon");
7281
GUIContent icon3dGizmoContent = EditorGUIUtility.TrTextContent("3D Icons");
82+
GUIContent terrainDebugWarnings = EditorGUIUtility.TrTextContent("Terrain Debug Warnings");
7383
GUIContent showOutlineContent = EditorGUIUtility.TrTextContent("Selection Outline");
7484
GUIContent showWireframeContent = EditorGUIUtility.TrTextContent("Selection Wire");
7585
GUIContent fadeGizmosContent = EditorGUIUtility.TrTextContent("Fade Gizmos", "Fade out and stop rendering gizmos that are small on screen");
@@ -118,7 +128,7 @@ static public void IconChanged()
118128

119129
float GetTopSectionHeight()
120130
{
121-
const int numberOfControls = 4;
131+
const int numberOfControls = 5;
122132
return EditorGUI.kSingleLineHeight * numberOfControls + EditorGUI.kControlVerticalSpacing * (numberOfControls - 1) + EditorStyles.inspectorBig.padding.bottom;
123133
}
124134

@@ -298,8 +308,7 @@ void DrawTopSection(float topSectionHeight)
298308
float margin = 11;
299309
float curY = topmargin;
300310

301-
302-
float labelWidth = m_Styles.listHeaderStyle.CalcSize(showOutlineContent).x + GUI.skin.toggle.CalcSize(GUIContent.none).x + 1;
311+
float labelWidth = m_Styles.listHeaderStyle.CalcSize(terrainDebugWarnings).x + GUI.skin.toggle.CalcSize(GUIContent.none).x + 1;
303312
float rowHeight = 18;
304313

305314
// 3D icons toggle & slider
@@ -337,14 +346,21 @@ void DrawTopSection(float topSectionHeight)
337346
}
338347
curY += rowHeight;
339348

340-
// Selection outline/wire
341349
using (new EditorGUI.DisabledScope(m_IsGameView))
342350
{
351+
// Selection outline/wire
343352
toggleRect = new Rect(margin, curY, labelWidth, rowHeight);
344353
AnnotationUtility.showSelectionOutline = GUI.Toggle(toggleRect, AnnotationUtility.showSelectionOutline, showOutlineContent);
345354

346355
toggleRect.y += rowHeight;
347356
AnnotationUtility.showSelectionWire = GUI.Toggle(toggleRect, AnnotationUtility.showSelectionWire, showWireframeContent);
357+
358+
// TODO: Change to Debug Errors & Debug Warnings
359+
toggleRect.y += rowHeight;
360+
EditorGUI.BeginChangeCheck();
361+
s_ShowTerrainDebugWarnings.value = GUI.Toggle(toggleRect, s_ShowTerrainDebugWarnings.value, terrainDebugWarnings);
362+
if (EditorGUI.EndChangeCheck())
363+
SceneView.RepaintAll();
348364
}
349365
}
350366

Editor/Mono/AssetPipeline/TextureImporter.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,5 +432,8 @@ public void SetTextureSettings(TextureImporterSettings src)
432432

433433
public extern bool ignorePngGamma { get; set; }
434434
internal static readonly int MaxTextureSizeAllowedForReadable = 8192; //keep in sync with TextureImporter.h
435+
436+
// This is for remapping Sprite that are renamed.
437+
extern internal bool GetNameFromInternalIDMap(long id, ref string name);
435438
}
436439
}

Editor/Mono/AssetsMenuUtility.bindings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ namespace UnityEditor
88
{
99
internal enum ScriptTemplate
1010
{
11-
CSharp_NewBehaviourScript = 0,
11+
CSharp_NewSceneTemplatePipelineScript = 0,
12+
CSharp_NewBehaviourScript,
1213
CSharp_NewTestScript,
1314
Shader_NewSurfaceShader,
1415
Shader_NewUnlitShader,

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public class BuildPipeline
230230
internal static extern string GetBuildTargetGroupDisplayName(BuildTargetGroup targetPlatformGroup);
231231

232232
[FreeFunction("GetBuildTargetUniqueName", IsThreadSafe = true)]
233-
internal static extern string GetBuildTargetName(BuildTarget targetPlatform);
233+
public static extern string GetBuildTargetName(BuildTarget targetPlatform);
234234

235235
[FreeFunction(IsThreadSafe = true)]
236236
internal static extern string GetEditorTargetName();

Editor/Mono/BuildPipeline/DesktopStandaloneBuildWindowExtension.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ internal static BuildTarget GetBestStandaloneTarget(BuildTarget selectedTarget)
5959
if (ModuleManager.IsPlatformSupportLoadedByBuildTarget(selectedTarget))
6060
return selectedTarget;
6161
if (RuntimePlatform.WindowsEditor == Application.platform && ModuleManager.IsPlatformSupportLoadedByBuildTarget(BuildTarget.StandaloneWindows))
62-
return BuildTarget.StandaloneWindows;
62+
return BuildTarget.StandaloneWindows64;
6363
if (RuntimePlatform.OSXEditor == Application.platform && ModuleManager.IsPlatformSupportLoadedByBuildTarget(BuildTarget.StandaloneOSX))
6464
return BuildTarget.StandaloneOSX;
6565
if (ModuleManager.IsPlatformSupportLoadedByBuildTarget(BuildTarget.StandaloneOSX))
6666
return BuildTarget.StandaloneOSX;
6767
if (ModuleManager.IsPlatformSupportLoadedByBuildTarget(BuildTarget.StandaloneLinux64))
6868
return BuildTarget.StandaloneLinux64;
69-
return BuildTarget.StandaloneWindows;
69+
return BuildTarget.StandaloneWindows64;
7070
}
7171

7272
private static Dictionary<GUIContent, BuildTarget> GetArchitecturesForPlatform(BuildTarget target)
@@ -77,8 +77,8 @@ private static Dictionary<GUIContent, BuildTarget> GetArchitecturesForPlatform(B
7777
case BuildTarget.StandaloneWindows64:
7878
return new Dictionary<GUIContent, BuildTarget>()
7979
{
80-
{ EditorGUIUtility.TrTextContent("x86"), BuildTarget.StandaloneWindows },
8180
{ EditorGUIUtility.TrTextContent("x86_64"), BuildTarget.StandaloneWindows64 },
81+
{ EditorGUIUtility.TrTextContent("x86"), BuildTarget.StandaloneWindows },
8282
};
8383
case BuildTarget.StandaloneLinux64:
8484
return new Dictionary<GUIContent, BuildTarget>()
@@ -96,7 +96,7 @@ private static BuildTarget DefaultTargetForPlatform(BuildTarget target)
9696
{
9797
case BuildTarget.StandaloneWindows:
9898
case BuildTarget.StandaloneWindows64:
99-
return BuildTarget.StandaloneWindows;
99+
return BuildTarget.StandaloneWindows64;
100100
// Deprecated
101101
#pragma warning disable 612, 618
102102
case BuildTarget.StandaloneLinux:

Editor/Mono/ContainerWindow.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ internal partial class ContainerWindow : ScriptableObject
3838
static internal bool linuxEditor => Application.platform == RuntimePlatform.LinuxEditor;
3939

4040
static internal bool s_Modal = false;
41+
private static bool hasMainWindow = false;
4142

4243
private static class Styles
4344
{
@@ -111,6 +112,9 @@ internal void ShowTooltip()
111112

112113
internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
113114
{
115+
if (mode == ShowMode.MainWindow)
116+
throw new ArgumentException("Cannot create more than one main window.");
117+
114118
m_ShowMode = (int)mode;
115119
Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);
116120
if (m_RootView)
@@ -133,6 +137,9 @@ internal void ShowPopupWithMode(ShowMode mode, bool giveFocus)
133137
// Show the editor window.
134138
public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately, bool setFocus)
135139
{
140+
if (hasMainWindow && showMode == ShowMode.MainWindow)
141+
throw new InvalidOperationException("Trying to create a second main window from layout when one already exists.");
142+
136143
bool useMousePos = showMode == ShowMode.AuxWindow;
137144
if (showMode == ShowMode.AuxWindow)
138145
showMode = ShowMode.Utility;
@@ -150,7 +157,6 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
150157

151158
var initialMaximizedState = m_Maximized;
152159

153-
154160
Internal_Show(m_PixelRect, m_ShowMode, m_MinSize, m_MaxSize);
155161

156162
// Tell the main view its now in this window (quick hack to get platform-specific code to move its views to the right window)
@@ -166,6 +172,9 @@ public void Show(ShowMode showMode, bool loadPosition, bool displayImmediately,
166172
if (!this)
167173
return;
168174

175+
if (showMode == ShowMode.MainWindow)
176+
hasMainWindow = true;
177+
169178
// Fit window to screen - needs to be done after bringing the window live
170179
position = FitWindowRectToScreen(m_PixelRect, true, useMousePos);
171180
rootView.position = new Rect(0, 0, GUIUtility.RoundToPixelGrid(m_PixelRect.width), GUIUtility.RoundToPixelGrid(m_PixelRect.height));
@@ -280,6 +289,10 @@ private bool PrivateRequestClose(List<EditorWindow> allUnsaved)
280289
internal void InternalCloseWindow()
281290
{
282291
Save();
292+
293+
if (m_ShowMode == (int)ShowMode.MainWindow)
294+
hasMainWindow = false;
295+
283296
if (m_RootView)
284297
{
285298
DestroyImmediate(m_RootView, true);

Editor/Mono/GUI/AboutWindow.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ internal class AboutWindow : EditorWindow
1717
{
1818
static void ShowAboutWindow()
1919
{
20-
AboutWindow w = EditorWindow.GetWindowWithRect<AboutWindow>(new Rect(100, 100, 570, 360), true, "About Unity");
21-
w.position = new Rect(100, 100, 570, 360);
20+
AboutWindow w = EditorWindow.GetWindowWithRect<AboutWindow>(new Rect(100, 100, 600, 360), true, "About Unity");
21+
w.position = new Rect(100, 100, 600, 360);
2222
w.m_Parent.window.m_DontSaveToLayout = true;
2323
}
2424

@@ -151,9 +151,9 @@ public void OnGUI()
151151

152152
GUILayout.BeginHorizontal();
153153
GUILayout.Label(s_MonoLogo);
154-
GUILayout.Label("Scripting powered by The Mono Project.\n\n(c) 2011 Novell, Inc.", "MiniLabel", GUILayout.Width(210));
154+
GUILayout.Label("Scripting powered by The Mono Project.\n\n(c) 2011 Novell, Inc.", "MiniLabel", GUILayout.Width(220));
155155
GUILayout.Label(s_AgeiaLogo);
156-
GUILayout.Label("Physics powered by PhysX.\n\n(c) 2019 NVIDIA Corporation.", "MiniLabel", GUILayout.Width(200));
156+
GUILayout.Label("Physics powered by PhysX.\n\n(c) 2019 NVIDIA Corporation.", "MiniLabel", GUILayout.Width(205));
157157
GUILayout.EndHorizontal();
158158
GUILayout.FlexibleSpace();
159159
GUILayout.BeginHorizontal();

Editor/Mono/GameView/GameView.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ float maxScale
8282
[SerializeField] RenderTexture m_RenderTexture;
8383

8484
int m_SizeChangeID = int.MinValue;
85+
[System.NonSerialized]
86+
bool m_IsRepaintDelegateRegistered = false;
8587

8688
List<XRDisplaySubsystem> m_DisplaySubsystems = new List<XRDisplaySubsystem>();
8789

@@ -291,6 +293,7 @@ public void OnEnable()
291293

292294
public void OnDisable()
293295
{
296+
RemoveRepaintDelegate();
294297
ModeService.modeChanged -= OnEditorModeChanged;
295298
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
296299
if (m_RenderTexture)
@@ -758,13 +761,50 @@ private void OnPlayModeStateChanged(PlayModeStateChange state)
758761
{
759762
// Enable vsync in play mode to get as much as possible frame rate consistency
760763
m_Parent.EnableVSync(m_VSyncEnabled);
764+
RemoveRepaintDelegate();
761765
}
762766
else if (state == PlayModeStateChange.ExitingPlayMode)
763767
{
764768
m_Parent.EnableVSync(false);
769+
AddRepaintDelegate();
765770
}
766771
}
767772

773+
void OnBecameVisible()
774+
{
775+
AddRepaintDelegate();
776+
}
777+
778+
void OnBecameInvisible()
779+
{
780+
RemoveRepaintDelegate();
781+
}
782+
783+
void AddRepaintDelegate()
784+
{
785+
if (!m_IsRepaintDelegateRegistered && !EditorApplication.isPlaying)
786+
{
787+
EditorApplication.update += RepaintIfNeeded;
788+
m_IsRepaintDelegateRegistered = true;
789+
}
790+
}
791+
792+
void RemoveRepaintDelegate()
793+
{
794+
if (m_IsRepaintDelegateRegistered)
795+
{
796+
EditorApplication.update -= RepaintIfNeeded;
797+
m_IsRepaintDelegateRegistered = false;
798+
}
799+
}
800+
801+
void RepaintIfNeeded()
802+
{
803+
UnityEngine.VFX.VFXManager.RequestRepaint();
804+
if (LODUtility.IsLODAnimating(null))
805+
Repaint();
806+
}
807+
768808
private void OnEditorModeChanged(ModeService.ModeChangedArgs args)
769809
{
770810
showToolbar = ModeService.HasCapability(ModeCapability.GameViewToolbar, true);

0 commit comments

Comments
 (0)