Skip to content

Commit 8a74505

Browse files
author
Unity Technologies
committed
Unity 2023.1.0b1 C# reference source code
1 parent a2bdfe9 commit 8a74505

File tree

72 files changed

+935
-848
lines changed

Some content is hidden

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

72 files changed

+935
-848
lines changed

Editor/Mono/Annotation/SceneFXWindow.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using UnityEngine;
7+
using UnityEngine.Rendering;
78

89
namespace UnityEditor
910
{
@@ -74,6 +75,12 @@ private void Draw(Rect rect)
7475
DrawListElement(drawPos, "Skybox", state.showSkybox, value => state.showSkybox = value);
7576
drawPos.y += EditorGUI.kSingleLineHeight;
7677

78+
if(SupportedRenderingFeatures.active.supportsClouds)
79+
{
80+
DrawListElement(drawPos, "Clouds", state.showClouds, value => state.showClouds = value);
81+
drawPos.y += EditorGUI.kSingleLineHeight;
82+
}
83+
7784
DrawListElement(drawPos, "Fog", state.showFog, value => state.showFog = value);
7885
drawPos.y += EditorGUI.kSingleLineHeight;
7986

Editor/Mono/ContainerWindow.cs

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,23 @@ internal partial class ContainerWindow : ScriptableObject
3838
internal const float kButtonWidth = 16f, kButtonHeight = 16f;
3939

4040
static internal bool macEditor => Application.platform == RuntimePlatform.OSXEditor;
41-
static internal bool linuxEditor => Application.platform == RuntimePlatform.LinuxEditor;
4241

4342
static internal bool s_Modal = false;
4443
private static ContainerWindow s_MainWindow;
4544
static internal ContainerWindow mainWindow { get => s_MainWindow; }
4645

4746
private static class Styles
4847
{
49-
// Title Bar Buttons (Non)
50-
public static GUIStyle buttonMin = "WinBtnMinMac";
51-
public static GUIStyle buttonClose = macEditor ? "WinBtnCloseMac" : "WinBtnClose";
52-
public static GUIStyle buttonMax = macEditor ? "WinBtnMaxMac" : "WinBtnMax";
53-
public static GUIStyle buttonRestore = macEditor ? "WinBtnRestoreMac" : "WinBtnRestore";
54-
5548
public static float borderSize => macEditor ? osxBorderSize : winBorderSize;
5649
public static float buttonMargin => macEditor ? osxBorderMargin : winBorderMargin;
5750

58-
public static SVC<float> buttonTop = new SVC<float>("--container-window-button-top-margin");
59-
6051
private static SVC<float> winBorderSize = new SVC<float>("--container-window-buttons-right-margin-win");
6152
private static SVC<float> osxBorderSize = new SVC<float>("--container-window-buttons-right-margin-osx");
6253
private static SVC<float> winBorderMargin = new SVC<float>("--container-window-button-left-right-margin-win");
6354
private static SVC<float> osxBorderMargin = new SVC<float>("--container-window-button-left-right-margin-osx");
6455
}
65-
66-
private const float kButtonCountOSX = 0;
67-
private const float kButtonCountWin = 2;
6856
static internal float buttonHorizontalSpace => (kButtonWidth + Styles.buttonMargin * 2f);
69-
static internal float buttonStackWidth => buttonHorizontalSpace * (macEditor || linuxEditor ? kButtonCountOSX : kButtonCountWin) + Styles.borderSize;
70-
57+
static internal float buttonStackWidth => Styles.borderSize;
7158
public ContainerWindow()
7259
{
7360
m_PixelRect = new Rect(0, 0, 400, 300);
@@ -656,142 +643,5 @@ internal Rect GetDropDownRect(Rect buttonRect, Vector2 minSize, Vector2 maxSize)
656643
return PopupLocationHelper.GetDropDownRect(buttonRect, minSize, maxSize, this);
657644
}
658645

659-
public void HandleWindowDecorationEnd(Rect windowPosition)
660-
{
661-
// No Op
662-
}
663-
664-
public void HandleWindowDecorationStart(Rect windowPosition)
665-
{
666-
if (!macEditor && !linuxEditor)
667-
{
668-
bool hasTitleBar = (windowPosition.y == 0 && (showMode != ShowMode.Utility && showMode != ShowMode.MainWindow) && !isPopup);
669-
670-
if (!hasTitleBar)
671-
return;
672-
673-
bool hasWindowButtons = Mathf.Abs(windowPosition.xMax - position.width) < 2;
674-
if (hasWindowButtons)
675-
{
676-
GUIStyle min = Styles.buttonMin;
677-
GUIStyle close = Styles.buttonClose;
678-
GUIStyle maxOrRestore = maximized ? Styles.buttonRestore : Styles.buttonMax;
679-
680-
BeginTitleBarButtons(windowPosition);
681-
if (TitleBarButton(close))
682-
{
683-
if (InternalRequestClose())
684-
{
685-
Close();
686-
GUIUtility.ExitGUI();
687-
}
688-
}
689-
690-
var canMaximize = m_MaxSize.x == 0 || m_MaxSize.y == 0 || m_MaxSize.x >= Screen.currentResolution.width || m_MaxSize.y >= Screen.currentResolution.height;
691-
EditorGUI.BeginDisabled(!canMaximize);
692-
if (TitleBarButton(maxOrRestore))
693-
ToggleMaximize();
694-
EditorGUI.EndDisabled();
695-
}
696-
697-
DragTitleBar(new Rect(0, 0, position.width, kTitleHeight));
698-
}
699-
}
700-
701-
private void BeginTitleBarButtons(Rect windowPosition)
702-
{
703-
m_ButtonCount = 0;
704-
m_TitleBarWidth = windowPosition.width;
705-
}
706-
707-
private bool TitleBarButton(GUIStyle style)
708-
{
709-
var buttonRect = new Rect(m_TitleBarWidth - Styles.borderSize - (buttonHorizontalSpace * ++m_ButtonCount), Styles.buttonTop, kButtonWidth, kButtonHeight);
710-
var guiView = rootView as GUIView;
711-
if (guiView == null)
712-
{
713-
var splitView = rootView as SplitView;
714-
if (splitView != null)
715-
guiView = splitView.children.Length > 0 ? splitView.children[0] as GUIView : null;
716-
}
717-
if (guiView != null)
718-
guiView.MarkHotRegion(GUIClip.UnclipToWindow(buttonRect));
719-
720-
return GUI.Button(buttonRect, GUIContent.none, style);
721-
}
722-
723-
// Snapping windows
724-
private static Vector2 s_LastDragMousePos;
725-
private float startDragDpi;
726-
727-
// Indicates that we are using the native title bar caption dragging.
728-
private bool m_DraggingNativeTitleBarCaption = false;
729-
730-
private void DragTitleBar(Rect titleBarRect)
731-
{
732-
int id = GUIUtility.GetControlID(FocusType.Passive);
733-
Event evt = Event.current;
734-
735-
switch (evt.GetTypeForControl(id))
736-
{
737-
case EventType.Repaint:
738-
if (m_DraggingNativeTitleBarCaption)
739-
m_DraggingNativeTitleBarCaption = false;
740-
EditorGUIUtility.AddCursorRect(titleBarRect, MouseCursor.Arrow);
741-
break;
742-
case EventType.MouseDown:
743-
// If the mouse is inside the title bar rect, we say that we're the hot control
744-
if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
745-
{
746-
Event.current.Use();
747-
m_DraggingNativeTitleBarCaption = true;
748-
SendCaptionEvent(m_DraggingNativeTitleBarCaption);
749-
}
750-
break;
751-
case EventType.MouseUp:
752-
if (m_DraggingNativeTitleBarCaption)
753-
break;
754-
755-
if (GUIUtility.hotControl == id)
756-
{
757-
GUIUtility.hotControl = 0;
758-
Event.current.Use();
759-
Unsupported.SetAllowCursorLock(true, Unsupported.DisallowCursorLockReasons.SizeMove);
760-
}
761-
break;
762-
case EventType.MouseDrag:
763-
if (m_DraggingNativeTitleBarCaption)
764-
break;
765-
766-
if (GUIUtility.hotControl == id)
767-
{
768-
Vector2 mousePos = evt.mousePosition;
769-
if (startDragDpi != GUIUtility.pixelsPerPoint)
770-
{
771-
// We ignore this mouse event when changing screens in multi monitor setups with
772-
// different dpi scalings as funky things might/will happen
773-
startDragDpi = GUIUtility.pixelsPerPoint;
774-
s_LastDragMousePos = mousePos;
775-
}
776-
else
777-
{
778-
Vector2 movement = mousePos - s_LastDragMousePos;
779-
780-
float minimumDelta = 1.0f / GUIUtility.pixelsPerPoint;
781-
782-
if (Mathf.Abs(movement.x) >= minimumDelta || Mathf.Abs(movement.y) >= minimumDelta)
783-
{
784-
Rect dragPosition = position;
785-
dragPosition.x += movement.x;
786-
dragPosition.y += movement.y;
787-
position = dragPosition;
788-
789-
GUI.changed = true;
790-
}
791-
}
792-
}
793-
break;
794-
}
795-
}
796646
}
797647
} //namespace

