Skip to content

Commit 18cc4f6

Browse files
author
Unity Technologies
committed
Unity 2023.2.0a11 C# reference source code
1 parent 313479b commit 18cc4f6

File tree

82 files changed

+1351
-477
lines changed

Some content is hidden

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

82 files changed

+1351
-477
lines changed

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ void AddOpenScenes()
239239
for (int i = 0; i < SceneManager.sceneCount; i++)
240240
{
241241
Scene scene = SceneManager.GetSceneAt(i);
242+
243+
if (EditorSceneManager.IsAuthoringScene(scene))
244+
continue;
245+
242246
if (scene.path.Length == 0 && !EditorSceneManager.SaveScene(scene, "", false))
243247
continue;
244248

Editor/Mono/ConsoleWindow.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ internal static void UpdateLogStyleFixedHeights()
156156
ListViewState m_ListView;
157157
string m_ActiveText = "";
158158
StringBuilder m_CopyString;
159-
private int m_LastPingedEntry = -1;
159+
private int m_LastPingedEntryRow = -1;
160160
bool m_DevBuild;
161161
int m_CallstackTextStart = 0;
162162
private Mode m_ActiveMode = Mode.None;
@@ -453,18 +453,19 @@ void SetActiveEntry(LogEntry entry)
453453
m_ActiveMode = (Mode)entry.mode;
454454
entry.callstackTextStartUTF8 = entry.message.Length;
455455
m_CallstackTextStart = entry.callstackTextStartUTF16;
456+
var entryRow = LogEntries.GetEntryRowIndex(entry.globalLineIndex);
456457
// ping object referred by the log entry
457-
if (entry.instanceID != 0 && m_LastPingedEntry != entry.globalLineIndex)
458+
if (entry.instanceID != 0 && m_LastPingedEntryRow != entryRow)
458459
{
459460
EditorGUIUtility.PingObject(entry.instanceID);
460-
m_LastPingedEntry = entry.globalLineIndex;
461+
m_LastPingedEntryRow = entryRow;
461462
}
462463
}
463464
else
464465
{
465466
m_CallstackTextStart = 0;
466467
m_ActiveText = string.Empty;
467-
m_LastPingedEntry = -1;
468+
m_LastPingedEntryRow = -1;
468469
m_ListView.row = -1;
469470
m_CopyString.Clear();
470471
m_ActiveMode = Mode.None;

Editor/Mono/ContainerWindow.bindings.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ public extern Rect position
7575
[FreeFunction(k_ScriptingPrefix + "SendCaptionEvent", HasExplicitThis = true)]
7676
public extern void SendCaptionEvent(bool mouseDown);
7777

78-
// Close the editor window.
79-
[FreeFunction(k_ScriptingPrefix + "InternalClose", HasExplicitThis = true)]
80-
public extern void InternalClose();
78+
[FreeFunction(k_ScriptingPrefix + "Internal_Destroy", HasExplicitThis = true)]
79+
public extern void Internal_Destroy();
8180

8281
[FreeFunction(k_ScriptingPrefix + "Internal_SetMinMaxSizes", HasExplicitThis = true)]
8382
private extern void Internal_SetMinMaxSizes(Vector2 minSize, Vector2 maxSize);

Editor/Mono/ContainerWindow.cs

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
using System.Runtime.InteropServices;
88
using System.Collections.Generic;
99
using System;
10-
using System.Linq;
10+
using System.Text;
11+
using UnityEngine.Pool;
1112
using UnityEngine.Scripting;
1213

1314
namespace UnityEditor
@@ -66,6 +67,11 @@ internal void __internalAwake()
6667
hideFlags = HideFlags.DontSave;
6768
}
6869

70+
private void OnDestroy()
71+
{
72+
Internal_Destroy();
73+
}
74+
6975
internal ShowMode showMode => (ShowMode)m_ShowMode;
7076

7177
private string m_WindowID = null;
@@ -225,60 +231,69 @@ public void SetMinMaxSizes(Vector2 min, Vector2 max)
225231
Internal_SetMinMaxSizes(min, max);
226232
}
227233

