Skip to content

Commit 72356ce

Browse files
author
Unity Technologies
committed
Unity 6000.1.0b1 C# reference source code
1 parent cc8ba04 commit 72356ce

File tree

241 files changed

+5971
-1684
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

+5971
-1684
lines changed

Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UnityEngine.U2D;
88
using UnityEngine.Bindings;
99
using System;
10+
using UnityEditor.AssetImporters;
1011

1112
namespace UnityEditor.U2D
1213
{
@@ -100,6 +101,12 @@ public static class SpriteAtlasExtensions
100101
extern public static void Remove([NotNull] this SpriteAtlas spriteAtlas, UnityEngine.Object[] objects);
101102
extern internal static void RemoveAt([NotNull] this SpriteAtlas spriteAtlas, int index);
102103
extern public static UnityEngine.Object[] GetPackables([NotNull] this SpriteAtlas spriteAtlas);
104+
extern internal static void SetV2([NotNull] this SpriteAtlas spriteAtlas);
105+
internal static void RegisterAndPackAtlas(this SpriteAtlas spriteAtlas, AssetImportContext context, AssetImporter importer, U2D.ScriptablePacker scriptablePacker)
106+
{
107+
RegisterAndPackAtlasInternal(spriteAtlas, context, importer, scriptablePacker);
108+
}
109+
extern private static void RegisterAndPackAtlasInternal([NotNull] this SpriteAtlas spriteAtlas, [NotNull] AssetImportContext context, [NotNull] AssetImporter importer, UnityEngine.Object scriptablePacker);
103110
extern public static SpriteAtlasTextureSettings GetTextureSettings([NotNull] this SpriteAtlas spriteAtlas);
104111
extern public static void SetTextureSettings([NotNull] this SpriteAtlas spriteAtlas, SpriteAtlasTextureSettings src);
105112
extern public static SpriteAtlasPackingSettings GetPackingSettings([NotNull] this SpriteAtlas spriteAtlas);

Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private enum AtlasType { Undefined = -1, Master = 0, Variant = 1 }
132132
private string m_Hash;
133133
private int m_PreviewPage = 0;
134134
private int m_TotalPages = 0;
135+
const float kPrefixLabelWidth = 290f;
135136
private int[] m_OptionValues = null;
136137
private string[] m_OptionDisplays = null;
137138
private Texture2D[] m_PreviewTextures = null;
@@ -194,6 +195,17 @@ bool AllTargetsAreMaster()
194195

195196
void OnEnable()
196197
{
198+
if (targets == null)
199+
return;
200+
var validCount = 0;
201+
foreach (var so in targets)
202+
{
203+
if (so != null)
204+
validCount++;
205+
}
206+
if (validCount == 0)
207+
return;
208+
197209
m_FilterMode = serializedObject.FindProperty("m_EditorData.textureSettings.filterMode");
198210
m_AnisoLevel = serializedObject.FindProperty("m_EditorData.textureSettings.anisoLevel");
199211
m_GenerateMipMaps = serializedObject.FindProperty("m_EditorData.textureSettings.generateMipMaps");
@@ -353,6 +365,9 @@ public override void OnInspectorGUI()
353365

354366
serializedObject.Update();
355367

368+
var oldWidth = EditorGUIUtility.labelWidth;
369+
EditorGUIUtility.labelWidth = kPrefixLabelWidth;
370+
356371
HandleCommonSettingUI();
357372

358373
GUILayout.Space(EditorGUI.kSpacing);
@@ -374,22 +389,25 @@ public override void OnInspectorGUI()
374389
if (targets.Length == 1 && AllTargetsAreMaster())
375390
HandlePackableListUI();
376391

377-
bool spriteAtlasPackignEnabled = (EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnlyAtlas
392+
bool spriteAtlasPackingEnabled = (EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnlyAtlas
378393
|| EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOnAtlas || EditorSettings.spritePackerMode == SpritePackerMode.SpriteAtlasV2);
379-
if (spriteAtlasPackignEnabled && !Application.isPlaying)
394+
if (spriteAtlasPackingEnabled && !Application.isPlaying)
380395
{
381-
if (GUILayout.Button(styles.packButton, GUILayout.ExpandWidth(false)))
396+
using (new EditorGUI.DisabledScope(!Editor.IsPersistent(spriteAtlas)))
382397
{
383-
SpriteAtlas[] spriteAtlases = new SpriteAtlas[targets.Length];
384-
for (int i = 0; i < spriteAtlases.Length; ++i)
385-
spriteAtlases[i] = (SpriteAtlas)targets[i];
398+
if (GUILayout.Button(styles.packButton, GUILayout.ExpandWidth(false)))
399+
{
400+
SpriteAtlas[] spriteAtlases = new SpriteAtlas[targets.Length];
401+
for (int i = 0; i < spriteAtlases.Length; ++i)
402+
spriteAtlases[i] = (SpriteAtlas)targets[i];
386403

387-
SpriteAtlasUtility.PackAtlases(spriteAtlases, EditorUserBuildSettings.activeBuildTarget);
404+
SpriteAtlasUtility.PackAtlases(spriteAtlases, EditorUserBuildSettings.activeBuildTarget);
388405

389-
// Packing an atlas might change platform settings in the process, reinitialize
390-
SyncPlatformSettings();
406+
// Packing an atlas might change platform settings in the process, reinitialize
407+
SyncPlatformSettings();
391408

392-
GUIUtility.ExitGUI();
409+
GUIUtility.ExitGUI();
410+
}
393411
}
394412
}
395413
else
@@ -400,6 +418,7 @@ public override void OnInspectorGUI()
400418
}
401419
}
402420

421+
EditorGUIUtility.labelWidth = oldWidth;
403422
serializedObject.ApplyModifiedProperties();
404423
}
405424

