Skip to content

Commit 904b54f

Browse files
author
Unity Technologies
committed
Unity 2019.2.0a11 C# reference source code
1 parent 616cef5 commit 904b54f

318 files changed

Lines changed: 11001 additions & 2316 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/AnimEditor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,12 @@ static void ClutchRipple(ShortcutArguments args)
985985
ExecuteShortcut(args, animEditor => { animEditor.state.rippleTimeClutch = args.stage == ShortcutStage.Begin; });
986986
}
987987

988+
[Shortcut("Animation/Frame All", typeof(AnimationWindow), KeyCode.A)]
989+
static void FrameAll(ShortcutArguments args)
990+
{
991+
ExecuteShortcut(args, animEditor => { animEditor.triggerFraming = true; });
992+
}
993+
988994
private void PlayButtonOnGUI()
989995
{
990996
EditorGUI.BeginChangeCheck();

Editor/Mono/Animation/AnimationWindow/AnimationWindowEventInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public static void OnEditAnimationEvents(AnimationWindowEvent[] awEvents)
133133
{
134134
EditorGUI.showMixedValue = !singleFunctionName;
135135
string oldFunctionName = singleFunctionName ? firstEvent.functionName : "";
136-
string functionName = EditorGUILayout.TextField(EditorGUIUtility.TrTextContent("Function"), oldFunctionName);
136+
string functionName = EditorGUILayout.TextField(EditorGUIUtility.TrTextContent("Function"), oldFunctionName).Replace(" ", "");
137137
if (functionName != oldFunctionName)
138138
{
139139
foreach (var evt in data.selectedEvents)

Editor/Mono/Animation/AnimationWindow/AnimationWindowSelectionItem.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ public List<AnimationWindowCurve> curves
219219

220220
m_CurvesCache.Add(curve);
221221

222-
if (curveBinding.type == typeof(Transform) ||
223-
curveBinding.type == typeof(RectTransform) && (curveBinding.propertyName.StartsWith("m_LocalScale") ||
224-
curveBinding.propertyName.StartsWith("m_LocalRotation") ||
225-
curveBinding.propertyName.StartsWith("localEuler")))
222+
if (AnimationWindowUtility.IsActualTransformCurve(curveBinding))
226223
{
227224
transformCurves.Add(curve);
228225
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowUtility.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,13 @@ public static bool IsTransformType(Type type)
12811281
return type == typeof(Transform) || type == typeof(RectTransform);
12821282
}
12831283

1284+
public static bool IsActualTransformCurve(EditorCurveBinding curveBinding)
1285+
{
1286+
return curveBinding.type == typeof(Transform) || curveBinding.type == typeof(RectTransform) && (curveBinding.propertyName.StartsWith("m_LocalScale") ||
1287+
curveBinding.propertyName.StartsWith("m_LocalRotation") ||
1288+
curveBinding.propertyName.StartsWith("localEuler"));
1289+
}
1290+
12841291
public static bool ForceGrouping(EditorCurveBinding binding)
12851292
{
12861293
if (binding.type == typeof(Transform))

Editor/Mono/Animation/AnimationWindow/ControlPointRenderer.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ private class RenderChunk
2525
public bool isDirty = true;
2626
}
2727

28+
private int m_RenderChunkIndex = -1;
2829
private List<RenderChunk> m_RenderChunks = new List<RenderChunk>();
2930

3031
private Texture2D m_Icon;
@@ -80,6 +81,8 @@ public void Clear()
8081

8182
renderChunk.isDirty = true;
8283
}
84+
85+
m_RenderChunkIndex = 0;
8386
}
8487

8588
public void Render()
@@ -144,12 +147,24 @@ public void AddPoint(Rect rect, Color color)
144147

145148
private RenderChunk GetRenderChunk()
146149
{
147-
RenderChunk renderChunk;
150+
RenderChunk renderChunk = null;
148151
if (m_RenderChunks.Count > 0)
149152
{
150-
renderChunk = m_RenderChunks.Last();
151-
// Dynamically create new render chunks when needed.
152-
if ((renderChunk.vertices.Count + 4) > kMaxVertices)
153+
while (m_RenderChunkIndex < m_RenderChunks.Count)
154+
{
155+
renderChunk = m_RenderChunks[m_RenderChunkIndex];
156+
// Dynamically create new render chunks when needed.
157+
if ((renderChunk.vertices.Count + 4) > kMaxVertices)
158+
{
159+
m_RenderChunkIndex++;
160+
renderChunk = null;
161+
continue;
162+
}
163+
164+
break;
165+
}
166+
167+
if (renderChunk == null)
153168
{
154169
renderChunk = CreateRenderChunk();
155170
}
@@ -176,6 +191,7 @@ private RenderChunk CreateRenderChunk()
176191
renderChunk.indices = new List<int>();
177192

178193
m_RenderChunks.Add(renderChunk);
194+
m_RenderChunkIndex = m_RenderChunks.Count - 1;
179195

180196
return renderChunk;
181197
}

Editor/Mono/Animation/AnimationWindow/CurveEditor.cs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -849,29 +849,17 @@ private void RecalculateSelectionBounds()
849849
m_SelectionBoundsAreDirty = false;
850850
}
851851

852-
// Frame all curves to be visible.
853-
public void FrameClip(bool horizontally, bool vertically)
852+
public Bounds GetClipBounds()
854853
{
855-
Bounds frameBounds = curveBounds;
856-
if (frameBounds.size == Vector3.zero)
857-
return;
858-
859-
if (horizontally)
860-
SetShownHRangeInsideMargins(frameBounds.min.x, frameBounds.max.x);
861-
if (vertically)
862-
SetShownVRangeInsideMargins(frameBounds.min.y, frameBounds.max.y);
854+
return curveBounds;
863855
}
864856

865-
// Frame selected keys to be visible.
866-
public void FrameSelected(bool horizontally, bool vertically)
857+
public Bounds GetSelectionBounds()
867858
{
868859
if (!hasSelection)
869-
{
870-
FrameClip(horizontally, vertically);
871-
return;
872-
}
860+
return GetClipBounds();
873861

874-
Bounds frameBounds = new Bounds();
862+
Bounds frameBounds;
875863

876864
// Add neighboring keys in bounds if only a single key is selected.
877865
if (selectedCurves.Count == 1)
@@ -896,6 +884,26 @@ public void FrameSelected(bool horizontally, bool vertically)
896884
// Enforce minimum size of bounds
897885
frameBounds.size = new Vector3(Mathf.Max(frameBounds.size.x, 0.1F), Mathf.Max(frameBounds.size.y, 0.1F), 0);
898886

887+
return frameBounds;
888+
}
889+
890+
// Frame all curves to be visible.
891+
public void FrameClip(bool horizontally, bool vertically)
892+
{
893+
Frame(GetClipBounds(), horizontally, vertically);
894+
}
895+
896+
// Frame selected keys to be visible.
897+
public void FrameSelected(bool horizontally, bool vertically)
898+
{
899+
Frame(GetSelectionBounds(), horizontally, vertically);
900+
}
901+
902+
public void Frame(Bounds frameBounds, bool horizontally, bool vertically)
903+
{
904+
if (frameBounds.size == Vector3.zero)
905+
return;
906+
899907
if (horizontally)
900908
SetShownHRangeInsideMargins(frameBounds.min.x, frameBounds.max.x);
901909
if (vertically)
@@ -1008,15 +1016,6 @@ public void CurveGUI()
10081016
DeleteSelectedKeys();
10091017
evt.Use();
10101018
}
1011-
1012-
// Frame All.
1013-
// Manually handle hotkey unless we decide to add it to default Unity hotkeys like
1014-
// we did for FrameSelected.
1015-
if (evt.keyCode == KeyCode.A)
1016-
{
1017-
FrameClip(true, true);
1018-
evt.Use();
1019-
}
10201019
break;
10211020

10221021
case EventType.ContextClick:
@@ -1373,6 +1372,8 @@ internal void DeleteSelectedKeys()
13731372
GUI.changed = true;
13741373
}
13751374
SelectNone();
1375+
1376+
GUIUtility.hotControl = 0;
13761377
}
13771378

