Skip to content

Commit 6230ef8

Browse files
author
Unity Technologies
committed
Unity 2023.3.0a18 C# reference source code
1 parent 496f7d6 commit 6230ef8

File tree

64 files changed

+1033
-439
lines changed

Some content is hidden

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

64 files changed

+1033
-439
lines changed

Editor/Mono/Annotation/SceneFXWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private class Styles
2222

2323
public override Vector2 GetWindowSize()
2424
{
25-
var windowHeight = 2f * kFrameWidth + EditorGUI.kSingleLineHeight * 6;
25+
var windowHeight = 2f * kFrameWidth + EditorGUI.kSingleLineHeight * 7;
2626
if (UnityEngine.VFX.VFXManager.activateVFX)
2727
{
2828
windowHeight += EditorGUI.kSingleLineHeight;

Editor/Mono/AssetPipeline/TextureGenerator.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public struct SpriteImportData
2222
private SpriteAlignment m_Alignment;
2323
private Vector2 m_Pivot;
2424
private Vector4 m_Border;
25+
private string m_CustomData;
2526
private float m_TessellationDetail;
2627
private string m_SpriteID;
2728
private List<Vector2[]> m_Outline;
@@ -31,6 +32,7 @@ public struct SpriteImportData
3132
public SpriteAlignment alignment { get { return m_Alignment; } set { m_Alignment = value; } }
3233
public Vector2 pivot { get { return m_Pivot; } set { m_Pivot = value; } }
3334
public Vector4 border { get { return m_Border; } set { m_Border = value; } }
35+
internal string customData { get { return m_CustomData; } set { m_CustomData = value; } }
3436
public List<Vector2[]> outline { get { return m_Outline; } set { m_Outline = value; } }
3537
public float tessellationDetail {get { return m_TessellationDetail; } set { m_TessellationDetail = value; } }
3638
public string spriteID {get { return m_SpriteID; } set { m_SpriteID = value; } }

Editor/Mono/AssetPipeline/TextureImporterTypes.bindings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public struct SpriteMetaData
1818
public int alignment;
1919
public Vector2 pivot;
2020
public Vector4 border;
21+
internal string customData;
2122
}
2223

2324
// Note: MUST match memory layout of TextureImporterSettings in TextureImporter.h!

Editor/Mono/BuildPipeline/Android/AndroidPostGenerateGradleProject.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace UnityEditor.Android
1111
{
12+
[Obsolete("IPostGenerateGradleAndroidProject is deprecated. Use AndroidProjectFilesModifier instead.")]
1213
public interface IPostGenerateGradleAndroidProject : IOrderedCallback
1314
{
1415
[Obsolete("OnPostGenerateGradleAndroidProject is deprecated. Use AndroidProjectFilesModifier.OnModifyAndroidProjectFiles instead.")]

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public static void ShowBuildPlayerWindow()
160160
GetWindow<BuildPlayerWindow>(false, "Build Settings");
161161
}
162162

163+
internal static bool WillDrawMultiplayerBuildOptions() => drawingMultiplayerBuildOptions != null;
164+
163165
internal static void DrawMultiplayerBuildOption(NamedBuildTarget namedBuildTarget)
164166
{
165167
drawingMultiplayerBuildOptions?.Invoke(namedBuildTarget);

Editor/Mono/BuildProfile/BuildProfileModuleUtil.cs

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,42 @@ public static string GetClassicPlatformDisplayName(string moduleName, Standalone
3535
(moduleName, subtarget) switch
3636
{
3737
("OSXStandalone", StandaloneBuildSubtarget.Server) => "Mac Server",
38-
("WindowsStandalone",StandaloneBuildSubtarget.Server) => "Windows Server",
38+
("WindowsStandalone", StandaloneBuildSubtarget.Server) => "Windows Server",
3939
("LinuxStandalone", StandaloneBuildSubtarget.Server) => "Linux Server",
4040
("OSXStandalone", _) => "Mac",
4141
("WindowsStandalone", _) => "Windows",
4242
("LinuxStandalone", _) => "Linux",
43-
("UWP", _) => "Universal Windows Platform",
44-
("AppleTV", _) => "tvOS",
45-
_ => moduleName
43+
_ => GetModuleDisplayName(moduleName)
4644
};
4745

4846
/// <summary>
49-
/// Fetch editor platform icon texture.
47+
/// Fetch default editor platform icon texture.
5048
/// </summary>
5149
public static Texture2D GetPlatformIcon(string moduleName, StandaloneBuildSubtarget subtarget)
5250
{
53-
if (subtarget == StandaloneBuildSubtarget.Server)
54-
{
55-
return EditorGUIUtility.LoadIcon(string.Format(k_BuildSettingsPlatformIconFormat, "DedicatedServer"));
56-
}
51+
return GetBuildProfileIcon();
52+
// TODO: Finalize Icon Design https://jira.unity3d.com/browse/PLAT-7379
53+
// return EditorGUIUtility.LoadIcon(GetPlatformIconId(moduleName, subtarget));
54+
}
5755

58-
return EditorGUIUtility.LoadIcon(
59-
s_DiscoveredTargetInfos.TryGetValue(moduleName, out var targetInfo)
60-
? targetInfo.iconName : "BuildSettings.Editor");
56+
/// <summary>
57+
/// Fetch small (16x16) editor platform icon texture.
58+
/// </summary>
59+
public static Texture2D GetPlatformIconSmall(string moduleName, StandaloneBuildSubtarget subtarget)
60+
{
61+
return GetBuildProfileIcon();
62+
// TODO: Finalize Icon Design https://jira.unity3d.com/browse/PLAT-7379
63+
// return EditorGUIUtility.LoadIcon(GetPlatformIconId(moduleName, subtarget) + ".Small");
64+
}
65+
66+
public static Texture2D GetBuildProfileIcon() => EditorGUIUtility.FindTexture(typeof(UnityEditor.Build.Profile.BuildProfile));
67+
68+
/// <summary>
69+
/// Load internal warning icon
70+
/// </summary>
71+
public static Texture2D GetWarningIcon()
72+
{
73+
return EditorGUIUtility.LoadIcon("d_console.warnicon.sml");
6174
}
6275

6376
/// <summary>
@@ -242,6 +255,15 @@ public static IBuildProfileExtension GetBuildProfileExtension(BuildTarget buildT
242255
return result;
243256
}
244257

258+
/// <summary>
259+
/// Retrieve string of filename invalid characters
260+
/// </summary>
261+
/// <returns></returns>
262+
public static string GetFilenameInvalidCharactersStr()
263+
{
264+
return EditorUtility.GetInvalidFilenameChars();
265+
}
266+
245267
internal static BuildTarget GetBuildTarget(string moduleName)
246268
{
247269
return s_DiscoveredTargetInfos[moduleName].buildTargetPlatformVal;
@@ -257,5 +279,31 @@ internal static BuildTarget GetBuildTarget(string moduleName)
257279
}
258280
return result;
259281
}
282+
283+
static string GetPlatformIconId(string moduleName, StandaloneBuildSubtarget subtarget)
284+
{
285+
if (subtarget == StandaloneBuildSubtarget.Server)
286+
{
287+
return string.Format(k_BuildSettingsPlatformIconFormat, "DedicatedServer");
288+
}
289+
290+
if (s_DiscoveredTargetInfos.TryGetValue(moduleName, out var targetInfo))
291+
{
292+
return targetInfo.iconName;
293+
}
294+
295+
return "BuildSettings.Editor";
296+
}
297+
298+
/// <summary>
299+
/// Module display name as defined on native side in "BuildTargetGroupName.h"
300+
/// </summary>
301+
static string GetModuleDisplayName(string moduleName)
302+
{
303+
if (!s_DiscoveredTargetInfos.TryGetValue(moduleName, out var gt))
304+
return moduleName;
305+
306+
return BuildPipeline.GetBuildTargetGroupDisplayName(BuildPipeline.GetBuildTargetGroup(gt.buildTargetPlatformVal));
307+
}
260308
}
261309
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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.IO;
6+
using UnityEngine;
7+
using UnityEngine.Bindings;
8+
using UnityEngine.UIElements;
9+
10+
namespace UnityEditor.Build.Profile
11+
{
12+
/// <summary>
13+
/// Handles displaying tooltip view for renaming build profile
14+
/// items with text field
15+
/// </summary>
16+
[VisibleToOtherModules("UnityEditor.BuildProfileModule")]
17+
internal class BuildProfileRenameOverlay
18+
{
19+
static readonly string k_ErrorMessage = $"A file name can't contain any of the following characters:\t{BuildProfileModuleUtil.GetFilenameInvalidCharactersStr()}";
20+
21+
TextField m_TextField;
22+
Rect? m_ErrorRect = null;
23+
24+
Rect errorRect
25+
{
26+
get
27+
{
28+
if (m_ErrorRect == null)
29+
m_ErrorRect = GUIUtility.GUIToScreenRect(m_TextField.worldBound);
30+
31+
return m_ErrorRect.Value;
32+
}
33+
}
34+
35+
public BuildProfileRenameOverlay(TextField textField)
36+
{
37+
m_TextField = textField;
38+
}
39+
40+
public void OnNameChanged(string previousValue, string newValue)
41+
{
42+
// It's fine to call show and close tooltip on multiple frames
43+
// since it only opens if not opened before. Also it only closes if
44+
// not closed before
45+
if (HasInvalidCharacterIndex(newValue))
46+
{
47+
// We can't use the text field's tooltip property since it's displayed
48+
// automatically on hover. So we use the TooltipView to display the
49+
// error message (same way as the RenameOverlay used for assets)
50+
TooltipView.Show(k_ErrorMessage, errorRect);
51+
m_TextField.SetValueWithoutNotify(previousValue);
52+
53+
// The cursor should be kept in place when adding an invalid character
54+
var targetIndex = Mathf.Max(m_TextField.cursorIndex - 1, 0);
55+
m_TextField.cursorIndex = targetIndex;
56+
m_TextField.selectIndex = targetIndex;
57+
}
58+
else
59+
{
60+
TooltipView.ForceClose();
61+
}
62+
}
63+
64+
public void OnRenameEnd()
65+
{
66+
// Make sure tooltip is closed
67+
TooltipView.ForceClose();
68+
}
69+
70+
bool HasInvalidCharacterIndex(string value)
71+
{
72+
return value.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0;
73+
}
74+
}
75+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.Diagnostics.CodeAnalysis;
6+
using UnityEngine;
7+
8+
namespace UnityEditor
9+
{
10+
[SuppressMessage("ReSharper", "NotAccessedField.Local")]
11+
public partial class EditorGUI
12+
{
13+
private static readonly int s_RenderingLayerMaskField = "s_RenderingLayerMaskField".GetHashCode();
14+
15+
// Make a field for rendering layer masks.
16+
public static void RenderingLayerMaskField(Rect position, string label, SerializedProperty property)
17+
{
18+
RenderingLayerMaskFieldInternal(position, new GUIContent(label), property.uintValue, property, EditorStyles.layerMaskField);
19+
}
20+
21+
public static void RenderingLayerMaskField(Rect position, GUIContent label, SerializedProperty property)
22+
{
23+
RenderingLayerMaskFieldInternal(position, label, property.uintValue, property, EditorStyles.layerMaskField);
24+
}
25+
26+
public static RenderingLayerMask RenderingLayerMaskField(Rect position, string label, RenderingLayerMask layers)
27+
{
28+
return RenderingLayerMaskField(position, label, layers, EditorStyles.layerMaskField);
29+
}
30+
31+
public static RenderingLayerMask RenderingLayerMaskField(Rect position, string label, RenderingLayerMask layers, GUIStyle style)
32+
{
33+
return RenderingLayerMaskField(position, new GUIContent(label), layers, style);
34+
}
35+
36+
public static RenderingLayerMask RenderingLayerMaskField(Rect position, GUIContent label, RenderingLayerMask layers)
37+
{
38+
return RenderingLayerMaskField(position, label, layers, EditorStyles.layerMaskField);
39+
}
40+
41+
public static RenderingLayerMask RenderingLayerMaskField(Rect position, GUIContent label, RenderingLayerMask layers, GUIStyle style)
42+
{
43+
return RenderingLayerMaskFieldInternal(position, label, layers, null, style);
44+
}
45+
46+
static uint RenderingLayerMaskFieldInternal(Rect position, GUIContent label, uint layers, SerializedProperty property, GUIStyle style)
47+
{
48+
var id = GUIUtility.GetControlID(s_RenderingLayerMaskField, FocusType.Keyboard, position);
49+
if (label != null)
50+
position = PrefixLabel(position, id, label);
51+
52+
var names = RenderingLayerMask.GetDefinedRenderingLayerNames();
53+
var values = RenderingLayerMask.GetDefinedRenderingLayerValues();
54+
55+
using var scope = new MixedValueScope();
56+
57+
BeginChangeCheck();
58+
var newValue = MaskFieldGUI.DoMaskField(position, id, unchecked((int)layers), names, values, style);
59+
if (EndChangeCheck() && property != null)
60+
{
61+
var bits = property.FindPropertyRelative("m_Bits");
62+
Debug.Assert(bits != null, $"Property for RenderingLayerMask doesn't contain m_Bits. You should use new {nameof(RenderingLayerMask)} type with this drawer.");
63+
bits.uintValue = (uint)newValue;
64+
}
65+
66+
return unchecked((uint)newValue);
67+
}
68+
}
69+
}

Editor/Mono/EditorGUI.cs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public sealed partial class EditorGUI
6363
private static readonly int s_ColorHash = "s_ColorHash".GetHashCode();
6464
private static readonly int s_CurveHash = "s_CurveHash".GetHashCode();
6565
private static readonly int s_LayerMaskField = "s_LayerMaskField".GetHashCode();
66-
private static readonly int s_RenderingLayerMaskField = "s_RenderingLayerMaskField".GetHashCode();
6766
private static readonly int s_MaskField = "s_MaskField".GetHashCode();
6867
private static readonly int s_EnumFlagsField = "s_EnumFlagsField".GetHashCode();
6968
private static readonly int s_GenericField = "s_GenericField".GetHashCode();
@@ -6606,7 +6605,7 @@ public static void HelpBox(Rect position, GUIContent content)
66066605
if (content.image != null)
66076606
{
66086607
var labelRect = position;
6609-
int iconSize = (int) (content.image.width / EditorGUIUtility.pixelsPerPoint) + EditorStyles.helpBox.padding.right;
6608+
int iconSize = (int) (content.image.width / EditorGUIUtility.pixelsPerPoint);
66106609
labelRect.x += iconSize;
66116610
labelRect.width -= iconSize;
66126611

@@ -7139,40 +7138,6 @@ internal static uint LayerMaskField(Rect position, UInt32 layers, SerializedProp
71397138
return unchecked((uint)newValue);
71407139
}
71417140

7142-
// Make a field for rendering layer masks.
7143-
internal static void RenderingLayerMaskField(Rect position, SerializedProperty property, GUIContent label, GUIStyle style)
7144-
{
7145-
RenderingLayerMaskField(position, property.uintValue, property, label, style);
7146-
}
7147-
7148-
internal static void RenderingLayerMaskField(Rect position, SerializedProperty property, GUIContent label)
7149-
{
7150-
RenderingLayerMaskField(position, property.uintValue, property, label, EditorStyles.layerMaskField);
7151-
}
7152-
7153-
internal static RenderingLayerMask RenderingLayerMaskField(Rect position, RenderingLayerMask layers, GUIContent label)
7154-
{
7155-
return RenderingLayerMaskField(position, layers, null, label, EditorStyles.layerMaskField);
7156-
}
7157-
7158-
internal static uint RenderingLayerMaskField(Rect position, UInt32 layers, SerializedProperty property, GUIContent label, GUIStyle style)
7159-
{
7160-
var id = GUIUtility.GetControlID(s_RenderingLayerMaskField, FocusType.Keyboard, position);
7161-
if (label != null)
7162-
position = PrefixLabel(position, id, label);
7163-
7164-
TagManager.GetDefinedRenderingLayers(out var renderingLayerNames, out var renderingLayerValues);
7165-
7166-
using var scope = new MixedValueScope();
7167-
7168-
BeginChangeCheck();
7169-
var newValue = MaskFieldGUI.DoMaskField(position, id, unchecked((int)layers), renderingLayerNames, renderingLayerValues, style);
7170-
if (EndChangeCheck() && property != null)
7171-
property.FindPropertyRelative("m_Bits").uintValue = (uint)newValue;
7172-
7173-
return unchecked((uint)newValue);
7174-
}
7175-
71767141
// Helper function for helping with debugging the editor
71777142
internal static void ShowRepaints()
71787143
{
@@ -7716,6 +7681,23 @@ internal static bool DefaultPropertyField(Rect position, SerializedProperty prop
77167681
}
77177682
break;
77187683
}
7684+
case SerializedPropertyType.RenderingLayerMask:
7685+
{
7686+
var names = RenderingLayerMask.GetDefinedRenderingLayerNames();
7687+
var values = RenderingLayerMask.GetDefinedRenderingLayerValues();
7688+
MaskFieldGUI.GetMaskButtonValue((int) property.uintValue, names, values, out var toggleLabel, out var toggleLabelMixed);
7689+
if (label != null)
7690+
position = PrefixLabel(position, label, EditorStyles.label);
7691+
7692+
var toggleLabelContent = property.hasMultipleDifferentValues ? mixedValueContent : MaskFieldGUI.DoMixedLabel(toggleLabel, toggleLabelMixed, position, EditorStyles.layerMaskField);
7693+
bool toggled = DropdownButton(position, toggleLabelContent, FocusType.Keyboard, EditorStyles.layerMaskField);
7694+
if (toggled)
7695+
{
7696+
PopupWindowWithoutFocus.Show(position, new MaskFieldDropDown(property));
7697+
GUIUtility.ExitGUI();
7698+
}
7699+
break;
7700+
}
77197701
case SerializedPropertyType.Character:
77207702
{
77217703
char[] value = { (char)property.intValue };

0 commit comments

Comments
 (0)