228-
static internal bool InternalRequestCloseAll(bool keepMainWindow)
234+
static internal bool CanCloseAll(bool includeMainWindow)
229235
{
230-
var unsaved = windows
231-
.Where(w => keepMainWindow || w.showMode != ShowMode.MainWindow)
232-
.SelectMany(w => w.m_UnsavedEditorWindows)
233-
.ToList();
236+
using (var pooledObject = ListPool<EditorWindow>.Get(out List<EditorWindow> unsaved))
237+
{
238+
foreach (var window in windows)
239+
{
240+
if (includeMainWindow || window.showMode != ShowMode.MainWindow)
241+
{
242+
unsaved.AddRange(window.m_UnsavedEditorWindows);
243+
}
244+
}
234245

235-
if (unsaved.Any())
236-
return PrivateRequestClose(unsaved);
246+
if (unsaved.Count > 0)
247+
return AskToClose(unsaved);
237248

238-
return true;
249+
return true;
250+
}
239251
}
240252

241-
internal bool InternalRequestClose()
253+
private bool CanClose()
242254
{
243-
if (IsMainWindow())
244-
{
245-
var UnsavedWindows = windows.Where(w => w != s_MainWindow).SelectMany(w => w.m_UnsavedEditorWindows).ToList();
246-
247-
if (UnsavedWindows.Any())
248-
return PrivateRequestClose(UnsavedWindows);
249-
}
250-
if (hasUnsavedChanges)
255+
if (Application.isHumanControllingUs && hasUnsavedChanges)
251256
{
252-
return PrivateRequestClose(m_UnsavedEditorWindows);
257+
return AskToClose(m_UnsavedEditorWindows);
253258
}
254259

255260
return true;
256261
}
257262

258-
internal bool InternalRequestClose(EditorWindow dockedTab)
263+
internal static bool CanClose(EditorWindow dockedTab)
259264
{
260-
if (dockedTab.hasUnsavedChanges)
265+
if (Application.isHumanControllingUs && dockedTab.hasUnsavedChanges)
261266
{
262267
var unsaved = new List<EditorWindow>() { dockedTab };
263-
return PrivateRequestClose(unsaved);
268+
return AskToClose(unsaved);
264269
}
265270

266271
return true;
267272
}
268273

269-
internal bool InternalRequestCloseAllExcept(EditorWindow editorWindow)
274+
internal bool CanCloseAllExcept(EditorWindow editorWindow)
270275
{
271-
var unsaved = m_UnsavedEditorWindows.Where(w => w != editorWindow);
276+
if (!Application.isHumanControllingUs)
277+
return true;
272278

273-
if (unsaved.Any())
274-
return PrivateRequestClose(unsaved.ToList());
279+
using (var pooledObject = ListPool<EditorWindow>.Get(out List<EditorWindow> unsaved))
280+
{
281+
foreach (var w in m_UnsavedEditorWindows)
282+
{
283+
if (w != editorWindow)
284+
unsaved.Add(w);
285+
}
286+
287+
if (unsaved.Count > 0)
288+
return AskToClose(unsaved);
289+
}
275290

276291
return true;
277292
}
278293

279-
internal static bool PrivateRequestClose(List<EditorWindow> allUnsaved)
294+
private static bool AskToClose(List<EditorWindow> allUnsaved)
280295
{
281-
Debug.Assert(allUnsaved.Count > 0);
296+
Debug.Assert(Application.isHumanControllingUs && allUnsaved.Count > 0);
282297

283298
const int kSave = 0;
284299
const int kCancel = 1;
@@ -288,20 +303,28 @@ internal static bool PrivateRequestClose(List<EditorWindow> allUnsaved)
288303

289304
if (allUnsaved.Count == 1)
290305
{
291-
var title = allUnsaved.First().titleContent.text;
306+
var title = allUnsaved[0].titleContent.text;
292307

293308
option = EditorUtility.DisplayDialogComplex((string.IsNullOrEmpty(title) ? "" : (title + " - ")) + L10n.Tr("Unsaved Changes Detected"),
294-
allUnsaved.First().saveChangesMessage,
309+
allUnsaved[0].saveChangesMessage,
295310
L10n.Tr("Save"),
296311
L10n.Tr("Cancel"),
297312
L10n.Tr("Discard"));
298313
}
299314
else
300315
{
301-
string unsavedChangesMessage = string.Join("\n", allUnsaved.Select(v => v.saveChangesMessage).ToArray());
316+
var savedChangesBuilder = new StringBuilder();
317+
318+
int last = allUnsaved.Count - 1;
319+
for (int i = 0; i < last; ++i)
320+
{
321+
savedChangesBuilder.Append(allUnsaved[i].saveChangesMessage);
322+
savedChangesBuilder.Append('\n');
323+
}
324+
savedChangesBuilder.Append(allUnsaved[last]);
302325

303326
option = EditorUtility.DisplayDialogComplex(L10n.Tr("Unsaved Changes Detected"),
304-
unsavedChangesMessage,
327+
savedChangesBuilder.ToString(),
305328
L10n.Tr("Save All"),
306329
L10n.Tr("Cancel"),
307330
L10n.Tr("Discard All"));
@@ -342,11 +365,17 @@ internal static bool PrivateRequestClose(List<EditorWindow> allUnsaved)
342365
}
343366
}
344367