13781379
private void DeleteKeys(object obj)
@@ -2025,6 +2026,9 @@ CurveSelection AddKeyAtTime(CurveWrapper cw, float time)
20252026
int keyIndex = AnimationUtility.AddInbetweenKey(cw.curve, time);
20262027
if (keyIndex >= 0)
20272028
{
2029+
CurveUtility.SetKeyModeFromContext(cw.curve, keyIndex);
2030+
AnimationUtility.UpdateTangentsFromModeSurrounding(cw.curve, keyIndex);
2031+
20282032
// Select the key
20292033
CurveSelection selectedPoint = new CurveSelection(cw.id, keyIndex);
20302034
cw.selected = CurveWrapper.SelectionMode.Selected;

Editor/Mono/Animation/AnimationWindow/CurveEditorWindow.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using UnityEngine;
77
using UnityEditor;
8+
using UnityEditor.ShortcutManagement;
89
using System.Linq;
910

1011
using TangentMode = UnityEditor.AnimationUtility.TangentMode;
@@ -286,6 +287,16 @@ public void Show(Action<AnimationCurve> onCurveChanged, CurveEditorSettings sett
286287
ShowAuxWindow();
287288
}
288289

290+
public void FrameSelected()
291+
{
292+
m_CurveEditor.FrameSelected(true, true);
293+
}
294+
295+
public void FrameClip()
296+
{
297+
m_CurveEditor.FrameClip(true, true);
298+
}
299+
289300
internal class Styles
290301
{
291302
public GUIStyle curveEditorBackground = "PopupCurveEditorBackground";
@@ -546,32 +557,6 @@ void ValidateCurveLibraryTypeAndScale()
546557
}
547558
}
548559

