Skip to content

Commit 8a1a537

Browse files
author
Unity Technologies
committed
Unity 2020.2.0a11 C# reference source code
1 parent 59490f1 commit 8a1a537

File tree

94 files changed

+1938
-1207
lines changed

Some content is hidden

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

94 files changed

+1938
-1207
lines changed

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/ConsoleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public static void ShowConsoleWindow(bool immediate)
239239
if (ms_ConsoleWindow == null)
240240
{
241241
ms_ConsoleWindow = ScriptableObject.CreateInstance<ConsoleWindow>();
242-
if (Unity.MPE.ProcessService.level == Unity.MPE.ProcessLevel.UMP_MASTER)
242+
if (UnityEditor.MPE.ProcessService.level == MPE.ProcessLevel.Master)
243243
ms_ConsoleWindow.Show(immediate);
244244
else
245245
ms_ConsoleWindow.ShowModalUtility();

Editor/Mono/ContainerWindow.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public extern Rect position
9292
[FreeFunction(k_ScriptingPrefix + "Internal_SetTitle", HasExplicitThis = true)]
9393
private extern void Internal_SetTitle(string title);
9494

95+
[FreeFunction(k_ScriptingPrefix + "Internal_SetHasUnsavedChanges", HasExplicitThis = true)]
96+
private extern void Internal_SetHasUnsavedChanges(bool hasUnsavedChanges);
97+
9598
[FreeFunction(k_ScriptingPrefix + "SetBackgroundColor", HasExplicitThis = true)]
9699
private extern void SetBackgroundColor(Color color);
97100

Editor/Mono/ContainerWindow.cs

Lines changed: 146 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ internal partial class ContainerWindow : ScriptableObject
2525
[SerializeField] bool m_Maximized;
2626

2727
internal bool m_DontSaveToLayout = false;
28+
private bool m_HasUnsavedChanges = false;
29+
private List<EditorWindow> m_UnsavedEditorWindows;
30+
2831
private int m_ButtonCount;
2932
private float m_TitleBarWidth;
3033

@@ -40,7 +43,6 @@ private static class Styles
4043
{
4144
// Title Bar Buttons (Non)
4245
public static GUIStyle buttonMin = "WinBtnMinMac";
43-
public static GUIStyle buttonInactive = "WinBtnInactiveMac";
4446
public static GUIStyle buttonClose = macEditor ? "WinBtnCloseMac" : "WinBtnClose";
4547
public static GUIStyle buttonMax = macEditor ? "WinBtnMaxMac" : "WinBtnMax";
4648
public static GUIStyle buttonRestore = macEditor ? "WinBtnRestoreMac" : "WinBtnRestore";
@@ -64,6 +66,7 @@ private static class Styles
6466
public ContainerWindow()
6567
{
6668
m_PixelRect = new Rect(0, 0, 400, 300);
69+
m_UnsavedEditorWindows = new List<EditorWindow>();
6770
}
6871

6972
internal void __internalAwake()
@@ -196,6 +199,73 @@ public void SetMinMaxSizes(Vector2 min, Vector2 max)
196199
Internal_SetMinMaxSizes(min, max);
197200
}
198201

202+
internal bool InternalRequestClose()
203+
{
204+
if (hasUnsavedChanges)
205+
{
206+
return PrivateRequestClose(m_UnsavedEditorWindows);
207+
}
208+
209+
return true;
210+
}
211+
212+
internal bool InternalRequestClose(EditorWindow dockedTab)
213+
{
214+
if (dockedTab.hasUnsavedChanges)
215+
{
216+
var unsaved = new List<EditorWindow>() { dockedTab };
217+
return PrivateRequestClose(unsaved);
218+
}
219+
220+
return true;
221+
}
222+
223+
private bool PrivateRequestClose(List<EditorWindow> allUnsaved)
224+
{
225+
Debug.Assert(allUnsaved.Count > 0);
226+
227+
const int kSave = 0;
228+
const int kCancel = 1;
229+
const int kDiscard = 2;
230+
231+
int option = 1; // Cancel
232+
233+
if (allUnsaved.Count == 1)
234+
{
235+
option = EditorUtility.DisplayDialogComplex(L10n.Tr("Unsaved Changes Detected"),
236+
allUnsaved.First().saveChangesMessage,
237+
L10n.Tr("Save"),
238+
L10n.Tr("Cancel"),
239+
L10n.Tr("Discard"));
240+
}
241+
else
242+
{
243+
string unsavedChangesMessage = string.Join("\n", allUnsaved.Select(v => v.saveChangesMessage).ToArray());
244+
245+
option = EditorUtility.DisplayDialogComplex(L10n.Tr("Unsaved Changes Detected"),
246+
unsavedChangesMessage,
247+
L10n.Tr("Save All"),
248+
L10n.Tr("Cancel"),
249+
L10n.Tr("Discard All"));
250+
}
251+
252+
switch (option)
253+
{
254+
case kSave:
255+
foreach (var w in allUnsaved)
256+
w.SaveChanges();
257+
break;
258+
case kCancel:
259+
case kDiscard:
260+
break;
261+
default:
262+
Debug.LogError("Unrecognized option.");
263+
break;
264+
}
265+
266+
return option != kCancel;
267+
}
268+
199269
internal void InternalCloseWindow()
200270
{
201271
Save();
@@ -208,6 +278,37 @@ internal void InternalCloseWindow()
208278
DestroyImmediate(this, true);
209279
}
210280

281+
private static List<EditorWindow> FindUnsavedChanges(View view)
282+
{
283+
var unsavedChanges = new List<EditorWindow>();
284+
285+
foreach (View v in view.allChildren)
286+
{
287+
switch (v)
288+
{
289+
case DockArea dockArea:
290+
foreach (var windowClose in dockArea.m_Panes.OfType<EditorWindow>())
291+
if (windowClose.hasUnsavedChanges)
292+
unsavedChanges.Add(windowClose);
293+
break;
294+
case HostView hostView:
295+
if (hostView.actualView?.hasUnsavedChanges ?? false)
296+
unsavedChanges.Add(hostView.actualView);
297+
break;
298+
default:
299+
break;
300+
}
301+
}
302+
303+
return unsavedChanges;
304+
}
305+
306+
public void UnsavedStateChanged()
307+
{
308+
m_UnsavedEditorWindows = FindUnsavedChanges(rootView);
309+
hasUnsavedChanges = m_UnsavedEditorWindows.Count > 0;
310+
}
311+
211312
public void Close()
212313
{
213314
Save();
@@ -256,7 +357,7 @@ internal string GetWindowID()
256357

257358
public bool IsMainWindow()
258359
{
259-
if (Unity.MPE.ProcessService.level == Unity.MPE.ProcessLevel.UMP_MASTER)
360+
if (UnityEditor.MPE.ProcessService.level == UnityEditor.MPE.ProcessLevel.Master)
260361
return m_ShowMode == (int)ShowMode.MainWindow && m_DontSaveToLayout == false;
261362
return false;
262363
}
@@ -346,11 +447,47 @@ internal void OnMove()
346447
}
347448
}
348449

