Skip to content

Commit 13acc09

Browse files
author
Unity Technologies
committed
Unity 2018.3.0a7 C# reference source code
1 parent 109dd10 commit 13acc09

156 files changed

Lines changed: 2576 additions & 1374 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/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModule.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using UnityEngine.U2D.Interface;
1111
using UnityTexture2D = UnityEngine.Texture2D;
1212
using UnityEditor.Experimental.U2D;
13+
using UnityEditor.ShortcutManagement;
1314

1415
namespace UnityEditor
1516
{
@@ -24,22 +25,57 @@ public enum AutoSlicingMethod
2425
}
2526

2627
private bool[] m_AlphaPixelCache;
28+
SpriteFrameModuleContext m_SpriteFrameModuleContext;
2729
private const int kDefaultColliderAlphaCutoff = 254;
2830
private const float kDefaultColliderDetail = 0.25f;
2931

3032
public SpriteFrameModule(ISpriteEditor sw, IEventSystem es, IUndoSystem us, IAssetDatabase ad) :
3133
base("Sprite Editor", sw, es, us, ad)
3234
{}
3335

36+
class SpriteFrameModuleContext : IShortcutToolContext
37+
{
38+
SpriteFrameModule m_SpriteFrameModule;
39+
40+
public SpriteFrameModuleContext(SpriteFrameModule spriteFrame)
41+
{
42+
m_SpriteFrameModule = spriteFrame;
43+
}
44+
45+
public bool active
46+
{
47+
get { return true; }
48+
}
49+
public SpriteFrameModule spriteFrameModule
50+
{
51+
get { return m_SpriteFrameModule; }
52+
}
53+
}
54+
55+
[FormerlyPrefKeyAs("Sprite Editor/Trim", "#t")]
56+
[Shortcut("Sprite Editor/Trim", typeof(SpriteFrameModuleContext), "#t")]
57+
static void ShortcutTrim(ShortcutArguments args)
58+
{
59+
if (!string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()))
60+
return;
61+
var spriteFrameContext = (SpriteFrameModuleContext)args.context;
62+
spriteFrameContext.spriteFrameModule.TrimAlpha();
63+
spriteFrameContext.spriteFrameModule.spriteEditor.RequestRepaint();
64+
}
65+
3466
public override void OnModuleActivate()
3567
{
3668
base.OnModuleActivate();
3769
spriteEditor.enableMouseMoveEvent = true;
70+
m_SpriteFrameModuleContext = new SpriteFrameModuleContext(this);
71+
ShortcutIntegration.instance.contextManager.RegisterToolContext(m_SpriteFrameModuleContext);
3872
}
3973

4074
public override void OnModuleDeactivate()
4175
{
4276
base.OnModuleDeactivate();
77+
ShortcutIntegration.instance.contextManager.DeregisterToolContext(m_SpriteFrameModuleContext);
78+
4379
m_AlphaPixelCache = null;
4480
}
4581

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleView.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ private static class SpriteFrameModuleStyles
1616
public static readonly GUIContent trimButtonLabel = EditorGUIUtility.TrTextContent("Trim", "Trims selected rectangle (T)");
1717
}
1818

