Skip to content

Commit 2652cec

Browse files
author
Unity Technologies
committed
Unity 2020.2.0b2 C# reference source code
1 parent ce62a54 commit 2652cec

File tree

76 files changed

+913
-324
lines changed

Some content is hidden

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

76 files changed

+913
-324
lines changed

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,13 +1060,15 @@ public static Component GetClosestAnimationPlayerComponentInParents(Transform tr
10601060
{
10611061
while (true)
10621062
{
1063-
var animator = tr.GetComponent<Animator>();
1064-
if (animator != null)
1063+
if (tr.TryGetComponent(out Animator animator))
1064+
{
10651065
return animator;
1066+
}
10661067

1067-
var animation = tr.GetComponent<Animation>();
1068-
if (animation != null)
1068+
if (tr.TryGetComponent(out Animation animation))
1069+
{
10691070
return animation;
1071+
}
10701072

10711073
if (tr == tr.root)
10721074
break;
@@ -1081,7 +1083,10 @@ public static Animator GetClosestAnimatorInParents(Transform tr)
10811083
{
10821084
while (true)
10831085
{
1084-
if (tr.GetComponent<Animator>() != null) return tr.GetComponent<Animator>();
1086+
if (tr.TryGetComponent(out Animator animator))
1087+
{
1088+
return animator;
1089+
}
10851090
if (tr == tr.root) break;
10861091
tr = tr.parent;
10871092
}
@@ -1093,7 +1098,10 @@ public static Animation GetClosestAnimationInParents(Transform tr)
10931098
{
10941099
while (true)
10951100
{
1096-
if (tr.GetComponent<Animation>() != null) return tr.GetComponent<Animation>();
1101+
if (tr.TryGetComponent(out Animation animation))
1102+
{
1103+
return animation;
1104+
}
10971105
if (tr == tr.root) break;
10981106
tr = tr.parent;
10991107
}

Editor/Mono/Animation/AnimationWindow/ControlPointRenderer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public void Render()
9797

9898
if (renderChunk.isDirty)
9999
{
100-
renderChunk.mesh.vertices = renderChunk.vertices.ToArray();
101-
renderChunk.mesh.colors32 = renderChunk.colors.ToArray();
102-
renderChunk.mesh.uv = renderChunk.uvs.ToArray();
100+
renderChunk.mesh.SetVertices(renderChunk.vertices);
101+
renderChunk.mesh.SetColors(renderChunk.colors);
102+
renderChunk.mesh.SetUVs(0, renderChunk.uvs);
103103

104-
renderChunk.mesh.SetIndices(renderChunk.indices.ToArray(), MeshTopology.Triangles, 0);
104+
renderChunk.mesh.SetIndices(renderChunk.indices, MeshTopology.Triangles, 0);
105105

106106
renderChunk.isDirty = false;
107107
}

Editor/Mono/Animation/AnimationWindow/CurveEditor.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ internal void DeleteSelectedKeys()
14141414
continue;
14151415

14161416
if (!settings.allowDeleteLastKeyInCurve)
1417-
if (cw.curve.keys.Length == 1)
1417+
if (cw.curve.length == 1)
14181418
continue;
14191419

14201420
cw.curve.RemoveKey(k.key);
@@ -1444,7 +1444,7 @@ private void DeleteKeys(object obj)
14441444
for (int i = keyList.Count - 1; i >= 0; i--)
14451445
{
14461446
if (!settings.allowDeleteLastKeyInCurve)
1447-
if (keyList[i].curve.keys.Length == 1)
1447+
if (keyList[i].curve.length == 1)
14481448
continue;
14491449

14501450
if (!GetCurveWrapperFromID(keyList[i].curveId).animationIsEditable)
@@ -1933,7 +1933,7 @@ List<int> CreateKeyFromClick(Vector2 viewPos)
19331933
CurveWrapper cw = m_AnimationCurves[singleCurveIndex];
19341934
Vector2 localPos = ViewToDrawingTransformPoint(viewPos);
19351935
float time = localPos.x;
1936-
if (cw.curve.keys.Length == 0 || time < cw.curve.keys[0].time || time > cw.curve.keys[cw.curve.keys.Length - 1].time)
1936+
if (cw.curve.length == 0 || time < cw.curve[0].time || time > cw.curve[cw.curve.length - 1].time)
19371937
{
19381938
if (CreateKeyFromClick(singleCurveIndex, localPos))
19391939
curveIds.Add(cw.id);
@@ -2151,9 +2151,10 @@ CurveSelection FindNearest()
21512151
if (cw.readOnly || cw.hidden)
21522152
continue;
21532153

2154-
for (int i = 0; i < cw.curve.keys.Length; ++i)
2154+
Keyframe[] keys = cw.curve.keys;
2155+
for (int i = 0; i < cw.curve.length; ++i)
21552156
{
2156-
Keyframe k = cw.curve.keys[i];
2157+
Keyframe k = keys[i];
21572158
float d = (GetGUIPoint(cw, new Vector2(k.time, k.value)) - mousePos).sqrMagnitude;
21582159
// If we have an exact hit we just return that key
21592160
if (d <= kExactPickDistSqr)
@@ -2269,7 +2270,7 @@ bool HandleCurveAndRegionMoveToFrontOnMouseDown(ref Vector2 timeValue, ref Curve
22692270
if (mouseY >= v1 && mouseY <= v2)
22702271
{
22712272
timeValue = mousePositionInDrawing;
2272-
curves = new[] {cw, cw2};
2273+
curves = new[] { cw, cw2 };
22732274
MoveCurveToFront(cw.id);
22742275
return true;
22752276
}
@@ -2329,7 +2330,7 @@ void SelectPoints()
23292330
if (curve != null)
23302331
{
23312332
BeginRangeSelection();
2332-
for (int keyIndex = 0; keyIndex < curve.keys.Length; ++keyIndex)
2333+
for (int keyIndex = 0; keyIndex < curve.length; ++keyIndex)
23332334
{
23342335
if (!selectedCurves.Any(x => x.curveID == selectedPoint.curveID && x.key == keyIndex))
23352336
{
@@ -4086,7 +4087,7 @@ public void GridGUI()
40864087
float[] ticksPos = (float[])ticks.Clone();
40874088

40884089
// Calculate how many decimals are needed to show the differences between the labeled ticks
4089-
int decimals = MathUtils.GetNumberOfDecimalsForMinimumDifference(vTicks.GetPeriodOfLevel(labelLevel));
4090+
int decimals = MathUtils.GetNumberOfDecimalsForMinimumDifference(vTicks.GetPeriodOfLevel(labelLevel));
40904091
string format = "n" + decimals;
40914092
m_AxisLabelFormat = format;
40924093

Editor/Mono/Animation/AnimationWindow/CurveRenderer/NormalCurveRenderer.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ internal class NormalCurveRenderer : CurveRenderer
2020
private AnimationCurve m_Curve;
2121
private float m_CustomRangeStart = 0;
2222
private float m_CustomRangeEnd = 0;
23-
private float rangeStart { get { return (m_CustomRangeStart == 0 && m_CustomRangeEnd == 0 && m_Curve.length > 0 ? m_Curve.keys[0].time : m_CustomRangeStart); } }
24-
private float rangeEnd { get { return (m_CustomRangeStart == 0 && m_CustomRangeEnd == 0 && m_Curve.length > 0 ? m_Curve.keys[m_Curve.length - 1].time : m_CustomRangeEnd); } }
23+
private float rangeStart { get { return (m_CustomRangeStart == 0 && m_CustomRangeEnd == 0 && m_Curve.length > 0 ? m_Curve[0].time : m_CustomRangeStart); } }
24+
private float rangeEnd { get { return (m_CustomRangeStart == 0 && m_CustomRangeEnd == 0 && m_Curve.length > 0 ? m_Curve[m_Curve.length - 1].time : m_CustomRangeEnd); } }
2525
private WrapMode preWrapMode = WrapMode.Once;
2626
private WrapMode postWrapMode = WrapMode.Once;
2727

@@ -262,11 +262,14 @@ public void DrawCurve(float minTime, float maxTime, Color color, Matrix4x4 trans
262262
{
263263
BuildCurveMesh();
264264

265-
Keyframe[] keys = m_Curve.keys;
266-
if (keys.Length > 0)
265+
int numKeys = m_Curve.length;
266+
int first = 0;
267+
int last = Mathf.Max(first, numKeys - 1);
268+
269+
if (numKeys > 0)
267270
{
268-
Vector3 firstPoint = new Vector3(rangeStart, keys.First().value);
269-
Vector3 lastPoint = new Vector3(rangeEnd, keys.Last().value);
271+
Vector3 firstPoint = new Vector3(rangeStart, m_Curve[first].value);
272+
Vector3 lastPoint = new Vector3(rangeEnd, m_Curve[last].value);
270273
DrawCurveWrapped(minTime, maxTime, rangeStart, rangeEnd, preWrapMode, postWrapMode, m_CurveMesh, firstPoint, lastPoint, transform, color, wrapColor);
271274
}
272275
}

Editor/Mono/Animation/AnimationWindow/Deprecated/AnimationEventTimeline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public int Compare(AnimationEvent x, AnimationEvent y)
5454
}
5555
}
5656

57-
private class EventLineContextMenuObject
57+
private struct EventLineContextMenuObject
5858
{
5959
public GameObject m_Animated;
6060
public AnimationClip m_Clip;

Editor/Mono/Animation/AnimationWindow/MinMaxCurveEditorWindow.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ void UpdateRegionDomain()
249249
{
250250
foreach (var animationCurve in new[] { m_MaxCurve, m_MinCurve })
251251
{
252-
if (animationCurve.length > 0)
252+
var keyCount = animationCurve.length;
253+
if (keyCount > 0)
253254
{
254255
var keys = animationCurve.keys;
255-
domain.x = Mathf.Min(domain.x, keys.First().time);
256-
domain.y = Math.Max(domain.y, keys.Last().time);
256+
domain.x = Mathf.Min(domain.x, animationCurve[0].time);
257+
domain.y = Math.Max(domain.y, animationCurve[keyCount - 1].time);
257258
}
258259
}
259260
}

Editor/Mono/Animation/TickHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ public int GetLevelWithMinSeparation(float pixelSeparation)
190190

191191
public void SetTickStrengths(float tickMinSpacing, float tickMaxSpacing, bool sqrt)
192192
{
193-
m_TickStrengths = new float[m_TickModulos.Length];
193+
if (m_TickStrengths == null || m_TickStrengths.Length != m_TickModulos.Length)
194+
{
195+
m_TickStrengths = new float[m_TickModulos.Length];
196+
}
197+
194198
m_SmallestTick = 0;
195199
m_BiggestTick = m_TickModulos.Length - 1;
196200

Editor/Mono/AssetPipeline/TextureUtil.bindings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
using System;
66
using UnityEngine;
77
using UnityEngine.Bindings;
8-
8+
using UnityEngine.Experimental.Rendering; //for GraphicsFormat
99
namespace UnityEditor
1010
{
1111
[NativeHeader("Editor/Src/AssetPipeline/TextureImporting/TextureImporterUtils.h")]
1212
[NativeHeader("Runtime/Graphics/TextureFormat.h")]
13+
[NativeHeader("Runtime/Graphics/Format.h")]
1314
internal static class TextureUtil
1415
{
1516
[Obsolete("GetStorageMemorySize has been deprecated since it is limited to 2GB. Please use GetStorageMemorySizeLong() instead.")]
@@ -69,6 +70,9 @@ public static int GetRuntimeMemorySize(Texture t)
6970
[FreeFunction]
7071
public static extern bool IsHDRFormat(TextureFormat format);
7172

73+
[FreeFunction("IsHDRFormat")]
74+
public static extern bool IsHDRGraphicsFormat(GraphicsFormat format);
75+
7276
[FreeFunction]
7377
public static extern bool HasAlphaTextureFormat(TextureFormat format);
7478

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ private static bool StripAssembliesTo(string outputFolder, out string output, ou
153153
private static bool RunAssemblyLinker(IEnumerable<string> args, out string @out, out string err, string linkerPath, string workingDirectory)
154154
{
155155
var argString = args.Aggregate((buff, s) => buff + " " + s);
156-
Console.WriteLine("Invoking UnityLinker with arguments: " + argString);
157-
Runner.RunManagedProgram(linkerPath, argString, workingDirectory, null, null);
156+
var responseFile = Path.Combine(workingDirectory, "response.rsp");
157+
File.WriteAllText(responseFile, argString);
158+
Console.WriteLine("Invoking UnityLinker with response file. response.rsp contents: " + argString);
159+
Runner.RunManagedProgram(linkerPath, $"@{CommandLineFormatter.PrepareFileName(responseFile)}", workingDirectory, null, null);
158160

159161
@out = "";
160162
err = "";

Editor/Mono/BuildPipeline/BuildUtils.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,20 @@ internal static void RunNetCoreProgram(string exe, string args, string workingDi
102102
}
103103

104104
// Used when debugging il2cpp.exe from Windows, please don't remove it
105-
public static void RunNativeProgram(string exe, string args)
106-
{
107-
using (var p = new NativeProgram(exe, args))
108-
{
109-
p.Start();
110-
p.WaitForExit();
111-
if (p.ExitCode != 0)
112-
{
113-
Debug.LogError("Failed running " + exe + " " + args + "\n\n" + p.GetAllOutput());
114-
115-
throw new Exception(string.Format("{0} did not run properly!", exe));
116-
}
117-
}
118-
}
105+
// public static void RunNativeProgram(string exe, string args)
106+
// {
107+
// using (var p = new NativeProgram(exe, args))
108+
// {
109+
// p.Start();
110+
// p.WaitForExit();
111+
// if (p.ExitCode != 0)
112+
// {
113+
// Debug.LogError("Failed running " + exe + " " + args + "\n\n" + p.GetAllOutput());
114+
//
115+
// throw new Exception(string.Format("{0} did not run properly!", exe));
116+
// }
117+
// }
118+
// }
119119

120120
private static void RunProgram(Program p, string exe, string args, string workingDirectory, CompilerOutputParserBase parser)
121121
{

0 commit comments

Comments
 (0)