Skip to content

Commit b7836ef

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a16 C# reference source code
1 parent 37afe6d commit b7836ef

File tree

134 files changed

+4208
-1131
lines changed

Some content is hidden

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

134 files changed

+4208
-1131
lines changed

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ void CreateGUI()
248248

249249
m_Day0RootVisualElement.style.display = DisplayStyle.None;
250250
m_ContainerRootVisualElement.style.display = DisplayStyle.Flex;
251+
m_ClipsListView.Rebuild(); // Force a list rebuild when the list has changed or it will not always render correctly due to a UI toolkit bug.
251252
}
252253
}
253254
finally

Editor/Mono/BuildPlayerSceneTreeView.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public BuildPlayerSceneTreeViewItem(EditorBuildSettingsScene scene) : base(scene
5454
UpdateName();
5555
}
5656
}
57+
5758
internal class BuildPlayerSceneTreeView : TreeView
5859
{
5960
public BuildPlayerSceneTreeView(TreeViewState state) : base(state)
@@ -77,7 +78,7 @@ protected override TreeViewItem BuildRoot()
7778
var root = new TreeViewItem(-1, -1);
7879
root.children = new List<TreeViewItem>();
7980

80-
List<EditorBuildSettingsScene> scenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes);
81+
List<EditorBuildSettingsScene> scenes = new List<EditorBuildSettingsScene>(GetScenes());
8182
foreach (var sc in scenes)
8283
{
8384
var item = new BuildPlayerSceneTreeViewItem(sc);
@@ -145,7 +146,7 @@ protected override void RowGUI(RowGUIArgs args)
145146
sceneItem.active = newState;
146147
}
147148

148-
EditorBuildSettings.scenes = GetSceneList();
149+
SetScenes(GetSceneList());
149150
}
150151

151152
base.RowGUI(args);
@@ -202,7 +203,7 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
202203
}
203204
}
204205
rootItem.children = result;
205-
EditorBuildSettings.scenes = GetSceneList();
206+
SetScenes(GetSceneList());
206207
ReloadAndSelect(draggedIDs);
207208
Repaint();
208209
}
@@ -212,7 +213,7 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
212213
visualMode = DragAndDropVisualMode.Copy;
213214
if (args.performDrop)
214215
{
215-
var scenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes);
216+
var scenes = new List<EditorBuildSettingsScene>(GetScenes());
216217
var scenesToAdd = new List<EditorBuildSettingsScene>();
217218
var selection = new List<int>();
218219

@@ -240,7 +241,7 @@ protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args)
240241

241242
int newIndex = FindDropAtIndex(args);
242243
scenes.InsertRange(newIndex, scenesToAdd);
243-
EditorBuildSettings.scenes = scenes.ToArray();
244+
SetScenes(scenes.ToArray());
244245
ReloadAndSelect(selection);
245246
Repaint();
246247
}
@@ -311,11 +312,14 @@ protected void RemoveSelection()
311312
{
312313
rootItem.children.Remove(FindItem(nodeID, rootItem));
313314
}
314-
EditorBuildSettings.scenes = GetSceneList();
315+
SetScenes(GetSceneList());
315316
Reload();
316317
Repaint();
317318
}
318319

320+
protected virtual EditorBuildSettingsScene[] GetScenes() => EditorBuildSettings.scenes;
321+
protected virtual void SetScenes(EditorBuildSettingsScene[] scenes) => EditorBuildSettings.scenes = scenes;
322+
319323
public EditorBuildSettingsScene[] GetSceneList()
320324
{
321325
var sceneList = new EditorBuildSettingsScene[rootItem.children.Count];

Editor/Mono/BuildProfile/BuildProfile.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5+
using System;
56
using System.Runtime.InteropServices;
67
using UnityEngine;
78
using UnityEngine.Bindings;
@@ -57,14 +58,94 @@ public BuildProfilePlatformSettingsBase platformBuildProfile
5758
internal set => m_PlatformBuildProfile = value;
5859
}
5960