@@ -413,7 +432,10 @@ private void HandleCommonSettingUI()
413432

414433
EditorGUI.BeginChangeCheck();
415434
EditorGUI.showMixedValue = atlasType == AtlasType.Undefined;
416-
atlasType = (AtlasType)EditorGUILayout.IntPopup(styles.atlasTypeLabel, (int)atlasType, styles.atlasTypeOptions, styles.atlasTypeValues);
435+
using (new EditorGUI.DisabledScope(!Editor.IsPersistent(spriteAtlas)))
436+
{
437+
atlasType = (AtlasType)EditorGUILayout.IntPopup(styles.atlasTypeLabel, (int)atlasType, styles.atlasTypeOptions, styles.atlasTypeValues);
438+
}
417439
EditorGUI.showMixedValue = false;
418440
if (EditorGUI.EndChangeCheck())
419441
{

Editor/Mono/Animation/MaterialAnimationUtility.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using UnityEditor;
88
using UnityEngine;
9+
using ShaderPropertyType = UnityEngine.Rendering.ShaderPropertyType;
910
using Object = UnityEngine.Object;
1011

1112
namespace UnityEditorInternal
@@ -81,21 +82,21 @@ static public bool OverridePropertyColor(MaterialProperty materialProp, Renderer
8182
var propertyPaths = new List<string>();
8283
string basePropertyPath = kMaterialPrefix + materialProp.name;
8384

84-
if (materialProp.type == MaterialProperty.PropType.Texture)
85+
if (materialProp.propertyType == ShaderPropertyType.Texture)
8586
{
8687
propertyPaths.Add(basePropertyPath + "_ST.x");
8788
propertyPaths.Add(basePropertyPath + "_ST.y");
8889
propertyPaths.Add(basePropertyPath + "_ST.z");
8990
propertyPaths.Add(basePropertyPath + "_ST.w");
9091
}
91-
else if (materialProp.type == MaterialProperty.PropType.Color)
92+
else if (materialProp.propertyType == ShaderPropertyType.Color)
9293
{
9394
propertyPaths.Add(basePropertyPath + ".r");
9495
propertyPaths.Add(basePropertyPath + ".g");
9596
propertyPaths.Add(basePropertyPath + ".b");
9697
propertyPaths.Add(basePropertyPath + ".a");
9798
}
98-
else if (materialProp.type == MaterialProperty.PropType.Vector)
99+
else if (materialProp.propertyType == ShaderPropertyType.Vector)
99100
{
100101
propertyPaths.Add(basePropertyPath + ".x");
101102
propertyPaths.Add(basePropertyPath + ".y");
@@ -138,31 +139,31 @@ static public void TearDownMaterialPropertyBlock(Renderer target)
138139
static public bool ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, int changedMask, Renderer target, object oldValue)
139140
{
140141
bool applied = false;
141-
switch (materialProp.type)
142+
switch (materialProp.propertyType)
142143
{
143-
case MaterialProperty.PropType.Color:
144+
case ShaderPropertyType.Color:
144145
SetupMaterialPropertyBlock(materialProp, changedMask, target);
145146
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (Color)oldValue), MaterialPropertyToPropertyModifications(materialProp, target, materialProp.colorValue));
146147
if (!applied)
147148
TearDownMaterialPropertyBlock(target);
148149
return applied;
149150

150-
case MaterialProperty.PropType.Vector:
151+
case ShaderPropertyType.Vector:
151152
SetupMaterialPropertyBlock(materialProp, changedMask, target);
152153
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (Vector4)oldValue), MaterialPropertyToPropertyModifications(materialProp, target, materialProp.vectorValue));
153154
if (!applied)
154155
TearDownMaterialPropertyBlock(target);
155156
return applied;
156157

