Skip to content

Commit 6ac92f7

Browse files
author
Unity Technologies
committed
Unity 2023.2.0a9 C# reference source code
1 parent 243a8ca commit 6ac92f7

File tree

241 files changed

+11231
-2388
lines changed

Some content is hidden

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

241 files changed

+11231
-2388
lines changed

Editor/Mono/AssetPipeline/SpeedTreeImporter.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse
297297
{
298298
foreach (var asset in importedAssets)
299299
{
300-
bool st8 = asset.EndsWith(".st", StringComparison.InvariantCultureIgnoreCase);
300+
bool st8 = asset.EndsWith(".st", StringComparison.OrdinalIgnoreCase);
301301
if(st8)
302302
{
303303
// Check the external materials in case the user has extracted
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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;
8+
using UnityEngine.UIElements;
9+
10+
namespace UnityEditor;
11+
12+
class AudioContainerListDragAndDropManipulator : PointerManipulator
13+
{
14+
internal delegate void AddAudioClipsDelegate(List<AudioClip> audioClips);
15+
16+
internal AddAudioClipsDelegate addAudioClipsDelegate;
17+
18+
public AudioContainerListDragAndDropManipulator(VisualElement root)
19+
{
20+
target = root.Q<VisualElement>("audio-clips-list-view");
21+
}
22+
23+
protected override void RegisterCallbacksOnTarget()
24+
{
25+
target.RegisterCallback<DragUpdatedEvent>(OnDragUpdate);
26+
target.RegisterCallback<DragPerformEvent>(OnDragPerform);
27+
}
28+
29+
protected override void UnregisterCallbacksFromTarget()
30+
{
31+
target.UnregisterCallback<DragUpdatedEvent>(OnDragUpdate);
32+
target.UnregisterCallback<DragPerformEvent>(OnDragPerform);
33+
}
34+
35+
void OnDragUpdate(DragUpdatedEvent _)
36+
{
37+
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
38+
}
39+
40+
void OnDragPerform(DragPerformEvent evt)
41+
{
42+
var audioClips = new List<AudioClip>();
43+
44+
foreach (var path in DragAndDrop.paths)
45+
{
46+
var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(path);
47+
if (audioClip != null) audioClips.Add(audioClip);
48+
}
49+
50+
if (audioClips.Count > 0)
51+
{
52+
DragAndDrop.AcceptDrag();
53+
addAudioClipsDelegate(audioClips);
54+
}
55+
}
56+
}

Editor/Mono/Audio/AudioContainerWindow.cs

Lines changed: 772 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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.Audio;
8+
using Object = UnityEngine.Object;
9+
10+
namespace UnityEditor;
11+
12+
sealed class AudioContainerWindowState
13+
{
14+
AudioRandomContainer m_AudioContainer;
15+
bool m_IsPlayingOrPaused;
16+
AudioSource m_PreviewAudioSource;
17+
SerializedObject m_SerializedObject;
18+
string m_TargetPath;
19+
20+
internal event EventHandler OnPlaybackStateChanged;
21+
internal event EventHandler OnTargetChanged;
22+
23+
internal AudioContainerWindowState()
24+
{
25+
EditorApplication.playModeStateChanged += OnEditorPlayModeStateChanged;
26+
}
27+
28+
internal AudioRandomContainer AudioContainer
29+
{
30+
get
31+
{
32+
if (m_AudioContainer == null) UpdateTarget();
33+
34+
return m_AudioContainer;
35+
}
36+
}
37+
38+
internal SerializedObject SerializedObject
39+
{
40+
get
41+
{
42+
if (m_AudioContainer != null && (m_SerializedObject == null || m_SerializedObject.targetObject != m_AudioContainer)) m_SerializedObject = new SerializedObject(m_AudioContainer);
43+
44+
return m_SerializedObject;
45+
}
46+
}
47+
48+
internal string TargetPath => m_TargetPath;
49+
50+
bool IsPlayingOrPaused
51+
{
52+
get => m_IsPlayingOrPaused;
53+
set
54+
{
55+
m_IsPlayingOrPaused = value;
56+
OnPlaybackStateChanged?.Invoke(this, EventArgs.Empty);
57+
}
58+
}
59+
60+
internal void Reset()
61+
{
62+
m_AudioContainer = null;
63+
m_SerializedObject = null;
64+
m_IsPlayingOrPaused = false;
65+
m_TargetPath = null;
66+
67+
if (m_PreviewAudioSource != null)
68+
{
69+
Stop();
70+
m_PreviewAudioSource.resource = null;
71+
}
72+
}
73+
74+
internal void OnDestroy()
75+
{
76+
Stop();
77+
EditorApplication.playModeStateChanged -= OnEditorPlayModeStateChanged;
78+
79+
if (m_PreviewAudioSource != null) Object.DestroyImmediate(m_PreviewAudioSource.gameObject);
80+
}
81+
82+
internal void Play()
83+
{
84+
CreatePreviewObjects();
85+
86+
if (!IsReadyToPlay()) return;
87+
88+
m_PreviewAudioSource.Play();
89+
IsPlayingOrPaused = true;
90+
EditorApplication.update += OnEditorApplicationUpdate;
91+
}
92+
93+
internal void Stop()
94+
{
95+
if (!IsPlaying()) return;
96+
97+
m_PreviewAudioSource.Stop();
98+
IsPlayingOrPaused = false;
99+
EditorApplication.update -= OnEditorApplicationUpdate;
100+
}
101+
102+
internal void Skip()
103+
{
104+
if (!IsPlaying()) return;
105+
m_PreviewAudioSource.SkipToNextElementIfHasContainer();
106+
}
107+
108+
internal bool IsPlaying()
109+
{
110+
return IsPlayingOrPaused || (m_PreviewAudioSource != null && m_PreviewAudioSource.isContainerPlaying);
111+
}
112+
113+
internal bool IsReadyToPlay()
114+
{
115+
if (m_AudioContainer == null)
116+
{
117+
return false;
118+
}
119+
120+
CreatePreviewObjects();
121+
122+
if (m_PreviewAudioSource == null)
123+
{
124+
return false;
125+
}
126+
127+
var elements = m_AudioContainer.elements;
128+
var elementCount = m_AudioContainer.elements.Length;
129+
130+
for (var i = 0; i < elementCount; ++i)
131+
{
132+
if (elements[i] != null && elements[i].audioClip != null && elements[i].enabled)
133+
{
134+
return true;
135+
}
136+
}
137+
138+
return false;
139+
}
140+
141+
internal void UpdateTarget()
142+
{
143+
AudioRandomContainer newTarget = null;
144+
var selectedObject = Selection.activeObject;
145+
var audioClipSelected = false;
146+
147+
if (selectedObject != null)
148+
{
149+
if (selectedObject is GameObject go)
150+
{
151+
var audioSource = go.GetComponent<AudioSource>();
152+
153+
if (audioSource != null)
154+
{
155+
newTarget = audioSource.resource as AudioRandomContainer;
156+
}
157+
}
158+
else
159+
{
160+
audioClipSelected = selectedObject is AudioClip;
161+
newTarget = selectedObject as AudioRandomContainer;
162+
}
163+
}
164+
165+
if (!audioClipSelected && newTarget != m_AudioContainer)
166+
{
167+
if (m_AudioContainer != null)
168+
{
169+
Stop();
170+
}
171+
172+
Reset();
173+
m_AudioContainer = newTarget;
174+
175+
if (m_AudioContainer != null)
176+
{
177+
m_TargetPath = AssetDatabase.GetAssetPath(m_AudioContainer);
178+
CreatePreviewObjects();
179+
}
180+
181+
OnTargetChanged?.Invoke(this, EventArgs.Empty);
182+
}
183+
}
184+
185+
// Set up a hidden audio source in the scene for preview purposes
186+
187+
/// <summary>
188+
/// This method creates a hidden game object in the scene with an audio source for editor previewing purposes.
189+
/// The preview object is created with the window and destroyed when the window is closed.
190+
/// This means that this AudioSource object is a hidden part of the user's scene –
191+
/// but only in the editor and only while the window is open.
192+
/// </summary>
193+
void CreatePreviewObjects()
194+
{
195+
if (m_AudioContainer == null) return;
196+
197+
if (m_PreviewAudioSource != null)
198+
{
199+
m_PreviewAudioSource.resource = m_AudioContainer;
200+
return;
201+
}
202+
203+
var audioSourceGO = new GameObject
204+
{
205+
name = "PreviewAudioSource595651",
206+
hideFlags = HideFlags.HideInHierarchy | HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild
207+
};
208+
209+
m_PreviewAudioSource = audioSourceGO.AddComponent<AudioSource>();
210+
m_PreviewAudioSource.playOnAwake = false;
211+
m_PreviewAudioSource.resource = m_AudioContainer;
212+
}
213+
214+
internal bool IsDirty()
215+
{
216+
return m_AudioContainer != null && EditorUtility.IsDirty(m_AudioContainer);
217+
}
218+
219+
void OnEditorApplicationUpdate()
220+
{
221+
if (!IsPlayingOrPaused || !m_PreviewAudioSource.isContainerPlaying)
222+
{
223+
IsPlayingOrPaused = false;
224+
EditorApplication.update -= OnEditorApplicationUpdate;
225+
}
226+
}
227+
228+
void OnEditorPlayModeStateChanged(PlayModeStateChange state)
229+
{
230+
if (state == PlayModeStateChange.ExitingEditMode || state == PlayModeStateChange.ExitingPlayMode)
231+
{
232+
Stop();
233+
}
234+
}
235+
}

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ private static BuildReport BuildPlayer(string[] scenes, string locationPathName,
376376
{
377377
return BuildPlayerInternal(scenes, locationPathName, assetBundleManifestPath, buildTargetGroup, target, subtarget, options, extraScriptingDefines);
378378
}
379+
catch (System.ArgumentException argumentException)
380+
{
381+
Debug.LogException(argumentException);
382+
EditorApplication.Exit(1);
383+
return null;
384+
}
379385
catch (System.Exception exception)
380386
{
381387
// In some case BuildPlayer might let a null reference exception fall through. Prevent data loss by just exiting.
@@ -474,8 +480,8 @@ public static string BuildStreamedSceneAssetBundle(string[] levels, string locat
474480

475481
private static BuildReport BuildPlayerInternal(string[] levels, string locationPathName, string assetBundleManifestPath, BuildTargetGroup buildTargetGroup, BuildTarget target, int subtarget, BuildOptions options, string[] extraScriptingDefines)
476482
{
477-
if (!BuildPlayerWindow.DefaultBuildMethods.IsBuildPathValid(locationPathName))
478-
throw new Exception("Invalid Build Path: " + locationPathName);
483+
if (!BuildPlayerWindow.DefaultBuildMethods.IsBuildPathValid(locationPathName, out var msg))
484+
throw new ArgumentException($"Invalid build path: '{locationPathName}'. {msg}");
479485

480486
return BuildPlayerInternalNoCheck(levels, locationPathName, assetBundleManifestPath, buildTargetGroup, target, subtarget, options, extraScriptingDefines, false);
481487
}

Editor/Mono/BuildPipeline/Android/AndroidPostGenerateGradleProject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace UnityEditor.Android
1111
{
1212
public interface IPostGenerateGradleAndroidProject : IOrderedCallback
1313
{
14+
[Obsolete("OnPostGenerateGradleAndroidProject is deprecated. Use AndroidProjectFilesModifier.OnModifyAndroidProjectFiles instead.")]
1415
void OnPostGenerateGradleAndroidProject(string path);
1516
}
1617
}

0 commit comments

Comments
 (0)