549-
// Polynomial curves have limitations on how they have to be authored.
550-
// Since we don't enforce the layout, we have a button that enforces the curve layout instead.
551-
/*
552-
void OptimizePolynomialCurve (Rect rect)
553-
{
554-
///@TODO: only show this when editing shuriken curves....
555-
556-
bool wasEnabled = GUI.enabled;
557-
558-
bool isValidPolynomialCurve = true;
559-
for (int i=0;i<m_CurveEditor.animationCurves.Length;i++)
560-
isValidPolynomialCurve &= AnimationUtility.IsValidPolynomialCurve(m_CurveEditor.animationCurves[i].curve);
561-
562-
GUI.enabled = !isValidPolynomialCurve;
563-
if (GUI.Button (rect, "Optimize Polynomial Curve"))
564-
{
565-
for (int i=0;i<m_CurveEditor.animationCurves.Length;i++)
566-
AnimationUtility.ConstrainToPolynomialCurve(m_CurveEditor.animationCurves[i].curve);
567-
568-
m_CurveEditor.SelectNone();
569-
SendEvent (EventCommandNames.CurveChangedCommand, true);
570-
}
571-
572-
GUI.enabled = wasEnabled;
573-
}*/
574-
575560
public void UpdateCurve()
576561
{
577562
DoUpdateCurve(false);
@@ -606,5 +591,17 @@ void SendEvent(string eventName, bool exitGUI)
606591
}
607592
GUI.changed = true;
608593
}
594+
595+
[Shortcut("Curve Editor/Frame All", typeof(CurveEditorWindow), KeyCode.A)]
596+
static void FrameClip(ShortcutArguments args)
597+
{
598+
var curveEditorWindow = (CurveEditorWindow)args.context;
599+
600+
if (EditorWindow.focusedWindow != curveEditorWindow)
601+
return;
602+
603+
curveEditorWindow.FrameClip();
604+
curveEditorWindow.Repaint();
605+
}
609606
}
610607
}

0 commit comments

Comments
 (0)