Skip to content

Commit 034434b

Browse files
author
Unity Technologies
committed
Unity 2021.1.0a2 C# reference source code
1 parent 2652cec commit 034434b

File tree

722 files changed

+50471
-10781
lines changed

Some content is hidden

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

722 files changed

+50471
-10781
lines changed

Editor/Mono/2D/SpriteAtlas/SpriteAtlasAsset.bindings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,20 @@ public class SpriteAtlasAsset : UnityEngine.Object
4545
extern internal bool GetSecondaryColorSpace(string secondaryTextureName);
4646
extern internal void SetSecondaryColorSpace(string secondaryTextureName, bool srGB);
4747
extern internal void DeleteSecondaryPlatformSettings(string secondaryTextureName);
48+
49+
// Load SpriteAtlasAsset
50+
public static SpriteAtlasAsset Load(string assetPath)
51+
{
52+
var objs = UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget(assetPath);
53+
return (objs.Length > 0) ? objs[0] as SpriteAtlasAsset : null;
54+
}
55+
56+
public static void Save(SpriteAtlasAsset asset, string assetPath)
57+
{
58+
if (asset == null)
59+
throw new ArgumentNullException("Parameter asset is null");
60+
var objs = new UnityEngine.Object[] { asset };
61+
UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(objs, assetPath, true);
62+
}
4863
}
4964
};

Editor/Mono/2D/SpriteAtlas/SpriteAtlasImporterInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class Styles
7676
public readonly int packableElementHash = "PackableElement".GetHashCode();
7777
public readonly int packableSelectorHash = "PackableSelector".GetHashCode();
7878

