Skip to content

Commit b376c3a

Browse files
author
Unity Technologies
committed
Unity 2020.2.0a9 C# reference source code
1 parent 3c2fbfe commit b376c3a

File tree

96 files changed

+1209
-677
lines changed

Some content is hidden

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

96 files changed

+1209
-677
lines changed

Editor/Mono/Animation/AnimationWindow/AnimationWindowHierarchyGUI.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -832,24 +832,28 @@ override protected void SyncFakeItem()
832832

833833
override protected void RenameEnded()
834834
{
835-
string newName = GetRenameOverlay().name;
836-
string oldName = GetRenameOverlay().originalName;
837-
838-
if (newName != oldName)
835+
var renameOverlay = GetRenameOverlay();
836+
if (renameOverlay.userAcceptedRename)
839837
{
840-
Undo.RecordObject(state.activeAnimationClip, "Rename Curve");
838+
string newName = renameOverlay.name;
839+
string oldName = renameOverlay.originalName;
841840

842-
foreach (AnimationWindowCurve curve in m_RenamedNode.curves)
841+
if (newName != oldName)
843842
{
844-
EditorCurveBinding newBinding = AnimationWindowUtility.GetRenamedBinding(curve.binding, newName);
843+
Undo.RecordObject(state.activeAnimationClip, "Rename Curve");
845844

846-
if (AnimationWindowUtility.CurveExists(newBinding, state.allCurves.ToArray()))
845+
foreach (AnimationWindowCurve curve in m_RenamedNode.curves)
847846
{
848-
Debug.LogWarning("Curve already exists, renaming cancelled.");
849-
continue;
850-
}
847+
EditorCurveBinding newBinding = AnimationWindowUtility.GetRenamedBinding(curve.binding, newName);
848+
849+
if (AnimationWindowUtility.CurveExists(newBinding, state.allCurves.ToArray()))
850+
{
851+
Debug.LogWarning("Curve already exists, renaming cancelled.");
852+
continue;
853+
}
851854

852-
AnimationWindowUtility.RenameCurvePath(curve, newBinding, curve.clip);
855+
AnimationWindowUtility.RenameCurvePath(curve, newBinding, curve.clip);
856+
}
853857
}
854858
}
855859

Editor/Mono/Annotation/SceneFXWindow.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ private void Draw(Rect rect)
7171

7272
var state = m_SceneView.sceneViewState;
7373

74-
//
75-
// scene view effect options
76-
7774
DrawListElement(drawPos, "Skybox", state.showSkybox, value => state.showSkybox = value);
7875
drawPos.y += EditorGUI.kSingleLineHeight;
7976

@@ -83,10 +80,10 @@ private void Draw(Rect rect)
8380
DrawListElement(drawPos, "Flares", state.showFlares, value => state.showFlares = value);
8481
drawPos.y += EditorGUI.kSingleLineHeight;
8582

86-
DrawListElement(drawPos, "Animated Materials", state.showMaterialUpdate, value => state.showMaterialUpdate = value);
83+
DrawListElement(drawPos, "Always Refresh", state.alwaysRefresh, value => state.alwaysRefresh = value);
8784
drawPos.y += EditorGUI.kSingleLineHeight;
8885

89-
DrawListElement(drawPos, "Post Processings", state.showImageEffects, value => state.showImageEffects = value);
86+
DrawListElement(drawPos, "Post Processing", state.showImageEffects, value => state.showImageEffects = value);
9087
drawPos.y += EditorGUI.kSingleLineHeight;
9188

9289
DrawListElement(drawPos, "Particle Systems", state.showParticleSystems, value => state.showParticleSystems = value);

Editor/Mono/AssetPostprocessor.cs

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using UnityEditor.Experimental.AssetImporters;
1717
using UnityEditorInternal;
1818
using Unity.CodeEditor;
19+
using UnityEditor.Profiling;
1920

