Skip to content

Commit 332310b

Browse files
author
Unity Technologies
committed
Unity 2023.1.0a17 C# reference source code
1 parent d3aaa4d commit 332310b

File tree

154 files changed

+4131
-1892
lines changed

Some content is hidden

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

154 files changed

+4131
-1892
lines changed

Editor/Mono/Animation/AnimationUtility.bindings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78
using UnityEngine.Bindings;
89
using UnityEngine.Scripting;
910
using UnityEngine.Scripting.APIUpdating;
@@ -385,8 +386,23 @@ public static AnimationCurve GetEditorCurve(AnimationClip clip, string relativeP
385386
return GetEditorCurve(clip, EditorCurveBinding.FloatCurve(relativePath, type, propertyName));
386387
}
387388

388-
extern public static AnimationEvent[] GetAnimationEvents([NotNull] AnimationClip clip);
389-
[NativeThrows] extern public static void SetAnimationEvents([NotNull] AnimationClip clip, [NotNull] AnimationEvent[] events);
389+
public static AnimationEvent[] GetAnimationEvents(AnimationClip clip)
390+
{
391+
var blittableEvents = GetAnimationEventsInternal(clip);
392+
var animationEvents = blittableEvents.Select(AnimationEventBlittable.ToAnimationEvent).ToArray();
393+
foreach (var blittableEvent in blittableEvents)
394+
blittableEvent.Dispose();
395+
return animationEvents;
396+
}
397+
extern internal static AnimationEventBlittable[] GetAnimationEventsInternal([NotNull] AnimationClip clip);
398+
public static void SetAnimationEvents(AnimationClip clip, AnimationEvent[] events)
399+
{
400+
var blittableEvents = events.Select(AnimationEventBlittable.FromAnimationEvent).ToArray();
401+
SetAnimationEventsInternal(clip, blittableEvents);
402+
foreach (var blittableEvent in blittableEvents)
403+
blittableEvent.Dispose();
404+
}
405+
extern internal static void SetAnimationEventsInternal([NotNull] AnimationClip clip, [NotNull] AnimationEventBlittable[] events);
390406

391407
extern public static string CalculateTransformPath([NotNull] Transform targetTransform, Transform root);
392408

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,18 @@ public enum PlayerConnectionInitiateMode
235235
PlayerListens
236236
}
237237

238+
239+
[StructLayout(LayoutKind.Sequential)]
240+
public struct BuildAssetBundlesParameters
241+
{
242+
public string outputPath { get; set; }
243+
public AssetBundleBuild[] bundleDefinitions { get; set; }
244+
public BuildAssetBundleOptions options { get; set; }
245+
public BuildTarget targetPlatform { get; set; }
246+
public int subtarget { get; set; }
247+
public string[] extraScriptingDefines { get; set; }
248+
}
249+
238250
// Lets you programmatically build players or AssetBundles which can be loaded from the web.
239251
[NativeHeader("Editor/Mono/BuildPipeline.bindings.h")]
240252
[StaticAccessor("BuildPipeline", StaticAccessorType.DoubleColon)]
@@ -540,7 +552,7 @@ public static bool BuildAssetBundle(UnityEngine.Object mainAsset, UnityEngine.Ob
540552
return BuildAssetBundle(mainAsset, assets, pathName, out crc, assetBundleOptions, targetPlatformGroup, targetPlatform, EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform));
541553
}
542554

543-
// Builds an AssetBundle.
555+
// Builds an AssetBundle (Obsolete)
544556
internal static bool BuildAssetBundle(UnityEngine.Object mainAsset, UnityEngine.Object[] assets, string pathName, out uint crc, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget)
545557
{
546558
crc = 0;
@@ -571,7 +583,7 @@ public static bool BuildAssetBundleExplicitAssetNames(UnityEngine.Object[] asset
571583
return BuildAssetBundleExplicitAssetNames(assets, assetNames, pathName, out crc, assetBundleOptions, targetPlatformGroup, targetPlatform, EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform));
572584
}
573585