79+
public readonly string swapObjectRegisterUndo = L10n.Tr("Swap Packable");
7980
public readonly string secondaryTextureNameTextControlName = "secondary_texture_name_text_field";
8081
public readonly string defaultTextForSecondaryTextureName = L10n.Tr("(Matches the names of the Secondary Textures in your Sprites.)");
8182
public readonly string nameUniquenessWarning = L10n.Tr("Secondary Texture names must be unique within a Sprite or Sprite Atlas.");
@@ -345,6 +346,7 @@ void DrawPackableElement(Rect rect, int index, bool selected, bool focused)
345346
{
346347
// Always call Remove() on the previous object if we swapping the object field item.
347348
// This ensure the Sprites was pack in this atlas will be refreshed of it unbound.
349+
Undo.RegisterCompleteObjectUndo(spriteAtlasAsset, styles.swapObjectRegisterUndo);
348350
if (previousObject != null)
349351
spriteAtlasAsset.Remove(new Object[] { previousObject });
350352
property.objectReferenceValue = changedObject;

Editor/Mono/2D/SpriteAtlas/SpriteAtlasInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Styles
7777
public readonly int packableElementHash = "PackableElement".GetHashCode();
7878
public readonly int packableSelectorHash = "PackableSelector".GetHashCode();
7979

80+
public readonly string swapObjectRegisterUndo = L10n.Tr("Swap Packable");
8081
public readonly string secondaryTextureNameTextControlName = "secondary_texture_name_text_field";
8182
public readonly string defaultTextForSecondaryTextureName = L10n.Tr("(Matches the names of the Secondary Textures in your Sprites.)");
8283
public readonly string nameUniquenessWarning = L10n.Tr("Secondary Texture names must be unique within a Sprite or Sprite Atlas.");
@@ -326,6 +327,7 @@ void DrawPackableElement(Rect rect, int index, bool selected, bool focused)
326327
{
327328
// Always call Remove() on the previous object if we swapping the object field item.
328329
// This ensure the Sprites was pack in this atlas will be refreshed of it unbound.
330+
Undo.RegisterCompleteObjectUndo(spriteAtlas, styles.swapObjectRegisterUndo);
329331
if (previousObject != null)
330332
spriteAtlas.Remove(new Object[] { previousObject });
331333
property.objectReferenceValue = changedObject;

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44

55
using System;
66
using UnityEngine;
7-
using UnityEditor;
8-
using System.Collections;
97
using System.Collections.Generic;
108
using UnityEditor.ShortcutManagement;
119
using UnityEditorInternal;
12-
using Object = UnityEngine.Object;
1310

1411
namespace UnityEditor
1512
{
@@ -1272,16 +1269,18 @@ public void EndKeyModification()
12721269

12731270
void HandleMainAreaCopyPaste(int controlID)
12741271
{
1275-
if (GUIUtility.keyboardControl != controlID)
1276-
return;
1277-
12781272
var evt = Event.current;
12791273
var type = evt.GetTypeForControl(controlID);
12801274
if (type != EventType.ValidateCommand && type != EventType.ExecuteCommand)
12811275
return;
12821276

12831277
if (evt.commandName == EventCommandNames.Copy)
12841278
{
1279+
// If events timeline has selected events right now then bail out; copying of
1280+
// these will get processed later by AnimationEventTimeLine.
1281+
if (m_Events.HasSelectedEvents)
1282+
return;
1283+
12851284
if (type == EventType.ExecuteCommand)
12861285
{
12871286
if (m_State.showCurveEditor)
@@ -1294,9 +1293,17 @@ void HandleMainAreaCopyPaste(int controlID)
12941293
{
12951294
if (type == EventType.ExecuteCommand)
12961295
{
1297-
SaveCurveEditorKeySelection();
1298-
m_State.PasteKeys();
1299-
UpdateSelectedKeysToCurveEditor();
1296+
// If clipboard contains events right now then paste those.
1297+
if (AnimationWindowEventsClipboard.CanPaste())
1298+
{
1299+
m_Events.PasteEvents(m_State.activeRootGameObject, m_State.activeAnimationClip, m_State.currentTime);
1300+
}
1301+
else
1302+
{
1303+
SaveCurveEditorKeySelection();
1304+
m_State.PasteKeys();
1305+
UpdateSelectedKeysToCurveEditor();
1306+
}
13001307

13011308
// data is scheduled for an update, bail out now to avoid using out of date data.
13021309
EditorGUIUtility.ExitGUI();

Editor/Mono/Animation/AnimationWindow/AnimationWindowClipboard.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ internal static void CopyEvents(IList<AnimationEvent> allEvents, bool[] selected
7777
copyEvents.Add(new AnimationWindowEventClipboard(allEvents[explicitIndex]));
7878
}
7979
var data = new AnimationWindowEventsClipboard {events = copyEvents.ToArray()};
80+
81+
// Animation keyframes right now do not go through regular clipboard machinery,
82+
// so when copying Events, make sure Keyframes are cleared from the clipboard, or things
83+
// get confusing.
84+
AnimationWindowState.ClearKeyframeClipboard();
85+
8086
Clipboard.SetCustomValue(data);
8187
}
8288

Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6-
using System.Reflection;
76
using System.Linq;
87
using UnityEngine;
98
using UnityEditor;
109
using System.Collections.Generic;
11-
using System.Collections;
1210
using UnityEditor.IMGUI.Controls;
1311
using Object = UnityEngine.Object;
14-
using Random = UnityEngine.Random;
1512

1613
namespace UnityEditorInternal
1714
{
@@ -1163,6 +1160,16 @@ public void TransformRippleKeys(Matrix4x4 matrix, float t1, float t2, bool flipX
11631160
EndLiveEdit();
11641161
}
11651162

1163+
internal static bool CanPasteKeys()
1164+
{
1165+
return s_KeyframeClipboard != null && s_KeyframeClipboard.Count > 0;
1166+
}
1167+
1168+
internal static void ClearKeyframeClipboard()
1169+
{
1170+
s_KeyframeClipboard?.Clear();
1171+
}
1172+
11661173
public void CopyKeys()
11671174
{
11681175
if (s_KeyframeClipboard == null)
@@ -1187,6 +1194,12 @@ public void CopyKeys()
11871194
{
11881195
CopyAllActiveCurves();
11891196
}
1197+
1198+
// Animation keyframes right now do not go through regular clipboard machinery,
1199+
// so when copying keyframes, make sure regular clipboard is cleared, or things
1200+
// get confusing.
1201+
if (s_KeyframeClipboard.Count > 0)
1202+
Clipboard.stringValue = string.Empty;
11901203
}
11911204

11921205
public void CopyAllActiveCurves()

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ internal static class Styles
3131

3232
private bool m_DirtyTooltip = false;
3333
private int m_HoverEvent = -1;
34-
// Rects used for checking mouse-move state changes
3534
private string m_InstantTooltipText = null;
3635
private Vector2 m_InstantTooltipPoint = Vector2.zero;
36+
private bool m_HasSelectedEvents;
3737

3838
public AnimationEventTimeLine(EditorWindow owner)
3939
{
@@ -72,6 +72,8 @@ public EventLineContextMenuObject(GameObject animated, AnimationClip clip, float
7272
}
7373
}
7474

75+
internal bool HasSelectedEvents => m_HasSelectedEvents;
76+
7577
public void AddEvent(float time, GameObject gameObject, AnimationClip animationClip)
7678
{
7779
AnimationWindowEvent awEvent = AnimationWindowEvent.CreateAndEdit(gameObject, animationClip, time);
@@ -142,7 +144,7 @@ void CopyEvents(AnimationClip clip, bool[] selected, int explicitIndex = -1)
142144
AnimationWindowEventsClipboard.CopyEvents(allEvents, selected, explicitIndex);
143145
}
144146

145-
void PasteEvents(GameObject animated, AnimationClip clip, float time)
147+
internal void PasteEvents(GameObject animated, AnimationClip clip, float time)
146148
{
147149
var oldEvents = AnimationUtility.GetAnimationEvents(clip);
148150
var newEvents = AnimationWindowEventsClipboard.AddPastedEvents(oldEvents, time, out var selected);
@@ -226,6 +228,7 @@ public void EventLineGUI(Rect rect, AnimationWindowState state)
226228
}
227229

228230
bool[] selectedEvents = new bool[events.Length];
231+
m_HasSelectedEvents = false;
229232

230233
Object[] selectedObjects = Selection.objects;
231234
foreach (Object selectedObject in selectedObjects)
@@ -236,6 +239,7 @@ public void EventLineGUI(Rect rect, AnimationWindowState state)
236239
if (awe.eventIndex >= 0 && awe.eventIndex < selectedEvents.Length)
237240
{
238241
selectedEvents[awe.eventIndex] = true;
242+
m_HasSelectedEvents = true;
239243
}
240244
}
241245
}

Editor/Mono/Animation/ZoomableArea.cs

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,25 @@ private void SetAllowExceed(ref float rangeEnd, ref bool allowExceed, float valu
8585
private float m_VScaleMin = kMinScale;
8686
private float m_VScaleMax = kMaxScale;
8787

88-
private const float kMinWidth = 0.05f;
88+
private float m_MinWidth = 0.05f;
8989
private const float kMinHeight = 0.05f;
9090

91+
public float minWidth
92+
{
93+
get { return m_MinWidth; }
94+
set
95+
{
96+
if (value > 0)
97+
m_MinWidth = value;
98+
else
99+
{
100+
Debug.LogWarning("Zoomable area width cannot have a value of " +
101+
"or below 0. Reverting back to a default value of 0.05f");
102+
m_MinWidth = 0.05f;
103+
}
104+
}
105+
}
106+
91107
public float hScaleMin
92108
{
93109
get { return m_HScaleMin; }
@@ -352,10 +368,10 @@ public Rect rect
352368
public void SetShownHRangeInsideMargins(float min, float max)
353369
{
354370
float widthInsideMargins = drawRect.width - leftmargin - rightmargin;
355-
if (widthInsideMargins < kMinWidth) widthInsideMargins = kMinWidth;
371+
if (widthInsideMargins < m_MinWidth) widthInsideMargins = m_MinWidth;
356372

357373
float denum = max - min;
358-
if (denum < kMinWidth) denum = kMinWidth;
374+
if (denum < m_MinWidth) denum = m_MinWidth;
359375

360376
m_Scale.x = widthInsideMargins / denum;
361377

@@ -366,7 +382,7 @@ public void SetShownHRangeInsideMargins(float min, float max)
366382
public void SetShownHRange(float min, float max)
367383
{
368384
float denum = max - min;
369-
if (denum < kMinWidth) denum = kMinWidth;
385+
if (denum < m_MinWidth) denum = m_MinWidth;
370386

371387
m_Scale.x = drawRect.width / denum;
372388

@@ -418,7 +434,7 @@ public Rect shownArea
418434
{
419435
set
420436
{
421-
float width = (value.width < kMinWidth) ? kMinWidth : value.width;
437+
float width = (value.width < m_MinWidth) ? m_MinWidth : value.width;
422438
float height = (value.height < kMinHeight) ? kMinHeight : value.height;
423439

424440
if (m_UpDirection == YDirection.Positive)
@@ -477,11 +493,11 @@ private Rect shownAreaInsideMarginsInternal
477493
{
478494
set
479495
{
480-
float width = (value.width < kMinWidth) ? kMinWidth : value.width;
496+
float width = (value.width < m_MinWidth) ? m_MinWidth : value.width;
481497
float height = (value.height < kMinHeight) ? kMinHeight : value.height;
482498

483499
float widthInsideMargins = drawRect.width - leftmargin - rightmargin;
484-
if (widthInsideMargins < kMinWidth) widthInsideMargins = kMinWidth;
500+
if (widthInsideMargins < m_MinWidth) widthInsideMargins = m_MinWidth;
485501

486502
float heightInsideMargins = drawRect.height - topmargin - bottommargin;
487503
if (heightInsideMargins < kMinHeight) heightInsideMargins = kMinHeight;
@@ -519,9 +535,9 @@ private Rect shownAreaInsideMarginsInternal
519535

520536
float GetWidthInsideMargins(float widthWithMargins, bool substractSliderWidth = false)
521537
{
522-
float width = (widthWithMargins < kMinWidth) ? kMinWidth : widthWithMargins;
538+
float width = (widthWithMargins < m_MinWidth) ? m_MinWidth : widthWithMargins;
523539
float widthInsideMargins = width - leftmargin - rightmargin - (substractSliderWidth ? (m_VSlider ? styles.visualSliderWidth : 0) : 0);
524-
return Mathf.Max(widthInsideMargins, kMinWidth);
540+
return Mathf.Max(widthInsideMargins, m_MinWidth);
525541
}
526542

527543
float GetHeightInsideMargins(float heightWithMargins, bool substractSliderHeight = false)
@@ -867,7 +883,7 @@ private void HandleZoomEvent(Vector2 zoomAround, bool scrollwhell)
867883

868884
// Cap scale when at min width to not "glide" away when zooming closer
869885
float width = shownAreaInsideMargins.width;
870-
if (width / scale <= kMinWidth)
886+
if (width / scale <= m_MinWidth)
871887
return;
872888

873889
SetScaleFocused(zoomAround, scale * m_Scale, Event.current.shift, EditorGUI.actionKey);
@@ -947,7 +963,7 @@ public void EnforceScaleAndRange()
947963
{
948964
// range only has an influence if it is enforced, i.e. not infinity
949965
float denum = hRangeMax - hRangeMin;
950-
if (denum < kMinWidth) denum = kMinWidth;
966+
if (denum < m_MinWidth) denum = m_MinWidth;
951967

952968
constrainedWidth = Mathf.Min(constrainedWidth, denum);
953969
}

Editor/Mono/Annotation/AnnotationUtility.bindings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,10 @@ internal sealed partial class AnnotationUtility
6969

7070
[StaticAccessor("GetAnnotationManager()", StaticAccessorType.Dot)]
7171
internal extern static float iconSize { get; set; }
72+
73+
[StaticAccessor("GetAnnotationManager()", StaticAccessorType.Dot)]
74+
internal extern static float fadeGizmoSize { get; set; }
75+
[StaticAccessor("GetAnnotationManager()", StaticAccessorType.Dot)]
76+
internal extern static bool fadeGizmos { get; set; }
7277
}
7378
}

0 commit comments

Comments
 (0)