Skip to content

Commit

Permalink
Unity 2022.1.0a13 C# reference source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Unity Technologies committed Oct 28, 2021
1 parent bf5ada6 commit e740821
Show file tree
Hide file tree
Showing 302 changed files with 13,740 additions and 3,560 deletions.
1 change: 1 addition & 0 deletions Editor/Mono/AssemblyInfo/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
[assembly: InternalsVisibleTo("Unity.UIElements.Tests")]
[assembly: InternalsVisibleTo("Unity.UIElements.PlayModeTests")]
[assembly: InternalsVisibleTo("Unity.UIElements.EditorTests")]
[assembly: InternalsVisibleTo("Unity.TextCore.Editor.Tests")]
[assembly: InternalsVisibleTo("UnityEditor.UIElementsGameObjectsModule")]
[assembly: InternalsVisibleTo("UnityEditor.TextCoreTextEngineModule")]
[assembly: InternalsVisibleTo("Unity.TextMeshPro.Editor")]
Expand Down
2 changes: 2 additions & 0 deletions Editor/Mono/AssetPipeline/TextureGenerator.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public TextureGenerationSettings(TextureImporterType type)
m_Settings.mipmapFadeDistanceEnd = 3;
m_Settings.heightmapScale = 0.25f;
m_Settings.normalMapFilter = TextureImporterNormalFilter.Standard;
m_Settings.flipGreenChannel = false;
m_Settings.swizzleRaw = 0x03020100; // R,G,B,A
m_Settings.cubemapConvolution = 0;
m_Settings.generateCubemap = TextureImporterGenerateCubemap.AutoCubemap;
m_Settings.seamlessCubemap = false;
Expand Down
28 changes: 24 additions & 4 deletions Editor/Mono/AssetPipeline/TextureImporter.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,32 @@ public bool lightmap
set { if (value) textureType = TextureImporterType.Lightmap; else textureType = TextureImporterType.Default; }
}

// Convert heightmap to normal map?
public extern bool convertToNormalmap { get; set; }
// Is this texture a normal map?
public extern TextureImporterNormalFilter normalmapFilter { get; set; }
// Amount of bumpyness in the heightmap.
public extern bool flipGreenChannel { get; set; }

extern uint swizzle { get; set; }
public TextureImporterSwizzle swizzleR
{
get => (TextureImporterSwizzle)(swizzle & 0xFF);
set => swizzle = (swizzle & 0xFFFFFF00) | (uint)value;
}
public TextureImporterSwizzle swizzleG
{
get => (TextureImporterSwizzle)((swizzle >> 8) & 0xFF);
set => swizzle = (swizzle & 0xFFFF00FF) | ((uint)value<<8);
}
public TextureImporterSwizzle swizzleB
{
get => (TextureImporterSwizzle)((swizzle >> 16) & 0xFF);
set => swizzle = (swizzle & 0xFF00FFFF) | ((uint)value<<16);
}
public TextureImporterSwizzle swizzleA
{
get => (TextureImporterSwizzle)((swizzle >> 24) & 0xFF);
set => swizzle = (swizzle & 0x00FFFFFF) | ((uint)value<<24);
}

[NativeProperty("NormalmapHeightScale")]
public extern float heightmapScale { get; set; }

Expand Down Expand Up @@ -439,7 +460,6 @@ public void SetTextureSettings(TextureImporterSettings src)
internal extern bool textureStillNeedsToBeCompressed { [NativeName("DoesTextureStillNeedToBeCompressed")] get; }

// This is pure backward compatibility codepath. It can be removed when we decide that the time has come
internal extern bool ShouldShowRemoveMatteOption();
internal extern bool removeMatte { get; set; }

public extern bool ignorePngGamma { get; set; }
Expand Down
14 changes: 14 additions & 0 deletions Editor/Mono/AssetPipeline/TextureImporterEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,18 @@ public enum AndroidETC2FallbackOverride
// 32-bit uncompressed, downscaled 2x
Quality32BitDownscaled = 3
}

public enum TextureImporterSwizzle
{
R = 0,
G = 1,
B = 2,
A = 3,
OneMinusR = 4,
OneMinusG = 5,
OneMinusB = 6,
OneMinusA = 7,
Zero = 8,
One = 9
}
}
35 changes: 35 additions & 0 deletions Editor/Mono/AssetPipeline/TextureImporterTypes.bindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public sealed partial class TextureImporterSettings
[SerializeField]
int m_NormalMapFilter;
[SerializeField]
int m_FlipGreenChannel;
[SerializeField]
uint m_Swizzle;
[SerializeField]
int m_IsReadable;