450+
// The title of the window, including unsaved changes markings, if any.
451+
public string displayedTitle { get; private set; }
452+
453+
private void UpdateTitle()
454+
{
455+
displayedTitle = hasUnsavedChanges ? m_Title + "*" : m_Title;
456+
Internal_SetTitle(displayedTitle);
457+
}
458+
349459
// The title of the window
350460
public string title
351461
{
352-
get { return m_Title; }
353-
set { m_Title = value; Internal_SetTitle(value); }
462+
get
463+
{
464+
return m_Title;
465+
}
466+
set
467+
{
468+
if (m_Title != value)
469+
{
470+
m_Title = value;
471+
UpdateTitle();
472+
}
473+
}
474+
}
475+
476+
public bool hasUnsavedChanges
477+
{
478+
get
479+
{
480+
return m_HasUnsavedChanges;
481+
}
482+
private set
483+
{
484+
if (m_HasUnsavedChanges != value)
485+
{
486+
m_HasUnsavedChanges = value;
487+
Internal_SetHasUnsavedChanges(value);
488+
UpdateTitle();
489+
}
490+
}
354491
}
355492

356493
// Array of all visible ContainerWindows, from frontmost to last
@@ -449,8 +586,11 @@ public void HandleWindowDecorationStart(Rect windowPosition)
449586
BeginTitleBarButtons(windowPosition);
450587
if (TitleBarButton(close))
451588
{
452-
Close();
453-
GUIUtility.ExitGUI();
589+
if (InternalRequestClose())
590+
{
591+
Close();
592+
GUIUtility.ExitGUI();
593+
}
454594
}
455595

456596
var canMaximize = m_MaxSize.x == 0 || m_MaxSize.y == 0 || m_MaxSize.x >= Screen.currentResolution.width || m_MaxSize.y >= Screen.currentResolution.height;