2021
namespace UnityEditor
2122
{
@@ -673,32 +674,24 @@ static void CallPostProcessMethods(string methodName, object[] args)
673674

674675
static object InvokeMethod(MethodInfo method, object[] args)
675676
{
676-
bool profile = Profiler.enabled;
677-
if (profile)
678-
Profiler.BeginSample(method.DeclaringType.FullName + "." + method.Name);
679-
680-
var res = method.Invoke(null, args);
681-
682-
if (profile)
683-
Profiler.EndSample();
677+
object res = null;
678+
using (new EditorPerformanceTracker(method.DeclaringType.FullName + "." + method.Name))
679+
{
680+
res = method.Invoke(null, args);
681+
}
684682

685683
return res;
686684
}
687685

688686
static bool InvokeMethodIfAvailable(object target, string methodName, object[] args)
689687
{
690-
bool profile = Profiler.enabled;
691-
692688
MethodInfo method = target.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
693689
if (method != null)
694690
{
695-
if (profile)
696-
Profiler.BeginSample(target.GetType().FullName + "." + methodName);
697-
698-
method.Invoke(target, args);
699-
700-
if (profile)
701-
Profiler.EndSample();
691+
using (new EditorPerformanceTracker(target.GetType().FullName + "." + methodName))
692+
{
693+
method.Invoke(target, args);
694+
}
702695

703696
return true;
704697
}
@@ -707,18 +700,13 @@ static bool InvokeMethodIfAvailable(object target, string methodName, object[] a
707700

708701
static bool InvokeMethodIfAvailable<T>(object target, string methodName, object[] args, ref T returnedObject) where T : class
709702
{
710-
bool profile = Profiler.enabled;
711-
712703
MethodInfo method = target.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
713704
if (method != null)
714705
{
715-
if (profile)
716-
Profiler.BeginSample(target.GetType().FullName + "." + methodName);
717-
718-
returnedObject = method.Invoke(target, args) as T;
719-
720-
if (profile)
721-
Profiler.EndSample();
706+
using (new EditorPerformanceTracker(target.GetType().FullName + "." + methodName))
707+
{
708+
returnedObject = method.Invoke(target, args) as T;
709+
}
722710

723711
return true;
724712
}

Editor/Mono/AsyncHTTPClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ public Dictionary<string, string> responseHeader
112112
Dictionary<string, string> ret = new Dictionary<string, string>();
113113
foreach (var curr in headerFlattened)
114114
{
115+
if (string.IsNullOrEmpty(curr))
116+
continue;
115117
string[] line = curr.Split(new string[] { ": " }, StringSplitOptions.None);
116118
if (line.Length > 1)
117119
ret.Add(line[0], string.Concat(line.Skip(1).ToArray()));

Editor/Mono/EditorApplication.bindings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ internal static extern string windowTitle
246246

247247
internal static extern void RequestCloseAndRelaunchWithCurrentArguments();
248248

249+
// Triggers the editor to restart, after which all scripts will be recompiled.
250+
internal static void RestartEditorAndRecompileScripts()
251+
{
252+
// Clear the script assemblies so we compile after the restart.
253+
EditorCompilationInterface.Instance.CleanScriptAssemblies();
254+
255+
RequestCloseAndRelaunchWithCurrentArguments();
256+
}
257+
249258
[StaticAccessor("GetApplication()", StaticAccessorType.Dot)]
250259
private static extern void FileMenuNewScene();
251260

Editor/Mono/EditorHandles/Disc.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,7 @@ public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vecto
129129
break;
130130

131131
case EventType.Repaint:
132-
Color temp = Color.white;
133-
134-
if (id == GUIUtility.hotControl)
135-
{
136-
temp = Handles.color;
137-
Handles.color = Handles.selectedColor;
138-
}
139-
else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
140-
{
141-
temp = Handles.color;
142-
Handles.color = Handles.preselectionColor;
143-
}
132+
Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
144133

145134
// If we're dragging it, we'll go a bit further and draw a selection pie
146135
if (GUIUtility.hotControl == id)
@@ -168,15 +157,14 @@ public static Quaternion Do(int id, Quaternion rotation, Vector3 position, Vecto
168157
}
169158

170159
if (showHotArc && GUIUtility.hotControl == id || GUIUtility.hotControl != id && !cutoffPlane)
171-
Handles.DrawWireDisc(position, axis, size);
160+
Handles.DrawWireDisc(position, axis, size, thickness);
172161
else if (GUIUtility.hotControl != id && cutoffPlane)
173162
{
174163
Vector3 from = Vector3.Cross(axis, cam).normalized;
175-
Handles.DrawWireArc(position, axis, from, 180, size);
164+
Handles.DrawWireArc(position, axis, from, 180, size, thickness);
176165
}
177166

178-
if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
179-
Handles.color = temp;
167+
Handles.color = prevColor;
180168
break;
181169
}
182170

Editor/Mono/EditorHandles/FreeMove.cs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public static Vector3 Do(int id, Vector3 position, Quaternion rotation, float si
2424
Event evt = Event.current;
2525
switch (evt.GetTypeForControl(id))
2626
{
27+
case EventType.MouseMove:
2728
case EventType.Layout:
2829
// We only want the position to be affected by the Handles.matrix.
2930
Handles.matrix = Matrix4x4.identity;
@@ -116,32 +117,13 @@ public static Vector3 Do(int id, Vector3 position, Quaternion rotation, float si
116117
}
117118
break;
118119

119-
case EventType.MouseMove:
120-
if (id == HandleUtility.nearestControl)
121-
HandleUtility.Repaint();
122-
break;
123-
124120
case EventType.Repaint:
125-
Color temp = Color.white;
126-
127-
if (id == GUIUtility.hotControl)
128-
{
129-
temp = Handles.color;
130-
Handles.color = Handles.selectedColor;
131-
}
132-
else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
133-
{
134-
temp = Handles.color;
135-
Handles.color = Handles.preselectionColor;
136-
}
137-
121+
Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
138122
// We only want the position to be affected by the Handles.matrix.
139123
Handles.matrix = Matrix4x4.identity;
140124
handleFunction(id, worldPosition, Camera.current.transform.rotation, size, EventType.Repaint);
141125
Handles.matrix = origMatrix;
142-
143-
if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
144-
Handles.color = temp;
126+
Handles.color = prevColor;
145127
break;
146128
}
147129
return position;

Editor/Mono/EditorHandles/FreeRotate.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,21 @@ internal static Quaternion Do(int id, Quaternion rotation, Vector3 position, flo
9999
}
100100
break;
101101
case EventType.Repaint:
102-
Color temp = Color.white;
102+
Handles.SetupHandleColor(id, evt, out var prevColor, out var thickness);
103103
var isHot = id == GUIUtility.hotControl;
104-
var isPreselected = id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt;
105-
106-
if (isHot)
107-
{
108-
temp = Handles.color;
109-
Handles.color = Handles.selectedColor;
110-
}
111-
else if (isPreselected)
112-
{
113-
temp = Handles.color;
114-
Handles.color = Handles.preselectionColor;
115-
}
104+
var isHover = Handles.IsHovering(id, evt);
116105

117106
// We only want the position to be affected by the Handles.matrix.
118107
Handles.matrix = Matrix4x4.identity;
119108
if (drawCircle)
120-
Handles.DrawWireDisc(worldPosition, Camera.current.transform.forward, size);
121-
if (isPreselected || isHot)
109+
Handles.DrawWireDisc(worldPosition, Camera.current.transform.forward, size, thickness);
110+
if (isHover || isHot)
122111
{
123112
Handles.color = s_DimmingColor;
124113
Handles.DrawSolidDisc(worldPosition, Camera.current.transform.forward, size);
125114
}
126115
Handles.matrix = origMatrix;
127-
128-
if (isHot || isPreselected)
129-
Handles.color = temp;
116+
Handles.color = prevColor;
130117
break;
131118
}
132119
return rotation;

Editor/Mono/EditorHandles/PositionHandle.cs

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

55
using System;
6-
using UnityEditor.Snap;
76
using UnityEngine;
87

98
namespace UnityEditor
@@ -222,6 +221,8 @@ internal static Vector3 DoPositionHandle(PositionHandleIds ids, Vector3 position
222221
static int[] s_DoPositionHandle_Internal_NextIndex = { 1, 2, 0 };
223222
static int[] s_DoPositionHandle_Internal_PrevIndex = { 2, 0, 1 };
224223
static int[] s_DoPositionHandle_Internal_PrevPlaneIndex = { 5, 3, 4 };
224+
static int[] s_DoPositionHandle_Internal_AxisDrawOrder = { 0, 1, 2 };
225+
225226
static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position, Quaternion rotation, PositionHandleParam param)
226227
{
227228
Color temp = color;
@@ -271,8 +272,11 @@ static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position
271272
}
272273

273274
// Draw axis sliders last to have priority over the planes
274-
for (var i = 0; i < 3; ++i)
275+
CalcDrawOrder(viewVectorDrawSpace, s_DoPositionHandle_Internal_AxisDrawOrder);
276+
for (var ii = 0; ii < 3; ++ii)
275277
{
278+
int i = s_DoPositionHandle_Internal_AxisDrawOrder[ii];
279+
276280
if (!param.ShouldShow(i))
277281
continue;
278282

@@ -300,7 +304,7 @@ static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position
300304

301305
if (cameraLerp <= kCameraViewThreshold)
302306
{
303-
color = Color.Lerp(color, Color.clear, cameraLerp);
307+
color = GetFadedAxisColor(color, cameraLerp, ids[i]);
304308
var axisVector = GetAxisVector(i);
305309
var dir = rotation * axisVector;
306310
var offset = dir * axisOffset[i] * size;
@@ -362,15 +366,15 @@ static Vector3 DoPlanarHandle(
362366

363367
bool isDisabled = !GUI.enabled;
364368
color = isDisabled ? staticColor : GetColorByAxis(axisNormalIndex);
365-
color = Color.Lerp(color, Color.clear, cameraLerp);
369+
color = GetFadedAxisColor(color, cameraLerp, id);
366370

367-
var updateOpacityFillColor = false;
371+
float faceOpacity = 0.8f;
368372
if (GUIUtility.hotControl == id)
369373
color = selectedColor;
370-
else if (HandleUtility.nearestControl == id && !Event.current.alt)
371-
color = preselectionColor;
374+
else if (IsHovering(id, Event.current))
375+
faceOpacity = 0.4f;
372376
else
373-
updateOpacityFillColor = true;
377+
faceOpacity = 0.1f;
374378

375379
color = ToActiveColorSpace(color);
376380

@@ -427,8 +431,7 @@ static Vector3 DoPlanarHandle(
427431
verts[1] = position + positionOffset + handleOffset + (-axis1 + axis2) * handleSize * 0.5f;
428432
verts[2] = position + positionOffset + handleOffset + (-axis1 - axis2) * handleSize * 0.5f;
429433
verts[3] = position + positionOffset + handleOffset + (axis1 - axis2) * handleSize * 0.5f;
430-
Color faceColor = updateOpacityFillColor ? new Color(color.r, color.g, color.b, 0.1f) : color;
431-
faceColor = ToActiveColorSpace(faceColor);
434+
Color faceColor = new Color(color.r, color.g, color.b, color.a * faceOpacity);
432435
Handles.DrawSolidRectangleWithOutline(verts, faceColor, Color.clear);
433436

434437
// And then render the handle itself (this is the colored outline)

0 commit comments

Comments
 (0)