Skip to content

Commit 27ca1bd

Browse files
author
Unity Technologies
committed
Unity 2020.1.0a23 C# reference source code
1 parent fbd4f2b commit 27ca1bd

File tree

140 files changed

+6442
-1981
lines changed

Some content is hidden

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

140 files changed

+6442
-1981
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public override void OnInspectorGUI()
297297
HandlePackableListUI();
298298

299299
bool spriteAtlasPackignEnabled = (EditorSettings.spritePackerMode == SpritePackerMode.BuildTimeOnlyAtlas
300-
|| EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOnAtlas);
300+
|| EditorSettings.spritePackerMode == SpritePackerMode.AlwaysOnAtlas || EditorSettings.spritePackerMode == SpritePackerMode.SpriteAtlasV2);
301301
if (spriteAtlasPackignEnabled)
302302
{
303303
if (GUILayout.Button(styles.packButton, GUILayout.ExpandWidth(false)))

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void OnAnimEditorGUI(EditorWindow parent, Rect position)
264264
}
265265
}
266266

267-
private void MainContentOnGUI(Rect contentLayoutRect)
267+
void MainContentOnGUI(Rect contentLayoutRect)
268268
{
269269
// Bail out if the hierarchy in animator is optimized.
270270
if (m_State.animatorIsOptimized)
@@ -277,6 +277,7 @@ private void MainContentOnGUI(Rect contentLayoutRect)
277277
return;
278278
}
279279

280+
var mainAreaControlID = 0;
280281
if (m_State.disabled)
281282
{
282283
SetupWizardOnGUI(contentLayoutRect);
@@ -298,14 +299,16 @@ private void MainContentOnGUI(Rect contentLayoutRect)
298299
if (m_State.showCurveEditor)
299300
{
300301
CurveEditorOnGUI(contentLayoutRect);
302+
mainAreaControlID = m_CurveEditor.areaControlID;
301303
}
302304
else
303305
{
304306
DopeSheetOnGUI(contentLayoutRect);
307+
mainAreaControlID = m_DopeSheet.areaControlID;
305308
}
306309
}
307310

308-
HandleCopyPaste();
311+
HandleMainAreaCopyPaste(mainAreaControlID);
309312
}
310313

311314
private void OverlayEventOnGUI()
@@ -1267,34 +1270,38 @@ public void EndKeyModification()
12671270
UpdateSelectedKeysToCurveEditor();
12681271
}
12691272