157-
case MaterialProperty.PropType.Float:
158-
case MaterialProperty.PropType.Range:
158+
case ShaderPropertyType.Float:
159+
case ShaderPropertyType.Range:
159160
SetupMaterialPropertyBlock(materialProp, changedMask, target);
160161
applied = ApplyMaterialModificationToAnimationRecording(MaterialPropertyToPropertyModifications(materialProp, target, (float)oldValue), MaterialPropertyToPropertyModifications(materialProp, target, materialProp.floatValue));
161162
if (!applied)
162163
TearDownMaterialPropertyBlock(target);
163164
return applied;
164165

165-
case MaterialProperty.PropType.Texture:
166+
case ShaderPropertyType.Texture:
166167
{
167168
if (MaterialProperty.IsTextureOffsetAndScaleChangedMask(changedMask))
168169
{
@@ -183,17 +184,17 @@ static public bool ApplyMaterialModificationToAnimationRecording(MaterialPropert
183184

184185
static public PropertyModification[] MaterialPropertyToPropertyModifications(MaterialProperty materialProp, Renderer target)
185186
{
186-
switch (materialProp.type)
187+
switch (materialProp.propertyType)
187188
{
188-
case MaterialProperty.PropType.Color:
189+
case ShaderPropertyType.Color:
189190
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.colorValue);
190-
case MaterialProperty.PropType.Vector:
191+
case ShaderPropertyType.Vector:
191192
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.vectorValue);
192-
case MaterialProperty.PropType.Float:
193-
case MaterialProperty.PropType.Range:
193+
case ShaderPropertyType.Float:
194+
case ShaderPropertyType.Range:
194195
return MaterialPropertyToPropertyModifications(materialProp, target, materialProp.floatValue);
195196

196-
case MaterialProperty.PropType.Texture:
197+
case ShaderPropertyType.Texture:
197198
{
198199
string name = materialProp.name + "_ST";
199200
return MaterialPropertyToPropertyModifications(name, target, materialProp.vectorValue);

Editor/Mono/AssemblyInfo/AssemblyInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
[assembly: InternalsVisibleTo("UnityEditor.CloudRendering.Extensions")]
6262
[assembly: InternalsVisibleTo("UnityEditor.EmbeddedLinux.Extensions")]
6363
[assembly: InternalsVisibleTo("UnityEditor.QNX.Extensions")]
64+
[assembly: InternalsVisibleTo("UnityEditor.Kepler.Extensions")]
6465
[assembly: InternalsVisibleTo("UnityEditor.WindowsStandalone.Extensions")]
6566
[assembly: InternalsVisibleTo("UnityEditor.OSXStandalone.Extensions")]
6667
[assembly: InternalsVisibleTo("UnityEditor.Lumin.Extensions")]
@@ -176,3 +177,5 @@
176177
[assembly: InternalsVisibleTo("Unity.Automation.Players.EmbeddedLinux")]
177178
[assembly: InternalsVisibleTo("Unity.Automation.Players.QNX")]
178179

180+
[assembly: InternalsVisibleTo("Unity.GraphToolsAuthoringFramework.InternalEditorBridge")]
181+

Editor/Mono/AssetPipeline/TextureImporterEnums.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6+
using System.ComponentModel;
67
using UnityEngine.Scripting;
78

89
namespace UnityEditor
@@ -119,13 +120,22 @@ public enum TextureImporterFormat
119120
DXT5Crunched = 29,
120121

121122
// PowerVR (iPhone) 2 bits/pixel compressed color texture format.
123+
[System.Obsolete("Texture compression format PVRTC has been deprecated and will be removed in a future release")]
124+
[EditorBrowsable(EditorBrowsableState.Never)]
122125
PVRTC_RGB2 = 30,
123126
// PowerVR (iPhone) 2 bits/pixel compressed with alpha channel texture format.
127+
[System.Obsolete("Texture compression format PVRTC has been deprecated and will be removed in a future release")]
128+
[EditorBrowsable(EditorBrowsableState.Never)]
124129
PVRTC_RGBA2 = 31,
125130
// PowerVR (iPhone) 4 bits/pixel compressed color texture format.
131+
[System.Obsolete("Texture compression format PVRTC has been deprecated and will be removed in a future release")]
132+
[EditorBrowsable(EditorBrowsableState.Never)]
126133
PVRTC_RGB4 = 32,
127134
// PowerVR (iPhone) 4 bits/pixel compressed with alpha channel texture format.
135+
[System.Obsolete("Texture compression format PVRTC has been deprecated and will be removed in a future release")]
136+
[EditorBrowsable(EditorBrowsableState.Never)]
128137
PVRTC_RGBA4 = 33,
138+
129139
// ETC (GLES2.0) 4 bits/pixel compressed RGB texture format.
130140
ETC_RGB4 = 34,
131141

Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UnityEngine.Scripting;
1414
using UnityEditor.AssetImporters;
1515
using UnityEngine.SceneManagement;
16+
using UnityEditor.Build.Profile;
1617

1718
namespace UnityEditor.Build
1819
{
@@ -161,6 +162,7 @@ internal class Processors
161162

162163
public List<IPreprocessBuildWithReport> buildPreprocessorsWithReport;
163164
public List<IPostprocessBuildWithReport> buildPostprocessorsWithReport;
165+
public List<IPostprocessLaunch> launchPostprocessors;
164166
public List<IProcessSceneWithReport> sceneProcessorsWithReport;
165167

166168
public List<IFilterBuildAssemblies> filterBuildAssembliesProcessor;
@@ -506,6 +508,14 @@ internal static void OnBuildPreProcess(BuildReport report)
506508
processors.buildPreprocessorsWithReport, bpp => bpp.OnPreprocessBuild(report),
507509
(report.summary.options & BuildOptions.StrictMode) != 0 || (report.summary.assetBundleOptions & BuildAssetBundleOptions.StrictMode) != 0);
508510
#pragma warning restore 618
511+
512+
// NOTE: This is a workaround for PLAT-11795.
513+
// Sometimes, when a player settings override is modified in one of the callbacks, its internal
514+
// serialized version is not updated prior to the build. As a result it will be restored to the
515+
// serialized values. To avoid that situation we force the update here.
516+
var profile = BuildProfile.GetActiveBuildProfile();
517+
if (profile != null)
518+
profile.SerializePlayerSettings();
509519
}
510520

511521
[RequiredByNativeCode]
@@ -572,6 +582,50 @@ internal static void OnBuildPostProcess(BuildReport report)
572582
#pragma warning restore 618
573583
}
574584

585+
586+
// Some platforms like Desktop, instead of launching the app via C#, perform their launch in C++
587+
// See BuildPlayer.cpp LaunchPlayerIfSupported, which calls native LaunchApplication
588+
// Internal_OnPostprocessLaunch is used by this code path
589+
[RequiredByNativeCode]
590+
internal static void Internal_OnPostprocessLaunch(BuildTarget buildTarget, bool success)
591+
{
592+
OnPostprocessLaunch(new DefaultLaunchReport(NamedBuildTarget.FromActiveSettings(buildTarget), success ? LaunchResult.Succeeded : LaunchResult.Failed));
593+
}
594+
595+
internal static void OnPostprocessLaunch(ILaunchReport launchReport)
596+
{
597+
// Domain reload happens after player build, so anything collected in InitializeBuildCallbacks gets invalidated
598+
// Thus collect callbacks here as necessary
599+
if (processors.launchPostprocessors == null)
600+
{
601+
foreach (var t in TypeCache.GetTypesDerivedFrom<IPostprocessLaunch>())
602+
{
603+
if (t.IsAbstract || t.IsInterface)
604+
continue;
605+
606+
object instance = null;
607+
AddToListIfTypeImplementsInterface(t, ref instance, ref processors.launchPostprocessors);
608+
}
609+
610+
processors?.launchPostprocessors?.Sort(CompareICallbackOrder);
611+
}
612+
613+
if (processors.launchPostprocessors == null)
614+
return;
615+
616+
foreach (var run in processors.launchPostprocessors)
617+
{
618+
try
619+
{
620+
run.OnPostprocessLaunch(launchReport);
621+
}
622+
catch (Exception e)
623+
{
624+
Debug.LogException(e);
625+
}
626+
}
627+
}
628+
575629
[RequiredByNativeCode]
576630
internal static void OnActiveBuildTargetChanged(BuildTarget previousPlatform, BuildTarget newPlatform)
577631
{

Editor/Mono/BuildPipeline/DesktopStandalonePostProcessor.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public override void UpdateBootConfig(BuildTarget target, BootConfigData config,
4848
config.Set("capture-startup-logs", "1");
4949
}
5050

51-
public override void LaunchPlayer(BuildLaunchPlayerArgs args)
51+
public override ILaunchReport LaunchPlayer(BuildLaunchPlayerArgs args)
5252
{
5353
// This happens directly from BuildPlayer.cpp
54+
return null;
5455
}
5556

5657
readonly bool m_HasMonoPlayers;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
namespace UnityEditor.Build
6+
{
7+
public enum LaunchResult
8+
{
9+
Unknown = 0,
10+
Succeeded = 1,
11+
// For ex., when running on multiple Android devices, some succeeded, some didn't
12+
PartiallySucceeded = 2,
13+
Failed = 3
14+
}
15+
16+
public interface ILaunchReport
17+
{
18+
public NamedBuildTarget buildTarget { get; }
19+
20+
public LaunchResult result { get; }
21+
}
22+
23+
// Unity will provide DefaultLaunchReport for OnPostprocessLaunch callback if platform doesn't provide its own launch report
24+
public class DefaultLaunchReport : ILaunchReport
25+
{
26+
public NamedBuildTarget buildTarget { get; }
27+
28+
public LaunchResult result { get; }
29+
30+
internal DefaultLaunchReport(NamedBuildTarget buildTarget, LaunchResult result)
31+
{
32+
this.buildTarget = buildTarget;
33+
this.result = result;
34+
}
35+
}
36+
37+
public interface IPostprocessLaunch : IOrderedCallback
38+
{
39+
void OnPostprocessLaunch(ILaunchReport launchReport);
40+
}
41+
}

0 commit comments

Comments
 (0)