345-
internal void InternalCloseWindow()
368+
// Closes the Window _without prompting_
369+
public void Close()
346370
{
371+
// Because this is a UnityObject, DestroyImmediate _will_ nullify the this pointer.
372+
// This can guard against double-close
373+
if (this == null)
374+
return;
375+
347376
Save();
348377

349-
if (m_ShowMode == (int)ShowMode.MainWindow && s_MainWindow == this)
378+
if (s_MainWindow == this)
350379
s_MainWindow = null;
351380

352381
if (m_RootView)
@@ -358,6 +387,15 @@ internal void InternalCloseWindow()
358387
DestroyImmediate(this, true);
359388
}
360389

390+
[RequiredByNativeCode]
391+
private void RequestCloseSentByNativeCode()
392+
{
393+
if (CanClose())
394+
{
395+
Close();
396+
}
397+
}
398+
361399
[RequiredByNativeCode]
362400
internal bool IsMultiplayerClone()
363401
{
@@ -373,7 +411,7 @@ private static List<EditorWindow> FindUnsavedChanges(View view)
373411
switch (v)
374412
{
375413
case DockArea dockArea:
376-
foreach (var windowClose in dockArea.m_Panes.OfType<EditorWindow>())
414+
foreach (var windowClose in dockArea.m_Panes)
377415
if (windowClose.hasUnsavedChanges)
378416
unsavedChanges.Add(windowClose);
379417
break;
@@ -395,16 +433,6 @@ public void UnsavedStateChanged()
395433
hasUnsavedChanges = m_UnsavedEditorWindows.Count > 0;
396434
}
397435

398-
public void Close()
399-
{
400-
Save();
401-
402-
// Guard against destroy window or window in the process of being destroyed.
403-
if (this && m_WindowPtr.m_IntPtr != IntPtr.Zero)
404-
InternalClose();
405-
DestroyImmediate(this, true);
406-
}
407-
408436
internal bool IsNotDocked()
409437
{
410438
return ( // hallelujah
@@ -433,7 +461,17 @@ internal string GetWindowID()
433461

434462
if (rootView.children.Length > 0)
435463
{
436-
var dockArea = rootView.children.FirstOrDefault(c => c is DockArea) as DockArea;
464+
DockArea dockArea = null;
465+
466+
foreach (var child in rootView.children)
467+
{
468+
if (child is DockArea)
469+
{
470+
dockArea = (DockArea)child;
471+
break;
472+
}
473+
}
474+
437475
if (dockArea && dockArea.m_Panes.Count > 0)
438476
{
439477
return (m_ShowMode == (int)ShowMode.Utility || m_ShowMode == (int)ShowMode.AuxWindow) ? v.actualView.GetType().ToString()
@@ -642,6 +680,5 @@ internal Rect GetDropDownRect(Rect buttonRect, Vector2 minSize, Vector2 maxSize)
642680
{
643681
return PopupLocationHelper.GetDropDownRect(buttonRect, minSize, maxSize, this);
644682
}
645-
646683
}
647684
} //namespace

Editor/Mono/CustomInspectorStubs.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,21 @@ private InputManager() {}
6868
[SettingsProvider]
6969
internal static SettingsProvider CreateProjectSettingsProvider()
7070
{
71-
var provider = AssetSettingsProvider.CreateProviderFromAssetPath(
72-
"Project/Input Manager", "ProjectSettings/InputManager.asset",
73-
SettingsProvider.GetSearchKeywordsFromPath("ProjectSettings/InputManager.asset"));
74-
return provider;
71+
// The new input system adds objects to InputManager.asset. This means we can't use AssetSettingsProvider.CreateProviderFromAssetPath
72+
// as it will load *all* objects at that path and try to create an editor for it.
73+
// NOTE: When the input system package is uninstalled, InputManager.asset will contain serialized MonoBehaviour objects for which
74+
// the C# classes are no longer available. They will thus not load correctly and appear as null entries.
75+
var objects = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset");
76+
foreach (var obj in objects)
77+
{
78+
if (obj != null && obj.name == "InputManager")
79+
{
80+
var provider = AssetSettingsProvider.CreateProviderFromObject("Project/Input Manager", obj,
81+
SettingsProvider.GetSearchKeywordsFromPath("ProjectSettings/InputManager.asset"));
82+
return provider;
83+
}
84+
}
85+
return null;
7586
}
7687
}
7788

Editor/Mono/EditorUserBuildSettings.bindings.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -347,37 +347,35 @@ public enum EmbeddedArchitecture
347347
}
348348

349349
[NativeType(Header = "Editor/Src/EditorUserBuildSettings.h")]
350-
[Obsolete("QNXArchitecture is deprecated. Use EmbeddedArchitecture. (UnityUpgradeable) -> EmbeddedArchitecture")]
351350
public enum QNXArchitecture
352351
{
353352
[UnityEngine.InspectorName("Arm64")]
354-
Arm64 = 0,
353+
Arm64 = EmbeddedArchitecture.Arm64,
355354

356355
[UnityEngine.InspectorName("Arm32")]
357-
Arm32 = 1,
356+
Arm32 = EmbeddedArchitecture.Arm32,
358357

359358
[UnityEngine.InspectorName("X64")]
360-
X64 = 2,
359+
X64 = EmbeddedArchitecture.X64,
361360

362361
[UnityEngine.InspectorName("X86")]
363-
X86 = 3,
362+
X86 = EmbeddedArchitecture.X86,
364363
}
365364

366365
[NativeType(Header = "Editor/Src/EditorUserBuildSettings.h")]
367-
[Obsolete("EmbeddedLinuxArchitecture is deprecated. Use EmbeddedArchitecture. (UnityUpgradeable) -> EmbeddedArchitecture")]
368366
public enum EmbeddedLinuxArchitecture
369367
{
370368
[UnityEngine.InspectorName("Arm64")]
371-
Arm64 = 0,
369+
Arm64 = EmbeddedArchitecture.Arm64,
372370

373371
[UnityEngine.InspectorName("Arm32")]
374-
Arm32 = 1,
372+
Arm32 = EmbeddedArchitecture.Arm32,
375373

376374
[UnityEngine.InspectorName("X64")]
377-
X64 = 2,
375+
X64 = EmbeddedArchitecture.X64,
378376

379377
[UnityEngine.InspectorName("X86")]
380-
X86 = 3,
378+
X86 = EmbeddedArchitecture.X86,
381379
}
382380

383381
[NativeHeader("Editor/Src/EditorUserBuildSettings.h")]
@@ -414,7 +412,7 @@ public static extern QNXOsVersion selectedQnxOsVersion
414412
}
415413

416414
// QNX Architecture
417-
public static extern EmbeddedArchitecture selectedQnxArchitecture
415+
public static extern QNXArchitecture selectedQnxArchitecture
418416
{
419417
[NativeMethod("GetSelectedQNXArchitecture")]
420418
get;
@@ -423,7 +421,7 @@ public static extern EmbeddedArchitecture selectedQnxArchitecture
423421
}
424422

425423
// Embedded Linux Architecture
426-
public static extern EmbeddedArchitecture selectedEmbeddedLinuxArchitecture
424+
public static extern EmbeddedLinuxArchitecture selectedEmbeddedLinuxArchitecture
427425
{
428426
[NativeMethod("GetSelectedEmbeddedLinuxArchitecture")]
429427
get;

0 commit comments

Comments
 (0)