Skip to content

Commit cc8ba04

Browse files
author
Unity Technologies
committed
Unity 6000.1.0a8 C# reference source code
1 parent 4f72eda commit cc8ba04

Some content is hidden

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

52 files changed

+1075
-162
lines changed

Editor/Mono/AssemblyReloadEvents.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public static event AssemblyReloadCallback afterAssemblyReload
2727
[RequiredByNativeCode]
2828
static void OnBeforeAssemblyReload()
2929
{
30-
using var scope = new ProgressScope("OnBeforeAssemblyReload Callback", "", forceShow: true);
30+
if (!m_BeforeAssemblyReloadEvent.hasSubscribers)
31+
return;
32+
using var scope = new ProgressScope("OnBeforeAssemblyReload Callback", "", forceUpdate: true);
3133
foreach (var evt in m_BeforeAssemblyReloadEvent)
3234
{
3335
scope.SetText($"{evt.Method?.DeclaringType?.FullName}.{evt.Method?.Name}", true);
@@ -38,7 +40,9 @@ static void OnBeforeAssemblyReload()
3840
[RequiredByNativeCode]
3941
static void OnAfterAssemblyReload()
4042
{
41-
using var scope = new ProgressScope("OnAfterAssemblyReload Callback", "", forceShow: true);
43+
if (!m_AfterAssemblyReloadEvent.hasSubscribers)
44+
return;
45+
using var scope = new ProgressScope("OnAfterAssemblyReload Callback", "", forceUpdate: true);
4246
foreach (var evt in m_AfterAssemblyReloadEvent)
4347
{
4448
scope.SetText($"{evt.Method?.DeclaringType?.FullName}.{evt.Method?.Name}", true);

Editor/Mono/BuildProfile/BuildProfile.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6-
using System.Collections.Generic;
76
using System.Runtime.InteropServices;
87
using UnityEngine;
98
using UnityEngine.Bindings;
@@ -138,6 +137,9 @@ public string[] scriptingDefines
138137
set => m_ScriptingDefines = value;
139138
}
140139

140+
[VisibleToOtherModules]
141+
internal Action OnPackageAddProgress;
142+
141143
[SerializeField]
142144
PlayerSettingsYaml m_PlayerSettingsYaml = new();
143145

@@ -197,6 +199,10 @@ internal bool IsActiveBuildProfileOrPlatform()
197199
[VisibleToOtherModules]
198200
internal bool CanBuildLocally()
199201
{
202+
// Note: If the build profile is still being configured (package add info is present)
203+
// we do not want it to be buildable.
204+
if (BuildProfileContext.instance.TryGetPackageAddInfo(this, out _))
205+
return false;
200206
// Note: A platform build profile may have a non-null value even if its module is not installed.
201207
// This scenario is true for server platform profiles, which are the same type as the standalone one.
202208
return platformBuildProfile != null && BuildProfileModuleUtil.IsModuleInstalled(platformGuid);
@@ -246,6 +252,19 @@ void OnEnable()
246252
TryLoadGraphicsSettings();
247253
TryLoadQualitySettings();
248254

255+
if (BuildProfileContext.instance.TryGetPackageAddInfo(this, out var packageAddInfo))
256+
{
257+
packageAddInfo.OnPackageAddProgress = () =>
258+
{
259+
OnPackageAddProgress?.Invoke();
260+
};
261+
packageAddInfo.OnPackageAddComplete = () =>
262+
{
263+
NotifyBuildProfileExtensionOfCreation(packageAddInfo.preconfiguredSettingsVariant);
264+
};
265+
packageAddInfo.RequestPackageInstallation();
266+
}
267+
249268
if (!EditorUserBuildSettings.isBuildProfileAvailable
250269
|| BuildProfileContext.activeProfile != this)
251270
return;
@@ -306,7 +325,9 @@ void OnDisable()
306325
// OnDisable is called when entering play mode, during domain reloads, or when the object is destroyed.
307326
// Avoid removing player settings for the first two cases to prevent slow syncs (e.g., color space) caused by global manager updates.
308327
if (!EditorApplication.isUpdating)
328+
{
309329
RemovePlayerSettings();
330+
}
310331
}
311332

312333
[MenuItem("CONTEXT/BuildProfile/Reset", false)]

Editor/Mono/BuildProfile/BuildProfileContext.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,57 @@ internal static BuildProfile activeProfile
114114
}
115115
}
116116

117+
[SerializeField]
118+
List<BuildProfilePackageAddInfo> m_PackageAddInfos = new();
119+
120+
[VisibleToOtherModules]
121+
internal bool TryGetPackageAddInfo(BuildProfile profile, out BuildProfilePackageAddInfo result)
122+
{
123+
var profileGuid = GetProfileGUID(profile);
124+
foreach (var packageAddInfo in m_PackageAddInfos)
125+
{
126+
if (packageAddInfo.profileGuid == profileGuid)
127+
{
128+
result = packageAddInfo;
129+
return true;
130+
}
131+
}
132+
result = null;
133+
return false;
134+
}
135+
136+
[VisibleToOtherModules]
137+
internal void AddPackageAddInfo(BuildProfile profile, string[] packagesToAdd, int preconfiguredSettingsVariant)
138+
{
139+
if ((packagesToAdd.Length == 0) && (preconfiguredSettingsVariant == BuildProfilePackageAddInfo.preconfiguredSettingsVariantNotSet))
140+
return;
141+
142+
var profileGuid = GetProfileGUID(profile);
143+
var packageAddInfo = new BuildProfilePackageAddInfo()
144+
{
145+
profileGuid = profileGuid,
146+
packagesToAdd = packagesToAdd,
147+
preconfiguredSettingsVariant = preconfiguredSettingsVariant
148+
};
149+
m_PackageAddInfos.Add(packageAddInfo);
150+
}
151+
152+
[VisibleToOtherModules]
153+
internal void ClearPackageAddInfo(BuildProfile profile)
154+
{
155+
if (TryGetPackageAddInfo(profile, out BuildProfilePackageAddInfo packageAddInfo))
156+
{
157+
m_PackageAddInfos.Remove(packageAddInfo);
158+
}
159+
}
160+
161+
string GetProfileGUID(BuildProfile profile)
162+
{
163+
var profilePath = AssetDatabase.GetAssetPath(profile);
164+
var profileGuid = AssetDatabase.AssetPathToGUID(profilePath);
165+
return profileGuid;
166+
}
167+
117168
static void OnActiveProfileChangedForSettingExtension(BuildProfile previous, BuildProfile newProfile)
118169
{
119170
BuildTargetDiscovery.TryGetBuildTarget(EditorUserBuildSettings.activeBuildTarget, out IBuildTarget iBuildTarget);

Editor/Mono/BuildProfile/BuildProfileCreate.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ internal static BuildProfile CreateInstance(GUID platformId)
5656
/// event after an asset is created by AssetDatabase.CreateAsset.
5757
/// </summary>
5858
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
59-
internal static void CreateInstance(GUID platformId, string assetPath, int preconfiguredSettingsVariant = -1)
59+
internal static void CreateInstance(GUID platformId, string assetPath)
60+
{
61+
CreateInstance(platformId, assetPath, -1, Array.Empty<string>());
62+
}
63+
64+
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
65+
internal static void CreateInstance(GUID platformId, string assetPath, int preconfiguredSettingsVariant, string[] packagesToAdd)
6066
{
6167
var (buildTarget, subtarget) = BuildProfileModuleUtil.GetBuildTargetAndSubtarget(platformId);
6268
var buildProfile = CreateInstance<BuildProfile>();
@@ -66,8 +72,8 @@ internal static void CreateInstance(GUID platformId, string assetPath, int preco
6672
AssetDatabase.CreateAsset(
6773
buildProfile,
6874
AssetDatabase.GenerateUniqueAssetPath(assetPath));
75+
BuildProfileContext.instance.AddPackageAddInfo(buildProfile, packagesToAdd, preconfiguredSettingsVariant);
6976
buildProfile.OnEnable();
70-
buildProfile.NotifyBuildProfileExtensionOfCreation(preconfiguredSettingsVariant);
7177
// Notify the UI of creation so that the new build profile can be selected
7278
onBuildProfileCreated?.Invoke(buildProfile);
7379
}
@@ -78,7 +84,10 @@ internal void NotifyBuildProfileExtensionOfCreation(int preconfiguredSettingsVar
7884
if (buildProfileExtension != null)
7985
{
8086
buildProfileExtension.OnBuildProfileCreated(this, preconfiguredSettingsVariant);
87+
SerializePlayerSettings();
88+
AssetDatabase.SaveAssetIfDirty(this);
8189
}
90+
BuildProfileContext.instance.ClearPackageAddInfo(this);
8291
}
8392

8493
void TryCreatePlatformSettings()
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using UnityEngine;
7+
using UnityEngine.Bindings;
8+
using System.Collections.Generic;
9+
10+
namespace UnityEditor.Build.Profile;
11+
12+
[VisibleToOtherModules]
13+
internal class BuildProfilePackageAddInfo
14+
{
15+
public const int preconfiguredSettingsVariantNotSet = -2;
16+
17+
public enum ProgressState
18+
{
19+
PackageStateUnknown,
20+
PackagePending,
21+
PackageDownloading,
22+
PackageInstalling,
23+
PackageReady,
24+
PackageError,
25+
ConfigurationPending,
26+
ConfigurationRunning
27+
}
28+
29+
public record struct ProgressEntry(ProgressState state, string name);
30+
31+
[SerializeField]
32+
public string profileGuid = string.Empty;
33+
[SerializeField]
34+
public string[] packagesToAdd { get; set; } = Array.Empty<string>();
35+
[SerializeField]
36+
public int preconfiguredSettingsVariant { get; set; } = preconfiguredSettingsVariantNotSet;
37+
38+
public Action OnPackageAddProgress;
39+
public Action OnPackageAddComplete;
40+
41+
PackageManager.Requests.AddAndRemoveRequest m_PackageAddRequest = null;
42+
List<ProgressEntry> m_PackageAddProgressInfo = new();
43+
44+
public void RequestPackageInstallation()
45+
{
46+
if (packagesToAdd.Length > 0)
47+
{
48+
m_PackageAddRequest = PackageManager.Client.AddAndRemove(packagesToAdd);
49+
m_PackageAddRequest.progressUpdated += HandlePackageAddProgress;
50+
}
51+
else if (preconfiguredSettingsVariant != preconfiguredSettingsVariantNotSet)
52+
{
53+
OnPackageAddComplete?.Invoke();
54+
}
55+
}
56+
57+
public IReadOnlyList<ProgressEntry> GetPackageAddProgressInfo() => m_PackageAddProgressInfo;
58+
59+
bool ContainsPackage(string name)
60+
{
61+
foreach (var package in packagesToAdd)
62+
{
63+
if (package == name)
64+
return true;
65+
}
66+
return false;
67+
}
68+
69+
void HandlePackageAddProgress(PackageManager.ProgressUpdateEventArgs progress)
70+
{
71+
bool done = true;
72+
var info = new List<ProgressEntry>();
73+
foreach (var entry in progress.entries)
74+
{
75+
if (ContainsPackage(entry.name))
76+
{
77+
switch (entry.state)
78+
{
79+
case PackageManager.ProgressState.Ready:
80+
info.Add(new ProgressEntry(ProgressState.PackageReady, entry.name));
81+
break;
82+
case PackageManager.ProgressState.Error:
83+
info.Add(new ProgressEntry(ProgressState.PackageError, entry.name));
84+
break;
85+
case PackageManager.ProgressState.Pending:
86+
info.Add(new ProgressEntry(ProgressState.PackagePending, entry.name));
87+
done = false;
88+
break;
89+
case PackageManager.ProgressState.Downloading:
90+
info.Add(new ProgressEntry(ProgressState.PackageDownloading, entry.name));
91+
done = false;
92+
break;
93+
case PackageManager.ProgressState.Installing:
94+
info.Add(new ProgressEntry(ProgressState.PackageInstalling, entry.name));
95+
done = false;
96+
break;
97+
default:
98+
info.Add(new ProgressEntry(ProgressState.PackageStateUnknown, entry.name));
99+
done = false;
100+
break;
101+
}
102+
}
103+
}
104+
info.Add(new ProgressEntry(done ? ProgressState.ConfigurationRunning : ProgressState.ConfigurationPending, string.Empty));
105+
m_PackageAddProgressInfo = info;
106+
OnPackageAddProgress?.Invoke();
107+
if (done)
108+
{
109+
m_PackageAddRequest = null;
110+
packagesToAdd = Array.Empty<string>();
111+
OnPackageAddComplete?.Invoke();
112+
}
113+
}
114+
}

Editor/Mono/EditorApplication.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ static void Internal_PauseStateChanged(PauseState state)
475475
#pragma warning disable 618
476476
playmodeStateChanged?.Invoke();
477477
#pragma warning restore 618
478-
479-
using var scope = new ProgressScope($"PauseStateChanged Callback", "" , forceShow: true);
478+
using var scope = new ProgressScope($"PauseStateChanged Callback", "" , forceUpdate: true);
480479
foreach (var evt in m_PauseStateChangedEvent)
481480
{
482481
scope.SetText($"{evt.Method?.DeclaringType?.FullName}.{evt.Method?.Name}", true);
@@ -506,7 +505,7 @@ static void Internal_PlayModeStateChanged(PlayModeStateChange state)
506505
}
507506
return;
508507
}
509-
using var scope = new ProgressScope($"PlayModeStateChanged Callback ({stateName})", "", forceShow: true);
508+
using var scope = new ProgressScope($"PlayModeStateChanged Callback ({stateName})", "", forceUpdate: true);
510509
foreach (var evt in m_PlayModeStateChangedEvent)
511510
{
512511
scope.SetText($"{evt.Method?.DeclaringType?.FullName}.{evt.Method?.Name}", true);

Editor/Mono/EditorAssemblies.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ private static void SetLoadedEditorAssemblies(Assembly[] assemblies)
102102
[RequiredByNativeCode]
103103
private static void ProcessInitializeOnLoadAttributes(Type[] types)
104104
{
105+
if (types.Length == 0)
106+
return;
105107
bool reportTimes = (bool)Debug.GetDiagnosticSwitch("EnableDomainReloadTimings").value;
106108

107109
IEnumerable<Type> sortedTypes;
@@ -113,15 +115,18 @@ private static void ProcessInitializeOnLoadAttributes(Type[] types)
113115
sortedTypes = types.OrderBy(x => Array.IndexOf(m_topologicallySortedAssemblies, x.Assembly));
114116
}
115117

116-
using var scope = new ProgressScope("Process InitializeOnLoad Attributes", "", forceShow: true);
118+
bool detailedProgress = types.Length <= (uint) Debug.GetDiagnosticSwitch("MaxInitializeAttributeDetailOnProgressBar").value;
119+
120+
using var scope = new ProgressScope(detailedProgress ? "Processing InitializeOnLoad Attributes" : "Processing many InitializeOnLoad Attributes", "Hold on...", forceUpdate: true);
117121

118122
foreach (Type type in sortedTypes)
119123
{
120124
using (_profilerMarkerProcessInitializeOnLoadAttributes.Auto(reportTimes,
121125
() => type.AssemblyQualifiedName))
122126
{
123127
var typeFullName = type?.FullName;
124-
scope.SetText($"{typeFullName}.{typeFullName}", true);
128+
if (detailedProgress)
129+
scope.SetText($"{typeFullName}.{typeFullName}", true);
125130
try
126131
{
127132
RuntimeHelpers.RunClassConstructor(type.TypeHandle);
@@ -142,13 +147,18 @@ private static void ProcessInitializeOnLoadAttributes(Type[] types)
142147
private static void ProcessInitializeOnLoadMethodAttributes()
143148
{
144149
bool reportTimes = (bool)Debug.GetDiagnosticSwitch("EnableDomainReloadTimings").value;
145-
using var scope = new ProgressScope("Process InitializeOnLoadMethod Attributes", "", forceShow: true);
146-
foreach (var method in TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>())
150+
var methods = TypeCache.GetMethodsWithAttribute<InitializeOnLoadMethodAttribute>();
151+
if (methods.Count == 0) return;
152+
bool showDetail = methods.Count <= (uint) Debug.GetDiagnosticSwitch("MaxInitializeAttributeDetailOnProgressBar").value;
153+
154+
using var scope = new ProgressScope(showDetail ? "Processing InitializeOnLoadMethod Attributes" : "Processing many InitializeOnLoadMethods", "Hold on...", forceUpdate: true);
155+
foreach (var method in methods)
147156
{
148157
using (_profilerMarkerProcessInitializeOnLoadMethodAttributes.Auto(reportTimes,
149158
() => $"{method.DeclaringType?.FullName}::{method.Name}"))
150159
{
151-
scope.SetText($"${method.DeclaringType?.FullName}.{method?.Name}", true);
160+
if (showDetail)
161+
scope.SetText($"{method.DeclaringType?.FullName}.{method?.Name}", true);
152162
try
153163
{
154164
method.Invoke(null, null);

Editor/Mono/GI/UnityComputeBake.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static bool BakeWithDummyProgress(string bakeInputPath, string lightmap
2727
[RequiredByNativeCode]
2828
internal static bool Bake(string bakeInputPath, string lightmapRequestsPath, string lightProbeRequestsPath, string bakeOutputFolderPath, BakeProgressState progressState)
2929
{
30-
Type strangler = Type.GetType("UnityEngine.PathTracing.LightBakerBridge.LightBakerStrangler, Unity.PathTracing.Runtime");
30+
Type strangler = Type.GetType("UnityEditor.PathTracing.LightBakerBridge.LightBakerStrangler, Unity.PathTracing.Editor");
3131
if (strangler == null)
3232
return false;
3333

Editor/Mono/GUI/DockArea.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,11 @@ private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, G
878878
evt.Use();
879879
break;
880880
case 2:
881-
Close(m_Panes[sel]);
882-
evt.Use();
881+
if (!s_HasStaticTabsCapability)
882+
{
883+
Close(m_Panes[sel]);
884+
evt.Use();
885+
}
883886
break;
884887
}
885888
}

0 commit comments

Comments
 (0)