19-
internal static PrefKey k_SpriteEditorTrim = new PrefKey("Sprite Editor/Trim", "#t");
20-
21-
2219
// overrides for SpriteFrameModuleBase
2320
public override void DoMainGUI()
2421
{
@@ -77,8 +74,7 @@ public override void DoToolbarGUI(Rect toolbarRect)
7774
drawArea.width = skin.CalcSize(SpriteFrameModuleStyles.trimButtonLabel).x;
7875
SpriteUtilityWindow.DrawToolBarWidget(ref drawArea, ref toolbarRect, (adjustedDrawArea) =>
7976
{
80-
if (GUI.Button(adjustedDrawArea, SpriteFrameModuleStyles.trimButtonLabel, EditorStyles.toolbarButton) ||
81-
(string.IsNullOrEmpty(GUI.GetNameOfFocusedControl()) && k_SpriteEditorTrim.activated))
77+
if (GUI.Button(adjustedDrawArea, SpriteFrameModuleStyles.trimButtonLabel, EditorStyles.toolbarButton))
8278
{
8379
TrimAlpha();
8480
Repaint();

Editor/Mono/Animation/AnimationWindow/AnimEditor.cs

Lines changed: 112 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using UnityEditor;
88
using System.Collections;
99
using System.Collections.Generic;
10+
using UnityEditor.ShortcutManagement;
1011
using UnityEditorInternal;
1112
using Object = UnityEngine.Object;
1213

@@ -21,6 +22,25 @@ internal enum WrapModeFixed
2122
PingPong = (int)WrapMode.PingPong
2223
}
2324

25+
class AnimationShortcutContex : IShortcutToolContext
26+
{
27+
AnimEditor m_AnimEditor;
28+
public AnimationShortcutContex(AnimEditor animEditor)
29+
{
30+
m_AnimEditor = animEditor;
31+
}
32+
33+
public bool active
34+
{
35+
get { return !animEditor.stateDisabled && !animEditor.state.animatorIsOptimized; }
36+
}
37+
38+
public AnimEditor animEditor
39+
{
40+
get { return m_AnimEditor; }
41+
}
42+
}
43+
2444
internal class AnimEditor : ScriptableObject
2545
{
2646
// Active Animation windows
@@ -82,16 +102,7 @@ static private Color inRangeColor
82102
}
83103
}
84104

85-
internal static PrefKey kAnimationPlayToggle = new PrefKey("Animation/Play Animation", " ");
86-
internal static PrefKey kAnimationPrevFrame = new PrefKey("Animation/Previous Frame", ",");
87-
internal static PrefKey kAnimationNextFrame = new PrefKey("Animation/Next Frame", ".");
88-
internal static PrefKey kAnimationPrevKeyframe = new PrefKey("Animation/Previous Keyframe", "&,");
89-
internal static PrefKey kAnimationNextKeyframe = new PrefKey("Animation/Next Keyframe", "&.");
90-
internal static PrefKey kAnimationFirstKey = new PrefKey("Animation/First Keyframe", "#,");
91-
internal static PrefKey kAnimationLastKey = new PrefKey("Animation/Last Keyframe", "#.");
92-
internal static PrefKey kAnimationRecordKeyframeSelected = new PrefKey("Animation/Key Selected", "k");
93-
internal static PrefKey kAnimationRecordKeyframeModified = new PrefKey("Animation/Key Modified", "#k");
94-
internal static PrefKey kAnimationShowCurvesToggle = new PrefKey("Animation/Show Curves", "c");
105+
AnimationShortcutContex m_AnimationShortcutContex;
95106

96107
internal const int kSliderThickness = 15;
97108
internal const int kLayoutRowHeight = EditorGUI.kWindowToolbarHeight + 1;
@@ -223,8 +234,6 @@ public void OnAnimEditorGUI(EditorWindow parent, Rect position)
223234
OverlayOnGUI(contentLayoutRect);
224235

225236
RenderEventTooltip();
226-
227-
HandleHotKeys();
228237
}
229238
}
230239

@@ -348,7 +357,8 @@ public void OnEnable()
348357
m_CurveEditor.curvesUpdated += SaveChangedCurvesFromCurveEditor;
349358
m_CurveEditor.OnEnable();
350359

351-
EditorApplication.globalEventHandler += HandleGlobalHotkeys;
360+
m_AnimationShortcutContex = new AnimationShortcutContex(this);
361+
ShortcutIntegration.instance.contextManager.RegisterToolContext(m_AnimationShortcutContex);
352362
}
353363

354364
public void OnDisable()
@@ -365,8 +375,7 @@ public void OnDisable()
365375
m_DopeSheet.OnDisable();
366376

367377
m_State.OnDisable();
368-
369-
EditorApplication.globalEventHandler -= HandleGlobalHotkeys;
378+
ShortcutIntegration.instance.contextManager.DeregisterToolContext(m_AnimationShortcutContex);
370379
}
371380

372381
public void OnDestroy()
@@ -495,11 +504,6 @@ private void TabSelectionOnGUI()
495504
{
496505
SwitchBetweenCurvesAndDopesheet();
497506
}
498-
else if (kAnimationShowCurvesToggle.activated)
499-
{
500-
SwitchBetweenCurvesAndDopesheet();
501-
Event.current.Use();
502-
}
503507
}
504508