Editor/Mono/EditorMode/ModeService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using System.IO;
99
using System.Linq;
1010
using JetBrains.Annotations;
11-
using Unity.MPE;
11+
using UnityEditor.MPE;
1212
using UnityEditor.Experimental.AssetImporters;
1313
using UnityEngine;
1414
using UnityEngine.Internal;

Editor/Mono/EditorResources.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ private static List<string> GetDefaultStyleCatalogPaths()
265265
var catalogFiles = new List<string>
266266
{
267267
"StyleSheets/Extensions/base/common.uss",
268-
"StyleSheets/Variables/Public/common.uss",
268+
"UIPackageResources/StyleSheets/Default/Variables/Public/common.uss",
269269
"StyleSheets/Northstar/common.uss"
270270
};
271271

@@ -277,7 +277,7 @@ private static List<string> GetDefaultStyleCatalogPaths()
277277
}
278278

279279
catalogFiles.Add(useDarkTheme ? "StyleSheets/Extensions/base/dark.uss" : "StyleSheets/Extensions/base/light.uss");
280-
catalogFiles.Add(useDarkTheme ? "StyleSheets/Northstar/Palette/dark.uss" : "StyleSheets/Northstar/Palette/light.uss");
280+
catalogFiles.Add(useDarkTheme ? "UIPackageResources/StyleSheets/Default/Northstar/Palette/dark.uss" : "UIPackageResources/StyleSheets/Default/Northstar/Palette/light.uss");
281281
return catalogFiles;
282282
}
283283

Editor/Mono/EditorWindow.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,16 @@ public void ShowAuxWindow()
626626
// Show modal editor window. Other windows will not be accessible until this one is closed.
627627
public void ShowModal()
628628
{
629-
ShowWithMode(ShowMode.AuxWindow);
630-
MakeModal();
629+
// It is normally bad to have different behavior on different platforms,
630+
// but in this case Linux is espcially picky about converting modal dialogs.
631+
// the only way we can ensure that without major API changes in window creation is to open them with this type.
632+
if (Application.platform == RuntimePlatform.LinuxEditor)
633+
ShowModalUtility();
634+
else
635+
{
636+
ShowWithMode(ShowMode.AuxWindow);
637+
MakeModal();
638+
}
631639
}
632640

633641
// Returns the first EditorWindow of type /t/ which is currently on the screen.
@@ -893,6 +901,30 @@ internal static T GetWindowDontShow<T>() where T : EditorWindow
893901
return (windows.Length > 0) ? (T)windows[0] : ScriptableObject.CreateInstance<T>();
894902
}
895903

904+
bool m_HasUnsavedChanges = false;
905+
public bool hasUnsavedChanges
906+
{
907+
get
908+
{
909+
return m_HasUnsavedChanges;
910+
}
911+
protected set
912+
{
913+
if (m_HasUnsavedChanges != value)
914+
{
915+
m_HasUnsavedChanges = value;
916+
m_Parent?.window?.UnsavedStateChanged();
917+
}
918+
}
919+
}
920+
921+
public string saveChangesMessage { get; protected set; }
922+
923+
public virtual void SaveChanges()
924+
{
925+
hasUnsavedChanges = false;
926+
}
927+
896928
// Close the editor window.
897929
public void Close()
898930
{
@@ -1084,6 +1116,7 @@ public EditorWindow()
10841116
m_EnableViewDataPersistence = true;
10851117
m_RequestedViewDataSave = false;
10861118
titleContent.text = GetType().ToString();
1119+
saveChangesMessage = $"{GetType()} has unsaved changes.";
10871120

10881121
UpdateWindowMenuListing();
10891122
}
@@ -1119,6 +1152,7 @@ internal static void CreateNewWindowForEditorWindow(EditorWindow window, bool lo
11191152
cw.Show(ShowMode.NormalWindow, loadPosition, showImmediately, setFocus: true);
11201153
//Need this, as show my change the size of the window, due to screen constraints
11211154
cw.OnResize();
1155+
cw.UnsavedStateChanged();
11221156
}
11231157

11241158
// This is such a hack, but will do for now

Editor/Mono/FileUtil.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static void CheckForValidSourceAndDestinationArgumentsAndRaiseAnExceptio
106106
[FreeFunction]
107107
public static extern string GetProjectRelativePath(string path);
108108

109-
[FreeFunction]
109+
[FreeFunction(Name = "GetLastPathNameComponentManaged")]
110110
internal static extern string GetLastPathNameComponent(string path);
111111

112112
[FreeFunction(Name = "DeleteLastPathNameComponentManaged")]

0 commit comments

Comments
 (0)