61+
[SerializeField] private EditorBuildSettingsScene[] m_Scenes = Array.Empty<EditorBuildSettingsScene>();
62+
public EditorBuildSettingsScene[] scenes
63+
{
64+
get
65+
{
66+
CheckSceneListConsistency();
67+
return m_Scenes;
68+
}
69+
set
70+
{
71+
if (m_Scenes == value)
72+
return;
73+
74+
m_Scenes = value;
75+
CheckSceneListConsistency();
76+
77+
if (this == BuildProfileContext.instance.activeProfile)
78+
EditorBuildSettings.SceneListChanged();
79+
}
80+
}
81+
6082
void OnEnable()
6183
{
6284
// Check if the platform support module has been installed,
6385
// and try to set an uninitialized platform settings.
6486
if (platformBuildProfile == null)
6587
TryCreatePlatformSettings();
6688

89+
CheckSceneListConsistency();
6790
onBuildProfileEnable?.Invoke(this);
6891
}
92+
93+
/// <summary>
94+
/// EditorBuildSettingsScene stores both path and GUID. Path can become
95+
/// invalid when scenes are moved or renamed and must be recalculated.
96+
/// </summary>
97+
/// <see cref="EditorBuildSettings"/> native function, EnsureScenesAreValid.
98+
void CheckSceneListConsistency()
99+
{
100+
int length = m_Scenes.Length;
101+
for (int i = length - 1; i >= 0; i--)
102+
{
103+
var scene = m_Scenes[i];
104+
105+
// EditorBuildSettingScene entry may be null.
106+
if (scene == null)
107+
{
108+
RemoveAt(i);
109+
continue;
110+
}
111+
112+
bool isGuidValid = !scene.guid.Empty();
113+
if (isGuidValid)
114+
{
115+
// Scene may have been moved or renamed.
116+
scene.path = AssetDatabase.GUIDToAssetPath(scene.guid);
117+
}
118+
119+
if (string.IsNullOrEmpty(scene.path))
120+
{
121+
// Scene Object may have been deleted from disk.
122+
RemoveAt(i);
123+
continue;
124+
}
125+
126+
if (!isGuidValid)
127+
scene.guid = AssetDatabase.GUIDFromAssetPath(scene.path);
128+
129+
// Asset may have been deleted. AssetDatabase may cache GUID to/from
130+
// path mapping.
131+
if (AssetDatabase.GetMainAssetTypeFromGUID(scene.guid) is null)
132+
RemoveAt(i);
133+
}
134+
135+
if (length == m_Scenes.Length)
136+
return;
137+
138+
var result = new EditorBuildSettingsScene[length];
139+
Array.Copy(m_Scenes, result, length);
140+
m_Scenes = result;
141+
EditorUtility.SetDirty(this);
142+
return;
143+
144+
void RemoveAt(int index)
145+
{
146+
length--;
147+
Array.Copy(m_Scenes, index + 1, m_Scenes, index, length - index);
148+
}
149+
}
69150
}
70151
}

Editor/Mono/BuildProfile/BuildProfileContext.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,22 @@ internal static BuildProfile GetClassicProfileAndResetActive(
183183
// the classic platform build profile directly. When doing this, the next getter
184184
// MUST return the classic platform build profile containing the newly set value.
185185
// The active build profile should be updated directly.
186-
Debug.LogWarning($"[BuildProfile] Active build profile ({AssetDatabase.GetAssetPath(instance.activeProfile)}) is set when calling a legacy setter for the same platform. For backwards compatibility, the active build profile has been unset.");
187-
instance.activeProfile = null;
186+
ResetActiveProfile();
188187
}
189188

190189
return IsSharedProfile(target) ? instance.sharedProfile : instance.GetForClassicPlatform(target, subTarget);
191190
}
192191

