Skip to content

Commit 0e55b91

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a7 C# reference source code
1 parent 94bcde1 commit 0e55b91

File tree

111 files changed

+2948
-1445
lines changed

Some content is hidden

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

111 files changed

+2948
-1445
lines changed

Editor/Mono/Annotation/SceneRenderModeWindow.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ internal class SceneRenderModeWindow : PopupWindowContent
8383
{
8484
static class Styles
8585
{
86-
private static GUIStyle s_MenuItem;
87-
private static GUIStyle s_Separator;
86+
private static GUIStyle menuItem;
87+
private static GUIStyle separator;
88+
private static GUIContent debuggerLabel;
8889

89-
public static GUIStyle sMenuItem => s_MenuItem ?? (s_MenuItem = "MenuItem");
90-
public static GUIStyle sSeparator => s_Separator ?? (s_Separator = "sv_iconselector_sep");
90+
public static GUIStyle s_MenuItem => menuItem ?? (menuItem = "MenuItem");
91+
public static GUIStyle s_Separator => separator ?? (separator = "sv_iconselector_sep");
92+
public static GUIContent s_DebuggerLabel => debuggerLabel ??= EditorGUIUtility.TrTextContent("Rendering Debugger...");
9193

9294
private static readonly string kShadingMode = "Shading Mode";
9395
private static readonly string kMiscellaneous = "Miscellaneous";
@@ -220,27 +222,27 @@ private void DrawSeparator(ref Rect rect)
220222
labelRect.width -= kHeaderHorizontalPadding * 2;
221223
labelRect.height = kSeparatorHeight;
222224

223-
GUI.Label(labelRect, GUIContent.none, Styles.sSeparator);
225+
GUI.Label(labelRect, GUIContent.none, Styles.s_Separator);
224226
rect.y += kSeparatorHeight;
225227
}
226228

227229
//Opens render debugger window located at \newSRP\unity\Packages\com.unity.render-pipelines.core\Editor\Debugging\DebugWindow.cs
228230
private void DrawRenderingDebuggerShortCut(Rect rect)
229231
{
230-
GUIContent label = new GUIContent("Rendering Debugger...");
231232
var labelRect = rect;
232-
labelRect.y += (kHeaderVerticalPadding * 2f);
233-
labelRect.x += kHeaderHorizontalPadding + 15f;
234-
labelRect.width = EditorStyles.foldout.CalcSize(label).x;
235-
labelRect.height = EditorStyles.foldout.CalcSize(label).y;
233+
labelRect.y += kHeaderVerticalPadding;
234+
EditorGUI.LabelField(labelRect,string.Empty, Styles.s_MenuItem);
235+
labelRect.x -= kHeaderHorizontalPadding;
236+
var debuggerLabelSize = EditorStyles.foldout.CalcSize(Styles.s_DebuggerLabel);
237+
labelRect.height = debuggerLabelSize.y;
236238

237-
if (GUI.Button(labelRect, label, EditorStyles.label))
239+
if (GUI.Button(labelRect, Styles.s_DebuggerLabel, Styles.s_MenuItem))
238240
{
239241
EditorApplication.ExecuteMenuItem("Window/Analysis/Rendering Debugger");
240242
editorWindow.Close();
241243
}
244+
rect.y += labelRect.height;
242245

243-
rect.y += EditorGUI.kSingleLineHeight;
244246
}
245247

246248
private void Draw(float listElementWidth)
@@ -268,10 +270,11 @@ private void Draw(float listElementWidth)
268270
}
269271

270272
bool previousState = foldoutStates[lastSection];
271-
foldoutStates[lastSection] = EditorGUI.Foldout(
272-
new Rect(drawPos.x + kHeaderHorizontalPadding, drawPos.y, drawPos.width,
273-
EditorGUI.kSingleLineHeight), foldoutStates[lastSection],
274-
EditorGUIUtility.TextContent(lastSection), true);
273+
Rect foldoutRect = new Rect(drawPos.x, drawPos.y, drawPos.width, EditorGUI.kSingleLineHeight);
274+
275+
EditorGUI.LabelField(foldoutRect,string.Empty, Styles.s_MenuItem);
276+
foldoutStates[lastSection] = EditorGUI.Foldout(foldoutRect, foldoutStates[lastSection], EditorGUIUtility.TextContent(lastSection), true);
277+
275278
drawPos.y += EditorGUI.kSingleLineHeight;
276279

277280
if (previousState != foldoutStates[lastSection])
@@ -358,7 +361,7 @@ void DoBuiltinMode(ref Rect rect, SceneView.CameraMode mode)
358361
EditorGUI.BeginChangeCheck();
359362