574-
// Builds an AssetBundle, with custom names for the assets.
586+
// Builds an AssetBundle, with custom names for the assets (Obsolete)
575587
internal static bool BuildAssetBundleExplicitAssetNames(UnityEngine.Object[] assets, string[] assetNames, string pathName, out uint crc, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget)
576588
{
577589
crc = 0;
@@ -588,51 +600,63 @@ internal static bool BuildAssetBundleExplicitAssetNames(UnityEngine.Object[] ass
588600

589601
#pragma warning restore 618
590602

603+
//Obsolete
591604
private static extern bool BuildAssetBundleInternal(UnityEngine.Object mainAsset, UnityEngine.Object[] assets, string[] assetNames, string pathName, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget, out uint crc);
592605

593606
public static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
594607
{
595-
BuildTargetGroup targetPlatformGroup = BuildPipeline.GetBuildTargetGroup(targetPlatform);
596-
return BuildAssetBundles(outputPath, assetBundleOptions, targetPlatformGroup, targetPlatform, EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform));
608+
BuildAssetBundlesParameters input = new BuildAssetBundlesParameters
609+
{
610+
outputPath = outputPath,
611+
bundleDefinitions = null, // Bundle assignment will be read from AssetDatabase
612+
options = assetBundleOptions,
613+
targetPlatform = targetPlatform,
614+
subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform),
615+
};
616+
617+
return BuildAssetBundles(input);
597618
}
598619

599-
internal static AssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget)
620+
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
600621
{
601-
if (isBuildingPlayer)
602-
throw new InvalidOperationException("Cannot build asset bundles while a build is in progress.");
622+
if (builds == null)
623+
// This signature is specifically meant for specifying the bundle definition array, so it is not optional
624+
throw new ArgumentException("AssetBundleBuild cannot be null.");
603625

604-
if (!System.IO.Directory.Exists(outputPath))
605-
throw new ArgumentException("The output path \"" + outputPath + "\" doesn't exist");
626+
BuildAssetBundlesParameters input = new BuildAssetBundlesParameters
627+
{
628+
outputPath = outputPath,
629+
bundleDefinitions = builds,
630+
options = assetBundleOptions,
631+
targetPlatform = targetPlatform,
632+
subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform),
633+
};
606634

607-
return BuildAssetBundlesInternal(outputPath, assetBundleOptions, targetPlatformGroup, targetPlatform, subtarget);
635+
return BuildAssetBundles(input);
608636
}
609637

610-
[NativeThrows]
611-
private static extern AssetBundleManifest BuildAssetBundlesInternal(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget);
612-
613-
public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
638+
public static AssetBundleManifest BuildAssetBundles(BuildAssetBundlesParameters buildParameters)
614639
{
615-
BuildTargetGroup targetPlatformGroup = BuildPipeline.GetBuildTargetGroup(targetPlatform);
616-
int subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(targetPlatform);
617-
return BuildAssetBundles(outputPath, builds, assetBundleOptions, targetPlatformGroup, targetPlatform, subtarget);
618-
}
640+
if (buildParameters.targetPlatform == 0 || buildParameters.targetPlatform == BuildTarget.NoTarget)
641+
{
642+
buildParameters.targetPlatform = EditorUserBuildSettings.activeBuildTarget;
643+
644+
// Note: subtarget is associated with multiple enums, and 0 may have a specific meaning,
645+
// so we only auto-set it when the target is also coming from the build settings
646+
buildParameters.subtarget = EditorUserBuildSettings.GetActiveSubtargetFor(buildParameters.targetPlatform);
647+
}
619648

620-
internal static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget)
621-
{
622649
if (isBuildingPlayer)
623650
throw new InvalidOperationException("Cannot build asset bundles while a build is in progress.");
624651

625-
if (!System.IO.Directory.Exists(outputPath))
626-
throw new ArgumentException("The output path \"" + outputPath + "\" doesn't exist");
627-
628-
if (builds == null)
629-
throw new ArgumentException("AssetBundleBuild cannot be null.");
652+
if (!System.IO.Directory.Exists(buildParameters.outputPath))
653+
throw new ArgumentException("The output path \"" + buildParameters.outputPath + "\" doesn't exist");
630654

631-
return BuildAssetBundlesWithInfoInternal(outputPath, builds, assetBundleOptions, targetPlatformGroup, targetPlatform, subtarget);
655+
return BuildAssetBundlesInternal(buildParameters);
632656
}
633657