[SerializeField]
Expand Down Expand Up @@ -264,6 +268,37 @@ public TextureImporterNormalFilter normalMapFilter
get {return (TextureImporterNormalFilter)m_NormalMapFilter; }
set { m_NormalMapFilter = (int)value; }
}
public bool flipGreenChannel
{
get => m_FlipGreenChannel != 0;
set => m_FlipGreenChannel = value ? 1 : 0;
}

public TextureImporterSwizzle swizzleR
{
get => (TextureImporterSwizzle)(m_Swizzle & 0xFF);
set => m_Swizzle = (m_Swizzle & 0xFFFFFF00) | (uint)value;
}
public TextureImporterSwizzle swizzleG
{
get => (TextureImporterSwizzle)((m_Swizzle >> 8) & 0xFF);
set => m_Swizzle = (m_Swizzle & 0xFFFF00FF) | ((uint)value<<8);
}
public TextureImporterSwizzle swizzleB
{
get => (TextureImporterSwizzle)((m_Swizzle >> 16) & 0xFF);
set => m_Swizzle = (m_Swizzle & 0xFF00FFFF) | ((uint)value<<16);
}
public TextureImporterSwizzle swizzleA
{
get => (TextureImporterSwizzle)((m_Swizzle >> 24) & 0xFF);
set => m_Swizzle = (m_Swizzle & 0x00FFFFFF) | ((uint)value<<24);
}
internal uint swizzleRaw
{
get => m_Swizzle;
set => m_Swizzle = value;
}
public TextureImporterAlphaSource alphaSource
{
get {return (TextureImporterAlphaSource)m_AlphaSource; }
Expand Down
9 changes: 1 addition & 8 deletions Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,7 @@ internal static ShaderCompilerData[] OnPreprocessShaders(Shader shader, ShaderSn
{
foreach (IPreprocessShaders abtc in processors.shaderProcessors)
{
try
{
abtc.OnProcessShader(shader, snippet, dataList);
}
catch (Exception e)
{
Debug.LogException(e);
}
abtc.OnProcessShader(shader, snippet, dataList);
}
}
return dataList.ToArray();
Expand Down
31 changes: 14 additions & 17 deletions Editor/Mono/BuildPipeline/DataBuildDirtyTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ class BuildDataInputFile
public string path;
public string contentHash;

public BuildDataInputFile(NPath npath)
public BuildDataInputFile(NPath npath, bool developmentBuild)
{
path = npath.ToString();
if (npath.HasExtension("cs"))
{
var monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>(path);
if (monoScript != null)
contentHash = monoScript.GetPropertiesHashString();
contentHash = monoScript.GetPropertiesHashString(developmentBuild);
}
else
{
contentHash = AssetDatabase.GetAssetDependencyHash(npath.ToString()).ToString();
}
}
}

Expand Down Expand Up @@ -68,19 +66,17 @@ bool CheckAssetDirty(BuildDataInputFile file)
return true;
}

string hash = "";
string contentHash = "";
if (path.Extension == "cs")
{
var monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>(path.ToString());
if (monoScript != null)
hash = monoScript.GetPropertiesHashString();
contentHash = monoScript.GetPropertiesHashString(buildOptions.HasFlag(BuildOptions.Development));
}
else
{
hash = AssetDatabase.GetAssetDependencyHash(path.ToString()).ToString();
}
contentHash = AssetDatabase.GetAssetDependencyHash(file.path).ToString();

if (hash != file.contentHash)
if (contentHash != file.contentHash)
{
Console.WriteLine($"Rebuilding Data files because {path} is dirty (hash)");
return true;
Expand All @@ -103,7 +99,7 @@ bool DoCheckDirty()
return true;
}