505509
private void HierarchyOnGUI()
@@ -723,110 +727,120 @@ private void LinkOptionsOnGUI()
723727
}
724728
}
725729

726-
private void HandleHotKeys()
730+
static void ExecuteShortcut(ShortcutArguments args, Action<AnimEditor> exp)
727731
{
728-
if (!GUI.enabled || m_State.disabled)
729-
return;
730-
731-
bool keyChanged = false;
732+
var animEditorContext = (AnimationShortcutContex)args.context;
733+
var animEditor = animEditorContext.animEditor;
732734

733-
if (kAnimationPrevKeyframe.activated)
734-
{
735-
controlInterface.GoToPreviousKeyframe();
736-
keyChanged = true;
737-
}
738-
739-
if (kAnimationNextKeyframe.activated)
740-
{
741-
controlInterface.GoToNextKeyframe();
742-
keyChanged = true;
743-
}
735+
if (EditorWindow.focusedWindow != animEditor.m_OwnerWindow)
736+
return;
744737

745-
if (kAnimationNextFrame.activated)
746-
{
747-
controlInterface.GoToNextFrame();
748-
keyChanged = true;
749-
}
738+
exp(animEditor);
750739

751-
if (kAnimationPrevFrame.activated)
752-
{
753-
controlInterface.GoToPreviousFrame();
754-
keyChanged = true;
755-
}
756-
757-
if (kAnimationFirstKey.activated)
758-
{
759-
controlInterface.GoToFirstKeyframe();
760-
keyChanged = true;
761-
}
740+
animEditor.Repaint();
741+
}
762742

763-
if (kAnimationLastKey.activated)
764-
{
765-
controlInterface.GoToLastKeyframe();
766-
keyChanged = true;
767-
}
743+
static void ExecuteShortcut(ShortcutArguments args, Action<IAnimationWindowControl> exp)
744+
{
745+
ExecuteShortcut(args, animEditor => exp(animEditor.controlInterface));
746+
}
768747

769-
if (keyChanged)
770-
{
771-
Event.current.Use();
772-
Repaint();
773-
}
748+
[FormerlyPrefKeyAs("Animation/Show Curves", "c")]
749+
[Shortcut("Animation/Show Curves", typeof(AnimationShortcutContex), "c")]
750+
static void ShowCurves(ShortcutArguments args)
751+
{
752+
ExecuteShortcut(args, animEditor => { animEditor.SwitchBetweenCurvesAndDopesheet(); });
753+
}
774754

775-
if (kAnimationPlayToggle.activated)
755+
[FormerlyPrefKeyAs("Animation/Play Animation", " ")]
756+
[Shortcut("Animation/Play Animation", typeof(AnimationShortcutContex), " ")]
757+
static void TogglePlayAnimation(ShortcutArguments args)
758+
{
759+
ExecuteShortcut(args, controlInterface =>
776760
{
777761
if (controlInterface.playing)
778762
controlInterface.StopPlayback();
779763
else
780764
controlInterface.StartPlayback();
765+
});
766+
}
781767

782-
Event.current.Use();
783-
}
768+
[FormerlyPrefKeyAs("Animation/Next Frame", ".")]
769+
[Shortcut("Animation/Next Frame", typeof(AnimationShortcutContex), ".")]
770+
static void NextFrame(ShortcutArguments args)
771+
{
772+
ExecuteShortcut(args, controlInterface => controlInterface.GoToNextFrame());
773+
}
784774

785-
if (kAnimationRecordKeyframeSelected.activated)
786-
{
787-
SaveCurveEditorKeySelection();
788-
AnimationWindowUtility.AddSelectedKeyframes(m_State, controlInterface.time);
789-
UpdateSelectedKeysToCurveEditor();
775+
[FormerlyPrefKeyAs("Animation/Previous Frame", ",")]
776+
[Shortcut("Animation/Previous Frame", typeof(AnimationShortcutContex), ",")]
777+
static void PreviousFrame(ShortcutArguments args)
778+
{
779+
ExecuteShortcut(args, controlInterface => controlInterface.GoToPreviousFrame());
780+
}
790781

791-
Event.current.Use();
792-
}
782+
[FormerlyPrefKeyAs("Animation/Previous Keyframe", "&,")]
783+
[Shortcut("Animation/Previous Keyframe", typeof(AnimationShortcutContex), "&,")]
784+
static void PreviousKeyFrame(ShortcutArguments args)
785+
{
786+
ExecuteShortcut(args, controlInterface => controlInterface.GoToPreviousKeyframe());
787+
}
793788