360363
GUI.Toggle(rect, m_SceneView.cameraMode == mode, EditorGUIUtility.TextContent(mode.name),
361-
Styles.sMenuItem);
364+
Styles.s_MenuItem);
362365
if (EditorGUI.EndChangeCheck())
363366
{
364367
m_SceneView.cameraMode = mode;

Editor/Mono/AssetPipeline/LocalCacheServer.cs

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

5-
using System.Diagnostics;
65
using System.IO;
7-
using System;
8-
using System.Net;
9-
using System.Net.Sockets;
10-
using UnityEditor.Scripting;
116
using UnityEditor.Utils;
12-
using UnityEngine;
13-
using UnityEngine.Scripting;
147

158
namespace UnityEditor
169
{
17-
internal class LocalCacheServer : ScriptableSingleton<LocalCacheServer>
10+
internal class LocalCacheServer
1811
{
19-
[SerializeField] public string path;
20-
[SerializeField] public int port;
21-
[SerializeField] public ulong size;
22-
[SerializeField] public int pid = -1;
23-
[SerializeField] public string time;
24-
25-
public const string SizeKey = "LocalCacheServerSize";
2612
public const string PathKey = "LocalCacheServerPath";
2713
public const string CustomPathKey = "LocalCacheServerCustomPath";
2814

@@ -36,195 +22,21 @@ public static string GetCacheLocation()
3622
return result;
3723
}
3824

39-
public static void CreateCacheDirectory()
40-
{
41-
string cacheDirectoryPath = GetCacheLocation();
42-
if (Directory.Exists(cacheDirectoryPath) == false)
43-
Directory.CreateDirectory(cacheDirectoryPath);
44-
}
45-
46-
void Create(int _port, ulong _size)
47-
{
48-
var nodeExecutable = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "nodejs");
49-
if (Application.platform == RuntimePlatform.WindowsEditor)
50-
nodeExecutable = Paths.Combine(nodeExecutable, "node.exe");
51-
else
52-
nodeExecutable = Paths.Combine(nodeExecutable, "bin", "node");
53-
54-
CreateCacheDirectory();
55-
path = GetCacheLocation();
56-
var cacheServerJs = Paths.Combine(EditorApplication.applicationContentsPath, "Tools", "CacheServer", "main.js");
57-
var processStartInfo = new ProcessStartInfo(nodeExecutable)
58-
{
59-
Arguments = "\"" + cacheServerJs + "\""
60-
+ " --port " + _port
61-
+ " --path \"" + path
62-
+ "\" --nolegacy"
63-
+ " --monitor-parent-process " + Process.GetCurrentProcess().Id
64-
// node.js has issues running on windows with stdout not redirected.
65-
// so we silence logging to avoid that. And also to avoid CacheServer
66-
// spamming the editor logs on OS X.
67-
+ " --silent"
68-
+ " --size " + _size,
69-
UseShellExecute = false,
70-
CreateNoWindow = true
71-
};
72-
73-
var p = new Process();
74-
p.StartInfo = processStartInfo;
75-
p.Start();
76-
77-
port = _port;
78-
pid = p.Id;
79-
size = _size;
80-
time = p.StartTime.ToString();
81-
Save(true);
82-
}
83-
84-
public static int GetRandomUnusedPort()
85-
{
86-
var listener = new TcpListener(IPAddress.Any, 0);
87-
listener.Start();
88-
var port = ((IPEndPoint)listener.LocalEndpoint).Port;
89-
listener.Stop();
90-
return port;
91-
}
92-
93-
public static bool PingHost(string host, int port, int timeout)
94-
{
95-
try
96-
{
97-
using (var client = new TcpClient())
98-
{
99-
var result = client.BeginConnect(host, port, null, null);
100-
result.AsyncWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeout));
101-
return client.Connected;
102-
}
103-
}
104-
catch
105-
{
106-
return false;
107-
}
108-
}
109-
110-
public static bool WaitForServerToComeAlive(int port)
111-
{
112-
DateTime start = DateTime.Now;
113-
DateTime maximum = start.AddSeconds(5);
114-
while (DateTime.Now < maximum)
115-
{
116-
if (PingHost("localhost", port, 10))
117-
{
118-
System.Console.WriteLine("Server Came alive after {0} ms", (DateTime.Now - start).TotalMilliseconds);
119-
return true;
120-
}
121-
}
122-
return false;
123-
}
124-
125-
public static void Kill()
126-
{
127-
if (instance.pid == -1)
128-
return;
129-
130-
Process p = null;
131-
try
132-
{
133-
p = Process.GetProcessById(instance.pid);
134-
p.Kill();
135-
instance.pid = -1;
136-
}
137-
catch
138-
{
139-
// if we could not get a process, there is non alive. continue.
140-
}
141-
}
142-
143-
public static void CreateIfNeeded()
144-
{
145-
// See if we can get an existing process with the PID we remembered.
146-
Process p = null;
147-
try
148-
{
149-
p = Process.GetProcessById(instance.pid);
150-
}
151-
catch
152-
{
153-
// if we could not get a process, there is non alive. continue.
154-
}
155-
156-
ulong size = (ulong)EditorPrefs.GetInt(SizeKey, 10) * 1024 * 1024 * 1024;
157-
// Check if this process is really the one we used (and not another one reusing the PID).
158-
if (p != null && p.StartTime.ToString() == instance.time)
159-
{
160-
if (instance.size == size && instance.path == GetCacheLocation())
161-
{
162-
// We have a server running for this setup, which we can reuse, but make sure that the cache server directory exists in case it was cleaned earlier
163-
CreateCacheDirectory();
164-
return;
165-
}
166-
else
167-
{
168-
// This server does not match our setup. Kill it, so we can start a new one.
169-
Kill();
170-
}
171-
}
172-
173-
// No existing server we can use. Start a new one.
174-
instance.Create(GetRandomUnusedPort(), size);
175-
WaitForServerToComeAlive(instance.port);
176-
}
177-
17825
public static void Setup()
17926
{
18027
var mode = (AssetPipelinePreferences.CacheServerMode)EditorPrefs.GetInt("CacheServerMode");
18128

18229
if (mode == AssetPipelinePreferences.CacheServerMode.Local)
183-
CreateIfNeeded();
184-
else
185-
Kill();
186-
}
187-
188-
[UsedByNativeCode]
189-
public static int GetLocalCacheServerPort()
190-
{
191-
Setup();
192-
return instance.port;
30+
{
31+
EditorGUILayout.HelpBox("Local CacheServer is no longer supported", MessageType.Info, true);
32+
}
19333
}
19434