Editor/Mono/EditorUtility.bindings.cs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,49 @@ public static string OpenFilePanelWithFilters(string title, string directory, st
3434
public static extern void RevealInFinder(string path);
3535

3636
[FreeFunction("DisplayDialog")]
37-
static extern bool DoDisplayDialog(string title, string message, string ok, [DefaultValue("\"\"")] string cancel);
37+
static extern bool DisplayDialogImpl(string title, string message, string ok, string cancel);
3838

3939
public static bool DisplayDialog(string title, string message, string ok, [DefaultValue("\"\"")] string cancel)
4040
{
41+
// i am not sure how picky should we be about the params
42+
// for example, for the buttons we have code that ignores empty strings,
43+
// to allow having "ok"-only dialogs (information panels, so to say)
44+
// same with title+message: it sounds like we should allow skipping one of those
45+
// hence we make sure that at least one button is present, and some message
46+
// we can go more picky if we want in the future
47+
if(string.IsNullOrEmpty(ok) && string.IsNullOrEmpty(cancel))
48+
throw new ArgumentException("Both 'ok' and 'cancel' strings are null or empty");
49+
if(string.IsNullOrEmpty(title) && string.IsNullOrEmpty(message))
50+
throw new ArgumentException("Both 'title' and 'message' strings are null or empty");
51+
4152
using (new DisabledGuiViewInputScope(GUIView.current, true))
4253
{
43-
return DoDisplayDialog(title, message, ok, cancel);
54+
return DisplayDialogImpl(title, message, ok, cancel);
4455
}
4556
}
46-
47-
[FreeFunction("GetDialogResponse")]
48-
internal static extern bool GetDialogResponse(InteractionContext interactionContext, string title, string message, string ok, [DefaultValue("\"\"")] string cancel);
49-
5057
[ExcludeFromDocs]
5158
public static bool DisplayDialog(string title, string message, string ok)
5259
{
5360
return DisplayDialog(title, message, ok, String.Empty);
5461
}
5562

5663
[FreeFunction("DisplayDialogComplex")]
57-
public static extern int DisplayDialogComplex(string title, string message, string ok, string cancel, string alt);
58-
[FreeFunction("GetDialogResponseComplex")]
59-
internal static extern int GetDialogResponseComplex(InteractionContext interactionContext, string title, string message, string ok, string cancel, string alt);
64+
static extern int DisplayDialogComplexImpl(string title, string message, string ok, string cancel, string alt);
65+
66+
public static int DisplayDialogComplex(string title, string message, string ok, string cancel, string alt)
67+
{
68+
// see the comment above in DisplayDialog
69+
// our implementation allows setting some strings empty (the button will be skipped then)
70+
// but we should totally ensure some buttons are set
71+
72+
if(string.IsNullOrEmpty(ok) && string.IsNullOrEmpty(cancel) && string.IsNullOrEmpty(alt))
73+
throw new ArgumentException("All three 'ok', 'cancel' and 'alt' strings are null or empty");
74+
if(string.IsNullOrEmpty(title) && string.IsNullOrEmpty(message))
75+
throw new ArgumentException("Both 'title' and 'message' strings are null or empty");
76+
77+
return DisplayDialogComplexImpl(title, message, ok, cancel, alt);
78+
}
79+
6080

6181

6282
[FreeFunction("RunOpenFolderPanel")]

Editor/Mono/EditorUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static string GetDialogOptOutMessage(DialogOptOutDecisionType dialogOptOu
8080

8181
public static bool LoadWindowLayout(string path)
8282
{
83-
return WindowLayout.LoadWindowLayout(path, false);
83+
return WindowLayout.TryLoadWindowLayout(path, false);
8484
}
8585

8686
public static void CompressTexture(Texture2D texture, TextureFormat format, TextureCompressionQuality quality)

Editor/Mono/GI/InputExtraction.bindings.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ internal static class InputExtraction
1616
public class SourceMap : IDisposable
1717
{
1818
internal IntPtr m_Ptr;
19+
internal bool m_OwnsPtr;
1920

2021
public SourceMap()
2122
{
2223
m_Ptr = Internal_Create();
24+
m_OwnsPtr = true;
25+
}
26+
public SourceMap(IntPtr ptr)
27+
{
28+
m_Ptr = ptr;
29+
m_OwnsPtr = false;
2330
}
24-
2531
~SourceMap()
2632
{
2733
Destroy();
@@ -35,7 +41,7 @@ public void Dispose()
3541

3642
void Destroy()
3743
{
38-
if (m_Ptr != IntPtr.Zero)
44+
if (m_OwnsPtr && m_Ptr != IntPtr.Zero)
3945
{
4046
Internal_Destroy(m_Ptr);
4147
m_Ptr = IntPtr.Zero;

Editor/Mono/GI/Lightmapping.bindings.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,17 @@ internal static void Internal_CallOnWroteLightingDataAsset()
388388
}
389389

390390
// This event is fired when BakeInput has been populated, but before passing it to Bake().
391-
// Create a LightBaker.BakeInput by passing the IntPtr but don't access it beyond the call-back.
392-
internal static event Action<IntPtr> createdBakeInputForTestingOnly;
391+
// Do not store and access BakeInput beyond the call-back.
392+
internal static event Action<LightBaker.BakeInput, InputExtraction.SourceMap> createdBakeInput;
393393

394-
internal static void Internal_CallOnCreatedBakeInputForTestingOnly(IntPtr ptr)
394+
internal static void Internal_CallOnCreatedBakeInput(IntPtr p_BakeInput, IntPtr p_SourceMap)
395395
{
396-
if (createdBakeInputForTestingOnly != null)
397-
createdBakeInputForTestingOnly(ptr);
396+
if (createdBakeInput != null)
397+
{
398+
using var bakeInput = new LightBaker.BakeInput(p_BakeInput);
399+
using var sourceMap = new InputExtraction.SourceMap(p_SourceMap);
400+
createdBakeInput(bakeInput, sourceMap);
401+
}
398402
}
399403

400404
[System.Obsolete("OnCompletedFunction.completed is obsolete, please use event bakeCompleted instead. ", false)]

Editor/Mono/GUI/AppStatusBar.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ protected override void OldOnGUI()
185185
}
186186
GUILayout.EndHorizontal();
187187

188-
DoWindowDecorationEnd();
189188
EditorGUI.ShowRepaints();
190189
}
191190

Editor/Mono/GUI/DockArea.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,6 @@ private void RemoveNullWindows()
118118
s_GUIContents.Clear();
119119
}
120120

121-
internal override void DoWindowDecorationStart()
122-
{
123-
// On windows, we want both close window and side resizes.
124-
// Titlebar dragging is done at the end, so we can drag next to tabs.
125-
if (window != null)
126-
window.HandleWindowDecorationStart(windowPosition);
127-
}
128-
129-
internal override void DoWindowDecorationEnd()
130-
{
131-
if (window != null)
132-
window.HandleWindowDecorationEnd(windowPosition);
133-
}
134-
135121
protected override void OnDestroy()
136122
{
137123
// Prevents double-destroy that may be indirectly caused if Close() is called by OnLostFocus()

0 commit comments

Comments
 (0)