794-
if (kAnimationRecordKeyframeModified.activated)
795-
{
796-
SaveCurveEditorKeySelection();
797-
controlInterface.ProcessCandidates();
798-
UpdateSelectedKeysToCurveEditor();
789+
[FormerlyPrefKeyAs("Animation/Next Keyframe", "&.")]
790+
[Shortcut("Animation/Next Keyframe", typeof(AnimationShortcutContex), "&.")]
791+
static void NextKeyFrame(ShortcutArguments args)
792+
{
793+
ExecuteShortcut(args, controlInterface => controlInterface.GoToNextKeyframe());
794+
}
799795

800-
Event.current.Use();
801-
}
796+
[FormerlyPrefKeyAs("Animation/First Keyframe", "#,")]
797+
[Shortcut("Animation/First Keyframe", typeof(AnimationShortcutContex), "#,")]
798+
static void FirstKeyFrame(ShortcutArguments args)
799+
{
800+
ExecuteShortcut(args, controlInterface => controlInterface.GoToFirstKeyframe());
802801
}
803802

804-
public void HandleGlobalHotkeys()
803+
[FormerlyPrefKeyAs("Animation/Last Keyframe", "#.")]
804+
[Shortcut("Animation/Last Keyframe", typeof(AnimationShortcutContex), "#.")]
805+
static void LastKeyFrame(ShortcutArguments args)
805806
{
806-
if (!m_State.previewing)
807-
return;
807+
ExecuteShortcut(args, controlInterface => controlInterface.GoToLastKeyframe());
808+
}
809+
810+
[FormerlyPrefKeyAs("Animation/Key Selected", "k")]
811+
[Shortcut("Animation/Key Selected", typeof(AnimationShortcutContex), "k")]
812+
static void KeySelected(ShortcutArguments args)
813+
{
814+
var animEditorContext = (AnimationShortcutContex)args.context;
815+
var animEditor = animEditorContext.animEditor;
808816

809-
if (!GUI.enabled || m_State.disabled)
817+
if (!animEditor.m_State.previewing)
810818
return;
811819

812-
if (kAnimationRecordKeyframeSelected.activated)
813-
{
814-
SaveCurveEditorKeySelection();
815-
AnimationWindowUtility.AddSelectedKeyframes(m_State, controlInterface.time);
816-
controlInterface.ClearCandidates();
817-
UpdateSelectedKeysToCurveEditor();
820+
animEditor.SaveCurveEditorKeySelection();
821+
AnimationWindowUtility.AddSelectedKeyframes(animEditor.m_State, animEditor.controlInterface.time);
822+
if (!animEditor.m_OwnerWindow.hasFocus)
823+
animEditor.controlInterface.ClearCandidates();
824+
animEditor.UpdateSelectedKeysToCurveEditor();
818825

819-
Event.current.Use();
820-
}
826+
animEditor.Repaint();
827+
}
821828

822-
if (kAnimationRecordKeyframeModified.activated)
823-
{
824-
SaveCurveEditorKeySelection();
825-
controlInterface.ProcessCandidates();
826-
UpdateSelectedKeysToCurveEditor();
829+
[FormerlyPrefKeyAs("Animation/Key Modified", "#k")]
830+
[Shortcut("Animation/Key Modified", typeof(AnimationShortcutContex), "#k")]
831+
static void KeyModified(ShortcutArguments args)
832+
{
833+
var animEditorContext = (AnimationShortcutContex)args.context;
834+
var animEditor = animEditorContext.animEditor;
827835

828-
Event.current.Use();
829-
}
836+
if (!animEditor.m_State.previewing)
837+
return;
838+
839+
animEditor.SaveCurveEditorKeySelection();
840+
animEditor.controlInterface.ProcessCandidates();
841+
animEditor.UpdateSelectedKeysToCurveEditor();
842+
843+
animEditor.Repaint();
830844
}
831845

832846
private void PlayButtonOnGUI()

0 commit comments

Comments
 (0)