Skip to content

Commit 2ea5a24

Browse files
author
Unity Technologies
committed
Unity 2019.3.0a5 C# reference source code
1 parent 222c983 commit 2ea5a24

110 files changed

Lines changed: 5031 additions & 8330 deletions

File tree

Some content is hidden

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

Editor/Mono/Animation/AnimationWindow/AnimationWindowCurve.cs

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace UnityEditorInternal
1313
{
14-
internal class AnimationWindowCurve : IComparable<AnimationWindowCurve>
14+
internal class AnimationWindowCurve : IComparable<AnimationWindowCurve>, IEquatable<AnimationWindowCurve>
1515
{
1616
public const float timeEpsilon = 0.00001f;
1717

@@ -101,47 +101,13 @@ public int GetBindingHashCode()
101101

102102
public int CompareTo(AnimationWindowCurve obj)
103103
{
104-
bool pathEquals = path.Equals(obj.path);
105-
bool typeEquals = obj.type == type;
106-
107-
if (!pathEquals && depth != obj.depth)
104+
if (!path.Equals(obj.path))
108105
{
109-
int minLength = Math.Min(path.Length, obj.path.Length);
110-
int commonLength = 0;
111-
int index = 0;
112-
for (; index < minLength; ++index)
113-
{
114-
if (path[index] != obj.path[index])
115-
break;
116-
117-
if (path[index] == '/')
118-
commonLength = index + 1;
119-
}
120-
121-
if (index == minLength)
122-
commonLength = minLength;
123-
124-
string subPath1 = path.Substring(commonLength);
125-
string subPath2 = obj.path.Substring(commonLength);
126-
127-
if (String.IsNullOrEmpty(subPath1))
128-
return -1;
129-
else if (String.IsNullOrEmpty(subPath2))
130-
return 1;
131-
132-
Regex r = new Regex(@"^[^\/]*\/");
133-
134-
Match match1 = r.Match(subPath1);
135-
string next1 = match1.Success ? match1.Value.Substring(0, match1.Value.Length - 1) : subPath1;
136-
137-
Match match2 = r.Match(subPath2);
138-
string next2 = match2.Success ? match2.Value.Substring(0, match2.Value.Length - 1) : subPath2;
139-
140-
return next1.CompareTo(next2);
106+
return ComparePaths(obj.path);
141107
}
142108

143-
bool sameTransformComponent = type == typeof(Transform) && obj.type == typeof(Transform) && pathEquals;
144-
bool oneIsTransformComponent = (type == typeof(Transform) || obj.type == typeof(Transform)) && pathEquals;
109+
bool sameTransformComponent = type == typeof(Transform) && obj.type == typeof(Transform);
110+
bool oneIsTransformComponent = (type == typeof(Transform) || obj.type == typeof(Transform));
145111

146112
// We want to sort position before rotation
147113
if (sameTransformComponent)
@@ -164,15 +130,45 @@ public int CompareTo(AnimationWindowCurve obj)
164130
}
165131

166132
// Sort (.r, .g, .b, .a) and (.x, .y, .z, .w)
167-
if (pathEquals && typeEquals)
133+
if (obj.type == type)
168134
{
169135
int lhsIndex = AnimationWindowUtility.GetComponentIndex(obj.propertyName);
170136
int rhsIndex = AnimationWindowUtility.GetComponentIndex(propertyName);
171137
if (lhsIndex != -1 && rhsIndex != -1 && propertyName.Substring(0, propertyName.Length - 2) == obj.propertyName.Substring(0, obj.propertyName.Length - 2))
172138
return rhsIndex - lhsIndex;
173139
}
174140

175-
return (path + type + propertyName).CompareTo(obj.path + obj.type + obj.propertyName);
141+
return string.Compare((path + type + propertyName), obj.path + obj.type + obj.propertyName, StringComparison.Ordinal);
142+
}
143+
144+
public bool Equals(AnimationWindowCurve other)
145+
{
146+
return CompareTo(other) == 0;
147+
}
148+
149+
int ComparePaths(string otherPath)
150+
{
151+
var thisPath = path.Split('/');
152+
var objPath = otherPath.Split('/');
153+
154+
int smallerLength = Math.Min(thisPath.Length, objPath.Length);
155+
for (int i = 0; i < smallerLength; ++i)
156+
{
157+
int compare = string.Compare(thisPath[i], objPath[i], StringComparison.Ordinal);
158+
if (compare == 0)
159+
{
160+
continue;
161+
}
162+
163+
return compare;
164+
}
165+
166+
if (thisPath.Length < objPath.Length)
167+
{
168+
return -1;
169+
}
170+
171+
return 1;
176172
}
177173

178174
public AnimationCurve ToAnimationCurve()

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,24 @@ private static bool StripAssembliesTo(string[] assemblies, string[] searchDirs,
9696
args.Add($"--rule-set={GetRuleSetForStrippingLevel(managedStrippingLevel)}");
9797
args.Add($"--editor-data-file={CommandLineFormatter.PrepareFileName(editorToLinkerDataPath)}");
9898

99-
// One final check to make sure we only run high on latest runtime.
100-
if ((managedStrippingLevel == ManagedStrippingLevel.High) && (PlayerSettingsEditor.IsLatestApiCompatibility(PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup))))
99+
var compilerPlatform = "";
100+
var compilerArchitecture = "";
101+
Il2CppNativeCodeBuilder il2cppNativeCodeBuilder = platformProvider.CreateIl2CppNativeCodeBuilder();
102+
if (il2cppNativeCodeBuilder != null)
101103
{
102-
// Prepare the arguments to run the UnityLinker. When in high mode, need to also
103-
// supply the IL2CPP compiler platform and compiler architecture. When the scripting backend
104-
// is not IL2CPP, we have to map those strings and use a utility function to figure out proper strings.
105-
106-
// Currently only need to do this on the non aot platforms of Android, Windows, Mac, Linux.
107-
var compilerPlatform = "";
108-
var compilerArchitecture = "";
109-
Il2CppNativeCodeBuilder il2cppNativeCodeBuilder = platformProvider.CreateIl2CppNativeCodeBuilder();
110-
if (il2cppNativeCodeBuilder != null)
111-
{
112-
compilerPlatform = il2cppNativeCodeBuilder.CompilerPlatform;
113-
compilerArchitecture = il2cppNativeCodeBuilder.CompilerArchitecture;
114-
}
115-
else
116-
{
117-
GetUnityLinkerPlatformStringsFromBuildTarget(platformProvider.target, out compilerPlatform, out compilerArchitecture);
118-
}
119-
120-
args.Add($"--platform={compilerPlatform}");
121-
if (!string.IsNullOrEmpty(compilerArchitecture))
122-
args.Add($"--architecture={compilerArchitecture}");
104+
compilerPlatform = il2cppNativeCodeBuilder.CompilerPlatform;
105+
compilerArchitecture = il2cppNativeCodeBuilder.CompilerArchitecture;
106+
}
107+
else
108+
{
109+
// When the scripting backend is not IL2CPP, we have to map those strings and use a utility function to figure out proper strings.
110+
GetUnityLinkerPlatformStringsFromBuildTarget(platformProvider.target, out compilerPlatform, out compilerArchitecture);
123111
}
124112

113+
args.Add($"--platform={compilerPlatform}");
114+
if (!string.IsNullOrEmpty(compilerArchitecture))
115+
args.Add($"--architecture={compilerArchitecture}");
116+
125117
if (!UseUnityLinkerEngineModuleStripping)
126118
{
127119
args.Add("--disable-engine-module-support");

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,10 @@ static bool IsColorSpaceValid(BuildPlatform platform)
410410
if (PlayerSettings.colorSpace == ColorSpace.Linear)
411411
{
412412
var hasMinGraphicsAPI = true;
413-
var hasMinOSVersion = true;
414413

415414
var apis = PlayerSettings.GetGraphicsAPIs(platform.defaultTarget);
416415
if (platform.targetGroup == BuildTargetGroup.Android)
417416
{
418-
hasMinOSVersion = (int)PlayerSettings.Android.minSdkVersion >= 18;
419417
hasMinGraphicsAPI = (apis.Contains(GraphicsDeviceType.Vulkan) || apis.Contains(GraphicsDeviceType.OpenGLES3)) && !apis.Contains(GraphicsDeviceType.OpenGLES2);
420418
}
421419
else if (platform.targetGroup == BuildTargetGroup.iOS || platform.targetGroup == BuildTargetGroup.tvOS)
@@ -428,7 +426,7 @@ static bool IsColorSpaceValid(BuildPlatform platform)
428426
hasMinGraphicsAPI = apis.Contains(GraphicsDeviceType.OpenGLES3) && !apis.Contains(GraphicsDeviceType.OpenGLES2);
429427
}
430428

431-
return hasMinGraphicsAPI && hasMinOSVersion;
429+
return hasMinGraphicsAPI;
432430
}
433431
else
434432
{
@@ -441,7 +439,6 @@ static bool IsLightmapEncodingValid(BuildPlatform platform)
441439
if (PlayerSettings.GetLightmapEncodingQualityForPlatformGroup(platform.targetGroup) != LightmapEncodingQuality.Low)
442440
{
443441
var hasMinGraphicsAPI = true;
444-
var hasMinOSVersion = true;
445442

446443
if (platform.targetGroup == BuildTargetGroup.iOS)
447444
{
@@ -457,10 +454,9 @@ static bool IsLightmapEncodingValid(BuildPlatform platform)
457454
{
458455
var apis = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
459456
hasMinGraphicsAPI = (apis.Contains(GraphicsDeviceType.Vulkan) || apis.Contains(GraphicsDeviceType.OpenGLES3)) && !apis.Contains(GraphicsDeviceType.OpenGLES2);
460-
hasMinOSVersion = (int)PlayerSettings.Android.minSdkVersion >= 18;
461457
}
462458

463-
return hasMinGraphicsAPI && hasMinOSVersion;
459+
return hasMinGraphicsAPI;
464460
}
465461
else
466462
{

Editor/Mono/BuildPlayerWindowBuildMethods.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public static void BuildPlayer(BuildPlayerOptions options)
168168
delayToAfterScriptReload = true;
169169
}
170170

171+
bool locationPathExistedBeforeBuild = System.IO.Directory.Exists(options.locationPathName);
171172
// Trigger build.
172173
// Note: report will be null, if delayToAfterScriptReload = true
173174
var report = BuildPipeline.BuildPlayerInternalNoCheck(options.scenes, options.locationPathName, null, options.targetGroup, options.target, options.options, delayToAfterScriptReload);
@@ -185,7 +186,7 @@ public static void BuildPlayer(BuildPlayerOptions options)
185186
case Build.Reporting.BuildResult.Failed:
186187
// On some platforms the user creates the build folder, therefore they own the folder and
187188
// it should not be automatically deleted by the Unity Editor, even if it is empty (case 1073851)
188-
if (options.target != BuildTarget.XboxOne)
189+
if (options.target != BuildTarget.XboxOne && !locationPathExistedBeforeBuild)
189190
DeleteBuildFolderIfEmpty(report.summary.outputPath);
190191
Debug.LogError(resultStr);
191192
throw new BuildMethodException(report.SummarizeErrors());

Editor/Mono/DragAndDropService.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,20 @@ private static DragAndDropVisualMode DefaultProjectBrowserDrop(int dragUponInsta
185185
if (search.Find(dragUponInstanceId, null))
186186
return InternalEditorUtility.ProjectWindowDrag(search, perform);
187187

188-
var path = AssetDatabase.GetAssetPath(dragUponInstanceId);
189-
if (string.IsNullOrEmpty(path))
190-
return DragAndDropVisualMode.Rejected;
191-
192-
var packageInfo = PackageManager.PackageInfo.FindForAssetPath(path);
193-
if (packageInfo != null)
188+
if (dragUponInstanceId != 0)
194189
{
195-
search = new HierarchyProperty(packageInfo.assetPath);
196-
if (search.Find(dragUponInstanceId, null))
197-
return InternalEditorUtility.ProjectWindowDrag(search, perform);
198-
}
190+
var path = AssetDatabase.GetAssetPath(dragUponInstanceId);
191+
if (string.IsNullOrEmpty(path))
192+
return DragAndDropVisualMode.Rejected;
199193

194+
var packageInfo = PackageManager.PackageInfo.FindForAssetPath(path);
195+
if (packageInfo != null)
196+
{
197+
search = new HierarchyProperty(packageInfo.assetPath);
198+
if (search.Find(dragUponInstanceId, null))
199+
return InternalEditorUtility.ProjectWindowDrag(search, perform);
200+
}
201+
}
200202
return InternalEditorUtility.ProjectWindowDrag(null, perform);
201203
}
202204

Editor/Mono/GI/Lightmapping.bindings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UnityEngine.Scripting;
1010
using System.Runtime.InteropServices;
1111
using UnityEngineInternal;
12+
using Scene = UnityEngine.SceneManagement.Scene;
1213

1314
namespace UnityEditor
1415
{
@@ -444,5 +445,13 @@ public sealed partial class Lightmapping
444445
// If we should write out AO to disk. Only works in On Demand bakes
445446
[StaticAccessor("GetLightmapEditorSettings()")]
446447
public extern static bool extractAmbientOcclusion { get; set; }
448+
449+
[NativeThrows]
450+
[FreeFunction]
451+
public static extern bool BakeAsync(Scene scene);
452+
453+
[NativeThrows]
454+
[FreeFunction]
455+
public static extern bool Bake(Scene scene);
447456
}
448457
}

Editor/Mono/GUIView.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ internal partial class GUIView
2626
public extern void RepaintImmediately();
2727
public extern void CaptureRenderDocScene();
2828
public extern void CaptureRenderDocFullContent();
29+
public extern void BeginCaptureRenderDoc();
30+
public extern void EndCaptureRenderDoc();
2931

3032
internal extern bool mouseRayInvisible {[NativeMethod("IsMouseRayInvisible")] get; [NativeMethod("SetMouseRayInvisible")] set; }
3133
internal extern bool disableInputEvents {[NativeMethod("AreInputEventsDisabled")] get; [NativeMethod("SetDisableInputEvents")] set; }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
using System.Linq;
7+
using System.Collections.Generic;
8+
using UnityEditor;
9+
using UnityEngine;
10+
using UnityEngine.Bindings;
11+
using UnityEngine.Scripting;
12+
13+
14+
namespace UnityEditor
15+
{
16+
/// <summary>
17+
/// Used by com.unity.hotreload package
18+
/// </summary>
19+
[NativeType(Header = "Runtime/Export/HotReload/HotReload.bindings.h")]
20+
[NativeConditional("HOT_RELOAD_AVAILABLE")]
21+
internal static class HotReloadSerializer
22+
{
23+
[NativeThrows]
24+
[FreeFunction("HotReload::SerializeAsset")]
25+
internal extern static byte[] SerializeAsset(UnityEngine.Object asset, BuildTarget buildTarget);
26+
}
27+
}

Editor/Mono/Inspector/AvatarPreview.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ private class ObjectSelectorOperation : ObjectSelectorReceiver
2626
{
2727
public static void Start(AvatarPreview owner)
2828
{
29-
var operation = new ObjectSelectorOperation(owner, ObjectSelector.get);
29+
var operation = ScriptableObject.CreateInstance<ObjectSelectorOperation>();
30+
operation.m_Owner = owner;
31+
operation.m_Selector = ObjectSelector.get;
3032
operation.Execute();
3133
}
3234

33-
public ObjectSelectorOperation(AvatarPreview owner, ObjectSelector selector)
34-
{
35-
m_Owner = owner;
36-
m_Selector = selector;
37-
}
38-
3935
AvatarPreview m_Owner;
4036
ObjectSelector m_Selector;
4137

Editor/Mono/Inspector/BlendTreeInspector.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,8 @@ private void BlendGraph(Rect area)
655655
// determine closest animation or blend tree
656656
float clickPosition = evt.mousePosition.x;
657657
float distance = Mathf.Infinity;
658+
659+
m_ReorderableList.index = -1;
658660
for (int i = 0; i < points.Length; i++)
659661
{
660662
float last = (i == 0) ? points[i] : points[i - 1];
@@ -673,9 +675,12 @@ private void BlendGraph(Rect area)
673675
m_UseAutomaticThresholds.boolValue = false;
674676

675677
// Get current blend value.
676-
SerializedProperty child = m_Childs.GetArrayElementAtIndex(m_ReorderableList.index);
677-
SerializedProperty threshold = child.FindPropertyRelative("m_Threshold");
678-
curBlendValue = threshold.floatValue;
678+
if (m_ReorderableList.index != -1)
679+
{
680+
SerializedProperty child = m_Childs.GetArrayElementAtIndex(m_ReorderableList.index);
681+
SerializedProperty threshold = child.FindPropertyRelative("m_Threshold");
682+
curBlendValue = threshold.floatValue;
683+
}
679684
}
680685

681686
// Get drag'n'drop infos.

0 commit comments

Comments
 (0)