192+
[RequiredByNativeCode, UsedImplicitly]
193+
internal static void ResetActiveProfile()
194+
{
195+
if (instance.activeProfile is null)
196+
return;
197+
198+
Debug.LogWarning($"[BuildProfile] Active build profile ({AssetDatabase.GetAssetPath(instance.activeProfile)}) is set when calling a global platform API.");
199+
instance.activeProfile = null;
200+
}
201+
193202
internal static bool TryGetActiveOrClassicPlatformSettingsBase<T>(
194203
BuildTarget target, StandaloneBuildSubtarget subTarget, out T result) where T : BuildProfilePlatformSettingsBase
195204
{
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.Collections.Generic;
6+
using UnityEditor.IMGUI.Controls;
7+
using UnityEditor.SceneManagement;
8+
using UnityEngine;
9+
using UnityEngine.Bindings;
10+
using UnityEngine.SceneManagement;
11+
12+
namespace UnityEditor.Build.Profile
13+
{
14+
/// <summary>
15+
/// Handles mapping the existing <see cref="BuildPlayerSceneTreeView"/> component
16+
/// to build profile. Classic platforms specifically target scenes stored in
17+
/// <see cref="EditorBuildSettings"/>.
18+
/// </summary>
19+
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
20+
internal class BuildProfileSceneTreeView : BuildPlayerSceneTreeView
21+
{
22+
readonly bool m_IsEditorBuildSettingsSceneList;
23+
readonly BuildProfile m_Target;
24+
25+
public BuildProfileSceneTreeView(TreeViewState state, BuildProfile target) : base(state)
26+
{
27+
m_Target = target;
28+
m_IsEditorBuildSettingsSceneList = target == null;
29+
}
30+
31+
/// <summary>
32+
/// Exported from <see cref="BuildPlayerWindow"/>.
33+
/// </summary>
34+
public void AddOpenScenes()
35+
{
36+
List<EditorBuildSettingsScene> list = new List<EditorBuildSettingsScene>(GetScenes());
37+
38+
bool isSceneAdded = false;
39+
for (int i = 0; i < SceneManager.sceneCount; i++)
40+
{
41+
Scene scene = SceneManager.GetSceneAt(i);
42+
43+
if (EditorSceneManager.IsAuthoringScene(scene))
44+
continue;
45+
46+
if (scene.path.Length == 0 && !EditorSceneManager.SaveScene(scene, "", false))
47+
continue;
48+
49+
if (list.Exists(s => s.path == scene.path))
50+
continue;
51+
52+
GUID newGUID;
53+
GUID.TryParse(scene.guid, out newGUID);
54+
var buildSettingsScene = (newGUID == default(GUID)) ?
55+
new EditorBuildSettingsScene(scene.path, true) :
56+
new EditorBuildSettingsScene(newGUID, true);
57+
list.Add(buildSettingsScene);
58+
isSceneAdded = true;
59+
}
60+
61+
if (!isSceneAdded)
62+
return;
63+
64+
SetScenes(list.ToArray());
65+
Reload();
66+
GUIUtility.ExitGUI();
67+
}
68+
69+
protected override EditorBuildSettingsScene[] GetScenes() => (m_IsEditorBuildSettingsSceneList)
70+
? EditorBuildSettings.GetEditorBuildSettingsSceneIgnoreProfile()
71+
: m_Target.scenes;
72+
73+
protected override void SetScenes(EditorBuildSettingsScene[] scenes)
74+
{
75+
if (!m_IsEditorBuildSettingsSceneList)
76+
{
77+
Undo.RecordObject(m_Target, "Scene list");
78+
m_Target.scenes = scenes;
79+
EditorUtility.SetDirty(m_Target);
80+
return;
81+
}
82+
83+
// Classic platforms scene list can only be changed through this component
84+
// and write data directly to EditorBuildSettings.
85+
EditorBuildSettings.SetEditorBuildSettingsSceneIgnoreProfile(scenes);
86+
if (BuildProfileContext.instance.activeProfile is null)
87+
EditorBuildSettings.SceneListChanged();
88+
}
89+
}
90+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 System.Collections.Generic;
7+
using UnityEngine.Bindings;
8+
9+
namespace UnityEditor.Build.Profile
10+
{
11+
[VisibleToOtherModules]
12+
internal enum ActionState
13+
{
14+
/// <summary>
15+
/// Action is visible and clickable.
16+
/// </summary>
17+
Enabled,
18+
19+
/// <summary>
20+
/// Action is visible and non-clickable.
21+
/// </summary>
22+
Disabled,
23+
24+
/// <summary>
25+
/// Action is hidden.
26+
/// </summary>
27+
Hidden
28+
}
29+
30+
[VisibleToOtherModules]
31+
internal class BuildProfileWorkflowState
32+
{
33+
Action<BuildProfileWorkflowState> m_OnStateChanged;
34+
35+
public BuildProfileWorkflowState(Action<BuildProfileWorkflowState> onStateChanged)
36+
{
37+
this.m_OnStateChanged = onStateChanged;
38+
}
39+
40+
/// <summary>
41+
/// When set, build actions in the Build Profile Window will query the user for a build location.
42+
/// </summary>
43+
public bool askForBuildLocation { get; set; } = true;
44+
45+
/// <summary>
46+
/// Name to be displayed in the build button name
47+
/// </summary>
48+
public string buildButtonDisplayName { get; set; } = L10n.Tr("Build");
49+
50+
/// <summary>
51+
/// Name to be displayed in the build and run button name
52+
/// </summary>
53+
public string buildAndRunButtonDisplayName { get; set; } = L10n.Tr("Build And Run");
54+
55+
/// <summary>
56+
/// Activate action allows a profile to be set as active profile.
57+
/// </summary>
58+
public ActionState activateAction { get; set; } = ActionState.Enabled;
59+
60+
/// <summary>
61+
/// Allows invoking the Build Pipeline for the selected profile.
62+
/// </summary>
63+
public ActionState buildAction { get; set; } = ActionState.Enabled;
64+
65+
/// <summary>
66+
/// Allows invoking the Build Pipeline for the selected profile with BuildAndRun flag set.
67+
/// </summary>
68+
public ActionState buildAndRunAction { get; set; } = ActionState.Enabled;
69+
70+
/// <summary>
71+
/// Additional actions shown in the Build Profile Window as generally defined by the Build Profile Extension.
72+
/// </summary>
73+
/// <remarks>
74+
/// Primary use case is for 'Run Last Build' action from console paltforms which implement
75+
/// module specific build callbacks.
76+
/// </remarks>
77+
public IList<(string displayName, Action callback, ActionState state)> additionalActions { get; set; }
78+
= new List<(string, Action, ActionState)>();
79+
80+
/// <summary>
81+
/// Reprocess the current state.
82+
/// </summary>
83+
public void Refresh() => m_OnStateChanged?.Invoke(this);
84+
85+
/// <summary>
86+
/// Apply the next state, OnStateChanged callback should handle reducing the
87+
/// target state into the current one.
88+
/// </summary>
89+
public void Apply(BuildProfileWorkflowState next) => m_OnStateChanged?.Invoke(next);
90+
91+
/// <summary>
92+
/// Merges two <see cref="ActionState"/> values.
93+
/// </summary>
94+
public static ActionState CalculateActionState(ActionState lhs, ActionState rhs)
95+
{
96+
if (lhs == ActionState.Hidden || rhs == ActionState.Hidden)
97+
return ActionState.Hidden;
98+
if (lhs == ActionState.Disabled || rhs == ActionState.Disabled)
99+
return ActionState.Disabled;
100+
return ActionState.Enabled;
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)