if (buildOptions != buildData.buildOptions)
if ((buildOptions & BuildData.BuildOptionsMask) != buildData.buildOptions)
{
Console.WriteLine("Rebuilding Data files because the build options have changed");
return true;
Expand Down Expand Up @@ -147,22 +143,23 @@ bool DoCheckDirty()
[RequiredByNativeCode]
static public void WriteBuildData(string buildDataPath, BuildReport report, string[] scenes, string[] prefabs)
{
var developmentBuild = report.summary.options.HasFlag(BuildOptions.Development);
var inputScenes = new List<BuildDataInputFile>();
foreach (var scene in scenes)
inputScenes.Add(new BuildDataInputFile(scene));
inputScenes.Add(new BuildDataInputFile(scene, developmentBuild));

var inputFiles = new List<BuildDataInputFile>();
foreach (var scene in scenes)
inputFiles.Add(new BuildDataInputFile(scene));
inputFiles.Add(new BuildDataInputFile(scene, developmentBuild));
foreach (var prefab in prefabs)
inputFiles.Add(new BuildDataInputFile(prefab));
inputFiles.Add(new BuildDataInputFile(prefab, developmentBuild));
foreach (var assetInfo in report.packedAssets.SelectMany(a => a.contents))
{
if (assetInfo.sourceAssetPath.ToNPath().FileExists() && !assetInfo.sourceAssetPath.StartsWith("."))
inputFiles.Add(new BuildDataInputFile(assetInfo.sourceAssetPath));
inputFiles.Add(new BuildDataInputFile(assetInfo.sourceAssetPath, developmentBuild));
}
foreach (var projectSetting in new NPath("ProjectSettings").Files("*.asset"))
inputFiles.Add(new BuildDataInputFile(projectSetting));
inputFiles.Add(new BuildDataInputFile(projectSetting, developmentBuild));

var buildData = new BuildData()
{
Expand All @@ -189,7 +186,7 @@ static public bool CheckDirty(string buildDataPath, BuildOptions buildOptions, s
{
buildData = JsonUtility.FromJson<BuildData>(buildReportPath.ReadAllText()),
scenes = scenes,
buildOptions = buildOptions & BuildData.BuildOptionsMask
buildOptions = buildOptions
};
return tracker.DoCheckDirty();
}
Expand Down
15 changes: 11 additions & 4 deletions Editor/Mono/BuildPipeline/DesktopStandaloneBuildWindowExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,16 @@ protected virtual string GetCannotBuildPlayerInCurrentSetupError()
{
var namedBuildTarget = EditorUserBuildSettingsUtils.CalculateSelectedNamedBuildTarget();

if (namedBuildTarget == NamedBuildTarget.Server && !m_HasServerPlayers)
return $"Dedicated Server support for {GetHostPlatformName()} is not installed";
if (namedBuildTarget == NamedBuildTarget.Server)
{
if(!m_HasServerPlayers)
return $"Dedicated Server support for {GetHostPlatformName()} is not installed";

if (PlayerSettings.GetScriptingBackend(namedBuildTarget) == ScriptingImplementation.IL2CPP && !m_IsRunningOnHostPlatform)
return string.Format("{0} IL2CPP player can only be built on {0}.", GetHostPlatformName());

return null;
}

if (PlayerSettings.GetScriptingBackend(namedBuildTarget) != ScriptingImplementation.IL2CPP)
{
Expand All @@ -220,8 +228,7 @@ protected virtual string GetCannotBuildPlayerInCurrentSetupError()
if (!m_IsRunningOnHostPlatform)
return string.Format("{0} IL2CPP player can only be built on {0}.", GetHostPlatformName());

// Il2cpp is always shipped in the Server support installer for the host platform.
if (!m_HasIl2CppPlayers && namedBuildTarget != NamedBuildTarget.Server)
if (!m_HasIl2CppPlayers)
return "Currently selected scripting backend (IL2CPP) is not installed."; // Note: error should match UWP player error message for consistency.
}

Expand Down
4 changes: 4 additions & 0 deletions Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using UnityEditor.Build;
using UnityEditor.Build.Player;
using UnityEditor.Build.Reporting;
using UnityEditor.CrashReporting;
using UnityEditor.Il2Cpp;
using UnityEditor.Scripting;
using UnityEditor.Scripting.Compilers;
Expand Down Expand Up @@ -760,6 +761,9 @@ private void ConvertPlayerDlltoCpp(Il2CppBuildPipelineData data)
arguments.Add(buildingArgument);
}

if (CrashReportingSettings.enabled)
arguments.Add($"--emit-source-mapping");

var additionalArgs = IL2CPPUtils.GetAdditionalArguments();
if (!string.IsNullOrEmpty(additionalArgs))
arguments.Add(additionalArgs);
Expand Down
4 changes: 4 additions & 0 deletions Editor/Mono/BuildPipeline/NamedBuildTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace UnityEditor.Build
"GameCoreXboxOne",
"PS5",
"EmbeddedLinux",
"QNX",
};

public static readonly NamedBuildTarget Unknown = new NamedBuildTarget("");
Expand All @@ -45,6 +46,7 @@ namespace UnityEditor.Build
public static readonly NamedBuildTarget Stadia = new NamedBuildTarget("Stadia");
public static readonly NamedBuildTarget CloudRendering = new NamedBuildTarget("CloudRendering");
public static readonly NamedBuildTarget EmbeddedLinux = new NamedBuildTarget("EmbeddedLinux");
public static readonly NamedBuildTarget QNX = new NamedBuildTarget("QNX");

public string TargetName { get; }

Expand Down Expand Up @@ -99,6 +101,8 @@ public static NamedBuildTarget FromBuildTargetGroup(BuildTargetGroup buildTarget
return NamedBuildTarget.CloudRendering;
case BuildTargetGroup.EmbeddedLinux:
return NamedBuildTarget.EmbeddedLinux;
case BuildTargetGroup.QNX:
return NamedBuildTarget.QNX;

// Build targets that are not explicitly listed
case BuildTargetGroup.Lumin:
Expand Down
2 changes: 2 additions & 0 deletions Editor/Mono/BuildTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public enum BuildTarget

EmbeddedLinux = 45,

QNX = 46,

// obsolete identifiers. We're using different values so that ToString() works.
[System.Obsolete("Use iOS instead (UnityUpgradable) -> iOS", true)]
iPhone = -1,
Expand Down
2 changes: 2 additions & 0 deletions Editor/Mono/BuildTargetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal static class BuildTargetConverter
return RuntimePlatform.Stadia;
case BuildTarget.EmbeddedLinux:
return RuntimePlatform.EmbeddedLinuxArm64;
case BuildTarget.QNX:
return RuntimePlatform.QNXArm64;
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions Editor/Mono/BuildTargetGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@ public enum BuildTargetGroup
PS5 = 33,

EmbeddedLinux = 34,

QNX = 35,
}
}
6 changes: 4 additions & 2 deletions Editor/Mono/ConsoleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ enum ConsoleFlags
static ConsoleWindow ms_ConsoleWindow = null;
private string m_SearchText;

static readonly int k_HasSpaceForExtraButtonsCutoff = 420;

public static void ShowConsoleWindow(bool immediate)
{
if (!ms_ConsoleWindow)
Expand Down Expand Up @@ -476,7 +478,7 @@ void UpdateListView()

bool HasSpaceForExtraButtons()
{
return position.width > 420;
return position.width > k_HasSpaceForExtraButtonsCutoff;
}

internal void OnGUI()
Expand Down Expand Up @@ -543,7 +545,7 @@ internal void OnGUI()
if (HasSpaceForExtraButtons())
{
SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPause, Constants.MiniButton));
PlayerConnectionGUILayout.ConnectionTargetSelectionDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown);
PlayerConnectionGUILayout.ConnectionTargetSelectionDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown, (int)(position.width - k_HasSpaceForExtraButtonsCutoff) + 80 );
}

GUILayout.FlexibleSpace();
Expand Down
12 changes: 9 additions & 3 deletions Editor/Mono/EditorApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,14 @@ internal static string GetDefaultMainWindowTitle(ApplicationTitleDescriptor desc

[RequiredByNativeCode]
internal static string BuildMainWindowTitle()
{
var desc = GetApplicationTitleDescriptor();
updateMainWindowTitle?.Invoke(desc);

return desc.title;
}

internal static ApplicationTitleDescriptor GetApplicationTitleDescriptor()
{
var activeSceneName = L10n.Tr("Untitled");
if (!string.IsNullOrEmpty(SceneManager.GetActiveScene().path))
Expand All @@ -347,9 +355,7 @@ internal static string BuildMainWindowTitle()

desc.title = GetDefaultMainWindowTitle(desc);

updateMainWindowTitle?.Invoke(desc);

return desc.title;
return desc;
}

[RequiredByNativeCode]
Expand Down
Loading

0 comments on commit e740821

Please sign in to comment.