634658
[NativeThrows]
635-
private static extern AssetBundleManifest BuildAssetBundlesWithInfoInternal(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions, BuildTargetGroup targetPlatformGroup, BuildTarget targetPlatform, int subtarget);
659+
private static extern AssetBundleManifest BuildAssetBundlesInternal(BuildAssetBundlesParameters buildParameters);
636660

637661
[FreeFunction("GetPlayerDataSessionId")]
638662
internal static extern string GetSessionIdForBuildTarget(BuildTarget target, int subtarget);

Editor/Mono/ConsoleWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ public static void LogChanged()
314314
if (!ms_ConsoleWindow)
315315
return;
316316
ms_ConsoleWindow.Repaint();
317+
ConsoleWindowUtility.Internal_CallLogsHaveChanged();
317318
}
318319

319320
public ConsoleWindow()

Editor/Mono/ConsoleWindowUtility.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
7+
namespace UnityEditor
8+
{
9+
public static class ConsoleWindowUtility
10+
{
11+
public static event Action consoleLogsChanged;
12+
13+
public static void GetConsoleLogCounts(out int error, out int warn, out int log)
14+
{
15+
int outError = 0;
16+
int outWarn = 0;
17+
int outLog = 0;
18+
19+
LogEntries.GetCountsByType(ref outError, ref outWarn, ref outLog);
20+
21+
error = outError;
22+
warn = outWarn;
23+
log = outLog;
24+
}
25+
26+
internal static void Internal_CallLogsHaveChanged()
27+
{
28+
consoleLogsChanged?.Invoke();
29+
}
30+
}
31+
}

Editor/Mono/EditorGraphicsSettings.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ public static AlbedoSwatchInfo[] albedoSwatches
4141
get { return GetAlbedoSwatches(); }
4242
set { SetAlbedoSwatches(value); }
4343
}
44+
45+
extern public static BatchRendererGroupStrippingMode batchRendererGroupShaderStrippingMode { get; }
4446
}
4547
}

Editor/Mono/EditorGraphicsSettings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public struct AlbedoSwatchInfo
2727
public float maxLuminance;
2828
}
2929

