Skip to content

Commit bf25390

Browse files
author
Unity Technologies
committed
Unity 2023.1.0a15 C# reference source code
1 parent 8242978 commit bf25390

File tree

205 files changed

+20814
-12692
lines changed

Some content is hidden

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

205 files changed

+20814
-12692
lines changed

Editor/Mono/ContainerWindow.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ internal partial class ContainerWindow : ScriptableObject
2626

2727
internal int m_DisplayIndex;
2828
internal bool m_IsFullscreenContainer;
29+
internal bool m_IsForceTitleBar;
2930

3031
internal bool m_DontSaveToLayout = false;
3132
private bool m_HasUnsavedChanges = false;
@@ -372,6 +373,11 @@ internal void InternalCloseWindow()
372373
DestroyImmediate(this, true);
373374
}
374375

376+
internal bool InternalIsForceTitleBar()
377+
{
378+
return m_IsForceTitleBar;
379+
}
380+
375381
private static List<EditorWindow> FindUnsavedChanges(View view)
376382
{
377383
var unsavedChanges = new List<EditorWindow>();

Editor/Mono/Delayer.cs

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,73 @@ class Delayer
1313
private readonly double m_DebounceDelay;
1414
private object m_Context;
1515
private readonly bool m_IsThrottle;
16+
private readonly bool m_FirstExecuteImmediate;
17+
private bool m_DelayInProgress;
1618

1719
public static Delayer Throttle(Action<object> action, double delay = 0.2)
1820
{
19-
return new Delayer(action, delay, true);
21+
return new Delayer(action, delay, true, false);
22+
}
23+
24+
public static Delayer Throttle(Action<object> action, double delay, bool firstExecuteImmediate)
25+
{
26+
return new Delayer(action, delay, true, firstExecuteImmediate);
2027
}
2128

2229
public static Delayer Debounce(Action<object> action, double delay = 0.2)
2330
{
24-
return new Delayer(action, delay, false);
31+
return new Delayer(action, delay, false, false);
32+
}
33+
34+
public static Delayer Debounce(Action<object> action, double delay, bool firstExecuteImmediate)
35+
{
36+
return new Delayer(action, delay, false, firstExecuteImmediate);
2537
}
2638

2739
public void Execute(object context = null)
2840
{
2941
m_Context = context;
42+
3043
if (m_IsThrottle)
3144
{
32-
if (m_LastExecutionTime == 0)
45+
if (m_LastExecutionTime == 0 || !m_DelayInProgress)
3346
Throttle();
3447
}
3548
else
3649
{
37-
m_LastExecutionTime = DateTime.UtcNow.Ticks;
38-
Debounce();
50+
if (m_FirstExecuteImmediate && m_LastExecutionTime == 0)
51+
{
52+
m_Action?.Invoke(m_Context);
53+
m_LastExecutionTime = DateTime.UtcNow.Ticks;
54+
}
55+
else
56+
{
57+
m_LastExecutionTime = DateTime.UtcNow.Ticks;
58+
Debounce();
59+
}
3960
}
4061
}
4162

42-
private Delayer(Action<object> action, double delay, bool isThrottle)
63+
private Delayer(Action<object> action, double delay, bool isThrottle, bool firstExecuteImmediate)
4364
{
4465
m_Action = action;
4566
m_DebounceDelay = delay;
4667
m_IsThrottle = isThrottle;
68+
m_FirstExecuteImmediate = firstExecuteImmediate;
4769
}
4870

4971
public void Dispose()
5072
{
51-
EditorApplication.delayCall -= Debounce;
52-
EditorApplication.delayCall -= Throttle;
73+
EditorApplication.tick -= Debounce;
74+
EditorApplication.tick -= Throttle;
5375
m_Context = null;
5476
m_Action = null;
5577
}
5678

5779
private void Debounce()
5880
{
59-
EditorApplication.delayCall -= Debounce;
81+
m_DelayInProgress = false;
82+
EditorApplication.tick -= Debounce;
6083
var currentTime = DateTime.UtcNow.Ticks;
6184
if (m_LastExecutionTime != 0 && DelayHasPassed(currentTime))
6285
{
@@ -65,31 +88,51 @@ private void Debounce()
6588
}
6689
else
6790
{
68-
EditorApplication.delayCall += Debounce;
91+
EditorApplication.tick += Debounce;
92+
m_DelayInProgress = true;
6993
}
7094
}
7195

7296
private void Throttle()
7397
{
74-
EditorApplication.delayCall -= Throttle;
98+
m_DelayInProgress = false;
99+
EditorApplication.tick -= Throttle;
75100
var currentTime = DateTime.UtcNow.Ticks;
76-
if (m_LastExecutionTime != 0 && DelayHasPassed(currentTime))
101+
102+
if (m_FirstExecuteImmediate)
77103
{
78-
m_Action?.Invoke(m_Context);
79-
m_LastExecutionTime = 0;
104+
if (m_LastExecutionTime == 0 || DelayHasPassed(currentTime))
105+
{
106+
m_Action?.Invoke(m_Context);
107+
m_LastExecutionTime = currentTime;
108+
}
109+
else
110+
{
111+
EditorApplication.tick += Throttle;
112+
m_DelayInProgress = true;
113+
}
80114
}
81115
else
82116
{
83-
if (m_LastExecutionTime == 0)
84-
m_LastExecutionTime = currentTime;
85-
EditorApplication.delayCall += Throttle;
117+
if (m_LastExecutionTime != 0 && DelayHasPassed(currentTime))
118+
{
119+
m_Action?.Invoke(m_Context);
120+
m_LastExecutionTime = 0;
121+
}
122+
else
123+
{
124+
if (m_LastExecutionTime == 0)
125+
m_LastExecutionTime = currentTime;
126+
EditorApplication.tick += Throttle;
127+
m_DelayInProgress = true;
128+
}
86129
}
87130
}
88131

89132
private bool DelayHasPassed(long currentTime)
90133
{
91134
var timeSpan = new TimeSpan(currentTime - m_LastExecutionTime);
92-
return timeSpan.TotalSeconds > m_DebounceDelay;
135+
return timeSpan.TotalSeconds >= m_DebounceDelay;
93136
}
94137
}
95138
}