1270-
private void HandleCopyPaste()
1273+
void HandleMainAreaCopyPaste(int controlID)
12711274
{
1272-
if (Event.current.type == EventType.ValidateCommand || Event.current.type == EventType.ExecuteCommand)
1275+
if (GUIUtility.keyboardControl != controlID)
1276+
return;
1277+
1278+
var evt = Event.current;
1279+
var type = evt.GetTypeForControl(controlID);
1280+
if (type != EventType.ValidateCommand && type != EventType.ExecuteCommand)
1281+
return;
1282+
1283+
if (evt.commandName == EventCommandNames.Copy)
12731284
{
1274-
switch (Event.current.commandName)
1285+
if (type == EventType.ExecuteCommand)
12751286
{
1276-
case EventCommandNames.Copy:
1277-
if (Event.current.type == EventType.ExecuteCommand)
1278-
{
1279-
if (m_State.showCurveEditor)
1280-
UpdateSelectedKeysFromCurveEditor();
1281-
m_State.CopyKeys();
1282-
}
1283-
Event.current.Use();
1284-
break;
1285-
case EventCommandNames.Paste:
1286-
if (Event.current.type == EventType.ExecuteCommand)
1287-
{
1288-
SaveCurveEditorKeySelection();
1289-
m_State.PasteKeys();
1290-
UpdateSelectedKeysToCurveEditor();
1287+
if (m_State.showCurveEditor)
1288+
UpdateSelectedKeysFromCurveEditor();
1289+
m_State.CopyKeys();
1290+
}
1291+
evt.Use();
1292+
}
1293+
else if (evt.commandName == EventCommandNames.Paste)
1294+
{
1295+
if (type == EventType.ExecuteCommand)
1296+
{
1297+
SaveCurveEditorKeySelection();
1298+
m_State.PasteKeys();
1299+
UpdateSelectedKeysToCurveEditor();
12911300

1292-
// data is scheduled for an update, bail out now to avoid using out of date data.
1293-
EditorGUIUtility.ExitGUI();
1294-
}
1295-
Event.current.Use();
1296-
break;
1301+
// data is scheduled for an update, bail out now to avoid using out of date data.
1302+
EditorGUIUtility.ExitGUI();
12971303
}
1304+
evt.Use();
12981305
}
12991306
}
13001307

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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.Collections.Generic;
7+
using System.Linq;
8+
using UnityEditor;
9+
using UnityEngine;
10+
11+
namespace UnityEditorInternal
12+
{
13+
// Classes for copy/paste support of animation window related things
14+
15+
[Serializable]
16+
internal sealed class AnimationWindowEventClipboard
17+
{
18+
public float time = 0;
19+
public string functionName = "";
20+
public string stringParam = "";
21+
public int objectParam = 0;
22+
public float floatParam = 0;
23+
public int intParam = 0;
24+
public SendMessageOptions messageOptions = SendMessageOptions.RequireReceiver;
25+
26+
public AnimationWindowEventClipboard(AnimationEvent e)
27+
{
28+
time = e.time;
29+
functionName = e.functionName;
30+
stringParam = e.stringParameter;
31+
objectParam = e.objectReferenceParameter ? e.objectReferenceParameter.GetInstanceID() : 0;
32+
floatParam = e.floatParameter;
33+
intParam = e.intParameter;
34+
messageOptions = e.messageOptions;
35+
}
36+
37+
public static AnimationEvent FromClipboard(AnimationWindowEventClipboard e)
38+
{
39+
return new AnimationEvent
40+
{
41+
time = e.time,
42+
functionName = e.functionName,
43+
stringParameter = e.stringParam,
44+
objectReferenceParameter = InternalEditorUtility.GetObjectFromInstanceID(e.objectParam),
45+
floatParameter = e.floatParam,
46+
intParameter = e.intParam,
47+
messageOptions = e.messageOptions
48+
};
49+
}
50+
}
51+
52+
[Serializable]
53+
internal class AnimationWindowEventsClipboard
54+
{
55+
public AnimationWindowEventClipboard[] events;
56+
57+
internal static bool CanPaste()
58+
{
59+
return Clipboard.HasCustomValue<AnimationWindowEventsClipboard>();
60+
}
61+
62+
internal static void CopyEvents(IList<AnimationEvent> allEvents, bool[] selected, int explicitIndex = -1)
63+
{
64+
var copyEvents = new List<AnimationWindowEventClipboard>();
65+
// If a selection already exists, copy selection instead of clicked index
66+
if (Array.Exists(selected, s => s))
67+
{
68+
for (var i = 0; i < selected.Length; ++i)
69+
{
70+
if (selected[i])
71+
copyEvents.Add(new AnimationWindowEventClipboard(allEvents[i]));
72+
}
73+
}
74+
// Else, only copy the clicked animation event
75+
else if (explicitIndex >= 0)
76+
{
77+
copyEvents.Add(new AnimationWindowEventClipboard(allEvents[explicitIndex]));
78+
}
79+
var data = new AnimationWindowEventsClipboard {events = copyEvents.ToArray()};
80+
Clipboard.SetCustomValue(data);
81+
}
82+
83+
internal static AnimationEvent[] AddPastedEvents(AnimationEvent[] events, float time, out bool[] selected)
84+
{
85+
selected = null;
86+
var data = Clipboard.GetCustomValue<AnimationWindowEventsClipboard>();
87+
if (data?.events == null || data.events.Length == 0)
88+
return null;
89+
90+
var minTime = data.events.Min(e => e.time);
91+
92+
var origEventsCount = events.Length;
93+
// Append new events to the end first,
94+
var newEvents = new List<AnimationEvent>();
95+
foreach (var e in data.events)
96+
{
97+
var t = e.time - minTime + time;
98+
var newEvent = AnimationWindowEventClipboard.FromClipboard(e);
99+
newEvent.time = t;
100+
newEvents.Add(newEvent);
101+
}
102+
events = events.Concat(newEvents).ToArray();
103+
104+
// Re-sort events by time
105+
var order = new int[events.Length];
106+
for (var i = 0; i < order.Length; i++)
107+
order[i] = i;
108+
Array.Sort(events, order, new AnimationEventTimeLine.EventComparer());
109+
110+
// Mark pasted ones as selected
111+
selected = new bool[events.Length];
112+
for (var i = 0; i < order.Length; ++i)
113+
selected[i] = order[i] >= origEventsCount;
114+
115+
return events;
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)