30+
public enum BatchRendererGroupStrippingMode
31+
{
32+
KeepIfEntitiesGraphics = 0,
33+
StripAll,
34+
KeepAll
35+
}
36+
3037
[StructLayout(LayoutKind.Sequential)]
3138
public struct TierSettings
3239
{

Editor/Mono/EditorHandles/ScaleHandle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ internal static Vector3 DoScaleHandle(ScaleHandleIds ids, Vector3 scale, Vector3
250250
if (param.ShouldShow(ScaleHandleParam.Handle.XYZ) && (ids.xyz == GUIUtility.hotControl || !isHot))
251251
{
252252
color = isProportionalScale ? constrainProportionsScaleHandleColor : ToActiveColorSpace(centerColor);
253+
if (isDisabled)
254+
color = Color.Lerp(color, staticColor, staticBlend);
253255
proportionalScale = false;
254256
EditorGUI.BeginChangeCheck();
255257
s_CurrentMultiplier = ScaleValueHandle(ids.xyz, s_CurrentMultiplier, position, rotation, handleSize * param.xyzSize, CubeHandleCap, EditorSnapSettings.scale);

Editor/Mono/EditorMode/ModeService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal enum ModeCapability
3939
SafeMode,
4040
Remember,
4141
AllowAssetCreation,
42+
StaticTabs,
4243
SearchPopupButton
4344
}
4445

Editor/Mono/GUI/DockArea.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,13 @@ private void DrawTabs(Rect tabAreaRect)
407407
if (tabStyle == null)
408408
tabStyle = Styles.dragTab;
409409

410-
var totalTabWidth = DragTab(tabAreaRect, m_ScrollOffset, tabStyle, Styles.dragTabFirst);
410+
var firstTabStyle = Styles.dragTabFirst;
411+
if (ModeService.HasCapability(ModeCapability.StaticTabs, false))
412+
{
413+
firstTabStyle = Styles.tabLabel;
414+
}
415+
416+
var totalTabWidth = DragTab(tabAreaRect, m_ScrollOffset, tabStyle, firstTabStyle);
411417
if (totalTabWidth > 0f)
412418
m_TotalTabWidth = totalTabWidth;
413419
tabStyle = Styles.dragTab;
@@ -798,6 +804,10 @@ private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, G
798804
{
799805
case EventType.TouchDown:
800806
case EventType.MouseDown:
807+
if (ModeService.HasCapability(ModeCapability.StaticTabs, false))
808+
{
809+
break;
810+
}
801811
// Handle double click
802812
if (EditorWindow.focusedWindow != null)
803813
WindowMaximizeStateOnDoubleClick(tabAreaRect);
@@ -826,6 +836,10 @@ private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, G
826836
}
827837
break;
828838
case EventType.ContextClick:
839+
if (ModeService.HasCapability(ModeCapability.StaticTabs, false))
840+
{
841+
break;
842+
}
829843
if (GUIUtility.hotControl == 0)
830844
{
831845
int sel = GetTabAtMousePos(tabStyle, evt.mousePosition, scrollOffset, tabAreaRect);
@@ -839,6 +853,10 @@ private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, G
839853
case EventType.TouchMove:
840854
case EventType.MouseDrag:
841855

856+
if (ModeService.HasCapability(ModeCapability.StaticTabs, false))
857+
{
858+
break;
859+
}
842860
if (evt.pointerType == PointerType.Pen && !evt.penStatus.HasFlag(PenStatus.Contact))
843861
break;
844862

@@ -943,6 +961,10 @@ private float DragTab(Rect tabAreaRect, float scrollOffset, GUIStyle tabStyle, G
943961
break;
944962
case EventType.TouchUp:
945963
case EventType.MouseUp:
964+
if (ModeService.HasCapability(ModeCapability.StaticTabs, false))
965+
{
966+
break;
967+
}
946968
if (GUIUtility.hotControl == id)
947969
{
948970
Vector2 screenMousePos = GUIUtility.GUIToScreenPoint(evt.mousePosition);

Editor/Mono/HandleUtility.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -871,41 +871,40 @@ public static Rect WorldPointToSizedRect(Vector3 position, GUIContent content, G
871871
{
872872
Vector2 screenpos = WorldToGUIPoint(position);
873873
Vector2 size = style.CalcSize(content);
874-
Rect r = new Rect(screenpos.x, screenpos.y, size.x, size.y);
874+
Rect rect = new Rect(screenpos.x, screenpos.y, size.x, size.y);
875875
switch (style.alignment)
876876
{
877-
case TextAnchor.UpperLeft:
878-
break;
879877
case TextAnchor.UpperCenter:
880-
r.xMin -= r.width * .5f;
878+
rect.x -= rect.width * 0.5f;
881879
break;
882880
case TextAnchor.UpperRight:
883-
r.xMin -= r.width;
881+
rect.x -= rect.width;
884882
break;
885883
case TextAnchor.MiddleLeft:
886-
r.yMin -= r.height * .5f;
884+
rect.y -= rect.height * 0.5f;
887885
break;
888886
case TextAnchor.MiddleCenter:
889-
r.xMin -= r.width * .5f;
890-
r.yMin -= r.height * .5f;
887+
rect.x -= rect.width * 0.5f;
888+
rect.y -= rect.height * 0.5f;
891889
break;
892890
case TextAnchor.MiddleRight:
893-
r.xMin -= r.width;
894-
r.yMin -= r.height * .5f;
891+
rect.x -= rect.width;
892+
rect.y -= rect.height * 0.5f;
895893
break;
896894
case TextAnchor.LowerLeft:
897-
r.yMin -= r.height * .5f;
895+
rect.y -= rect.height;
898896
break;
899897
case TextAnchor.LowerCenter:
900-
r.xMin -= r.width * .5f;
901-
r.yMin -= r.height;
898+
rect.x -= rect.width * 0.5f;
899+
rect.y -= rect.height;
902900
break;
903901
case TextAnchor.LowerRight:
904-
r.xMin -= r.width;
905-
r.yMin -= r.height;
902+
rect.x -= rect.width;
903+
rect.y -= rect.height;
906904
break;
907905
}
908-
return style.padding.Add(r);
906+
907+
return style.padding.Add(rect);
909908
}
910909

911910
// Pick game object in specified rectangle

0 commit comments

Comments
 (0)