Editor/Mono/GUI/WindowLayout.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,92 @@ internal static ContainerWindow FindMainWindow()
211211
return null;
212212
}
213213

214+
internal static ContainerWindow ShowWindowWithDynamicLayout(string windowId, string layoutDataPath)
215+
{
216+
try
217+
{
218+
ContainerWindow.SetFreezeDisplay(true);
219+
220+
if (!File.Exists(layoutDataPath))
221+
{
222+
Debug.LogError($"Failed to find layout data file at path {layoutDataPath}");
223+
return null;
224+
}
225+
226+
var layoutDataJson = File.ReadAllText(layoutDataPath);
227+
var layoutData = SJSON.LoadString(layoutDataJson);
228+
229+
LayoutViewInfo viewInfo = new LayoutViewInfo("view", 0, true);
230+
var availableEditorWindowTypes = TypeCache.GetTypesDerivedFrom<EditorWindow>().ToArray();
231+
232+
if (!GetLayoutViewInfo(layoutData, availableEditorWindowTypes, ref viewInfo))
233+
{
234+
Debug.LogError("Failed to load window layout; no view defined");
235+
return null;
236+
}
237+
238+
var window = Resources.FindObjectsOfTypeAll<ContainerWindow>()
239+
.FirstOrDefault(w => w.windowID == windowId);
240+
if (window == null)
241+
{
242+
window = ScriptableObject.CreateInstance<ContainerWindow>();
243+
244+
var windowMinSize = new Vector2(120, 80);
245+
var windowMaxSize = new Vector2(8192, 8192);
246+
if (layoutData.Contains("min_width"))
247+
{
248+
windowMinSize.x = Convert.ToSingle(layoutData["min_width"]);
249+
}
250+
if (layoutData.Contains("min_height"))
251+
{
252+
windowMinSize.y = Convert.ToSingle(layoutData["min_height"]);
253+
}
254+
if (layoutData.Contains("max_width"))
255+
{
256+
windowMaxSize.x = Convert.ToSingle(layoutData["max_width"]);
257+
}
258+
if (layoutData.Contains("max_height"))
259+
{
260+
windowMaxSize.y = Convert.ToSingle(layoutData["max_height"]);
261+
}
262+
263+
window.SetMinMaxSizes(windowMinSize, windowMaxSize);
264+
}
265+
266+
var hasGeometrySettings = EditorPrefs.HasKey(windowId);
267+
window.windowID = windowId;
268+
if (hasGeometrySettings)
269+
window.LoadGeometry(true);
270+
271+
var width = window.position.width;
272+
var height = window.position.height;
273+
274+
View view = LoadLayoutView<DockArea>(availableEditorWindowTypes, viewInfo, width, height);
275+
276+
var main = ScriptableObject.CreateInstance<MainView>();
277+
main.useTopView = false;
278+
main.useBottomView = false;
279+
280+
view.position = new Rect(0, 0, width, height);
281+
main.AddChild(view);
282+
283+
if (window.rootView)
284+
ScriptableObject.DestroyImmediate(window.rootView, true);
285+
286+
window.rootView = main;
287+
window.rootView.position = new Rect(0, 0, width, height);
288+
window.m_IsForceTitleBar = true;
289+
window.Show(ShowMode.Utility, true, true, true);
290+
window.DisplayAllViews();
291+
292+
return window;
293+
}
294+
finally
295+
{
296+
ContainerWindow.SetFreezeDisplay(false);
297+
}
298+
}
299+
214300
private static ContainerWindow GenerateLayout(bool keepMainWindow, Type[] availableEditorWindowTypes, LayoutViewInfo center, LayoutViewInfo top, LayoutViewInfo bottom, JSONObject layoutData)
215301
{
216302
ContainerWindow mainContainerWindow = FindMainWindow();

Editor/Mono/Inspector/AddComponent/AddComponentWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private void OnItemSelected(AdvancedDropdownItem item)
6868
{
6969
SendUsabilityAnalyticsEvent(new AnalyticsEventData
7070
{
71-
name = name,
71+
name = item.name,
7272
filter = searchString,
7373
isNewScript = false
7474
});

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class SettingsContent
200200
public static readonly GUIContent scriptingDefineSymbolsApply = EditorGUIUtility.TrTextContent("Apply");
201201
public static readonly GUIContent scriptingDefineSymbolsApplyRevert = EditorGUIUtility.TrTextContent("Revert");
202202
public static readonly GUIContent scriptingDefineSymbolsCopyDefines = EditorGUIUtility.TrTextContent("Copy Defines", "Copy applied defines");
203-
public static readonly GUIContent suppressCommonWarnings = EditorGUIUtility.TrTextContent("Suppress Common Warnings", "Suppresses C# warnings CS0169 and CS0649.");
203+
public static readonly GUIContent suppressCommonWarnings = EditorGUIUtility.TrTextContent("Suppress Common Warnings", "Suppresses C# warnings CS0169, CS0649, and CS0282.");
204204
public static readonly GUIContent scriptingBackend = EditorGUIUtility.TrTextContent("Scripting Backend");
205205
public static readonly GUIContent managedStrippingLevel = EditorGUIUtility.TrTextContent("Managed Stripping Level", "If scripting backend is IL2CPP, managed stripping can't be disabled.");
206206
public static readonly GUIContent il2cppCompilerConfiguration = EditorGUIUtility.TrTextContent("C++ Compiler Configuration");
@@ -653,8 +653,9 @@ void OnEnable()
653653

654654
m_ForceSRGBBlit = FindPropertyAssert("hmiForceSRGBBlit");
655655

656-
m_SettingsExtensions = new ISettingEditorExtension[validPlatforms.Length];
657-
for (int i = 0; i < validPlatforms.Length; i++)
656+
var validPlatformsLength = validPlatforms.Length;
657+
m_SettingsExtensions = new ISettingEditorExtension[validPlatformsLength];
658+
for (int i = 0; i < validPlatformsLength; i++)
658659
{
659660
string module = ModuleManager.GetTargetStringFromBuildTargetGroup(validPlatforms[i].namedBuildTarget.ToBuildTargetGroup());
660661
m_SettingsExtensions[i] = ModuleManager.GetEditorSettingsExtension(module);
@@ -673,8 +674,15 @@ void OnEnable()
673674
// we access this cache both from player settings editor and script side when changing api
674675
s_GraphicsDeviceLists.Clear();
675676

677+
var selectedPlatform = m_SelectedPlatform.intValue;
678+
if (selectedPlatform < 0)
679+
selectedPlatform = 0;
680+
681+
if (selectedPlatform >= validPlatformsLength)
682+
selectedPlatform = validPlatformsLength - 1;
683+
676684
// Setup initial values to prevent immediate script recompile (or editor restart)
677-
NamedBuildTarget namedBuildTarget = validPlatforms[m_SelectedPlatform.intValue].namedBuildTarget;
685+
NamedBuildTarget namedBuildTarget = validPlatforms[selectedPlatform].namedBuildTarget;
678686
serializedActiveInputHandler = m_ActiveInputHandler.intValue;
679687
serializedSuppressCommonWarnings = m_SuppressCommonWarnings.boolValue;
680688
serializedAllowUnsafeCode = m_AllowUnsafeCode.boolValue;
@@ -1009,7 +1017,7 @@ public void ResolutionSectionGUI(NamedBuildTarget namedBuildTarget, ISettingEdit
10091017
settingsExtension.ResolutionSectionGUI(h, kLabelFloatMinW, kLabelFloatMaxW);
10101018
}
10111019

1012-
if (namedBuildTarget == NamedBuildTarget.Standalone || namedBuildTarget == NamedBuildTarget.EmbeddedLinux)
1020+
if (namedBuildTarget == NamedBuildTarget.Standalone)
10131021
{
10141022
GUILayout.Label(SettingsContent.resolutionTitle, EditorStyles.boldLabel);
10151023

Editor/Mono/Modules/BeeBuildPostprocessor.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -577,19 +577,6 @@ public virtual string PrepareForBuild(BuildOptions options, BuildTarget target)
577577
if ((options & BuildOptions.CleanBuildCache) == BuildOptions.CleanBuildCache)
578578
EditorCompilation.ClearBeeBuildArtifacts();
579579

580-
if (Unsupported.IsDeveloperBuild())
581-
{
582-
NPath editorGitRevisionFile = $"{EditorApplication.applicationContentsPath}/Tools/BuildPipeline/gitrevision.txt";
583-
NPath playerGitRevisionFile = $"{BuildPipeline.GetPlaybackEngineDirectory(target, options)}/Bee/gitrevision.txt";
584-
if (editorGitRevisionFile.Exists() && playerGitRevisionFile.Exists())
585-
{
586-
string editorGitRevision = editorGitRevisionFile.ReadAllText();
587-
string playerGitRevision = playerGitRevisionFile.ReadAllText();
588-
if (editorGitRevision != playerGitRevision)
589-
return $"The Bee libraries used in the editor come from a different revision, than the ones used for the player. Please rebuild both editor and player when making changes to Bee player build libraries. (editor: '{editorGitRevision}', player: '{playerGitRevision}')";
590-
}
591-
}
592-
593580
return null;
594581
}
595582

Editor/Mono/Networking/PlayerConnection/EditorConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private void Cleanup()
8080
{
8181
UnregisterAllPersistedListeners(m_PlayerEditorConnectionEvents.connectionEvent);
8282
UnregisterAllPersistedListeners(m_PlayerEditorConnectionEvents.disconnectionEvent);
83-
m_PlayerEditorConnectionEvents.messageTypeSubscribers.Clear();
83+
m_PlayerEditorConnectionEvents.Clear();
8484
}
8585

8686
private void UnregisterAllPersistedListeners(UnityEventBase connectionEvent)

Editor/Mono/Prefabs/PrefabUtility.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void HandleApplySingleProperties(
505505
HashSet<SerializedObject> changedObjects,
506506
bool allowApplyDefaultOverride,
507507
InteractionMode action
508-
)
508+
)
509509
{
510510
bool isObjectOnRootInAsset = IsObjectOnRootInAsset(prefabInstanceObject, assetPath);
511511

@@ -1969,13 +1969,13 @@ internal static void ValidatePath(GameObject instanceRoot, string path)
19691969
}
19701970
}
19711971

1972-
private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path)
1972+
private static void SaveAsPrefabAssetArgumentCheck(GameObject instanceRoot, string path, bool connectToInstance)
19731973
{
19741974
if (instanceRoot == null)
19751975
throw new ArgumentNullException("Parameter root is null");
19761976

1977-
if (EditorUtility.IsPersistent(instanceRoot))
1978-
throw new ArgumentException("Can't save persistent object as a Prefab asset");
1977+
if (EditorUtility.IsPersistent(instanceRoot) && connectToInstance)
1978+
throw new ArgumentException("Can't save persistent Objects and connect them to the saved Prefab");
19791979

19801980
if (IsPartOfNonAssetPrefabInstance(instanceRoot))
19811981
{
@@ -2007,7 +2007,7 @@ private static void ReplacePrefabArgumentCheck(GameObject root, string path)
20072007

20082008
public static GameObject SaveAsPrefabAsset(GameObject instanceRoot, string assetPath, out bool success)
20092009
{
2010-
SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath);
2010+
SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath, false);
20112011

20122012
return SaveAsPrefabAsset_Internal(instanceRoot, assetPath, out success);
20132013
}
@@ -2026,7 +2026,7 @@ public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, st
20262026

20272027
public static GameObject SaveAsPrefabAssetAndConnect(GameObject instanceRoot, string assetPath, InteractionMode action, out bool success)
20282028
{
2029-
SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath);
2029+
SaveAsPrefabAssetArgumentCheck(instanceRoot, assetPath, true);
20302030

20312031
if (IsPathInStreamingAssets(assetPath))
20322032
throw new ArgumentException("Can't connect a Prefab in the StreamingAssets folder to GameObjects in the scene. To save a Prefab to the StreamingAssets folder use SaveAsPrefabAsset instead.");
@@ -2075,7 +2075,7 @@ internal static void ApplyPrefabInstance(GameObject instance)
20752075
var assetObject = GetCorrespondingObjectFromSource(instance);
20762076
string path = AssetDatabase.GetAssetPath(assetObject);
20772077

2078-
SaveAsPrefabAssetArgumentCheck(instance, path);
2078+
SaveAsPrefabAssetArgumentCheck(instance, path, true);
20792079

20802080
ApplyPrefabInstance_Internal(instance);
20812081
}

0 commit comments

Comments
 (0)