19535
public static void Clear()
19636
{
197-
Kill();
19837
string cacheDirectoryPath = GetCacheLocation();
19938
if (Directory.Exists(cacheDirectoryPath))
20039
Directory.Delete(cacheDirectoryPath, true);
20140
}
202-
203-
public static bool CheckCacheLocationExists()
204-
{
205-
return Directory.Exists(GetCacheLocation());
206-
}
207-
208-
public static bool CheckValidCacheLocation(string path)
209-
{
210-
if (Directory.Exists(path))
211-
{
212-
var contents = Directory.GetFileSystemEntries(path);
213-
foreach (var dir in contents)
214-
{
215-
var name = Path.GetFileName(dir).ToLower();
216-
if (name.Length == 2)
217-
continue;
218-
if (name == "temp")
219-
continue;
220-
if (name == ".ds_store")
221-
continue;
222-
if (name == "desktop.ini")
223-
continue;
224-
return false;
225-
}
226-
}
227-
return true;
228-
}
22941
}
23042
}

Editor/Mono/Audio/AudioContainerListDragAndDropManipulator.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ protected override void RegisterCallbacksOnTarget()
2828

2929
protected override void UnregisterCallbacksFromTarget()
3030
{
31-
target.UnregisterCallback<DragUpdatedEvent>(OnDragUpdate);
32-
target.UnregisterCallback<DragPerformEvent>(OnDragPerform);
31+
target?.UnregisterCallback<DragUpdatedEvent>(OnDragUpdate);
32+
target?.UnregisterCallback<DragPerformEvent>(OnDragPerform);
3333
}
3434

35-
void OnDragUpdate(DragUpdatedEvent _)
35+
static void OnDragUpdate(DragUpdatedEvent _)
3636
{
3737
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
3838
}
@@ -44,13 +44,15 @@ void OnDragPerform(DragPerformEvent evt)
4444
foreach (var path in DragAndDrop.paths)
4545
{
4646
var audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(path);
47-
if (audioClip != null) audioClips.Add(audioClip);
47+
48+
if (audioClip != null)
49+
audioClips.Add(audioClip);
4850
}
4951

5052
if (audioClips.Count > 0)
5153
{
5254
DragAndDrop.AcceptDrag();
53-
addAudioClipsDelegate(audioClips);
55+
addAudioClipsDelegate?.Invoke(audioClips);
5456
}
5557
}
5658
}

0 commit comments

Comments
 (0)