-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCutsceneEditor.cs
3772 lines (3235 loc) · 146 KB
/
CutsceneEditor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
using System.Linq;
using System.Collections.Generic;
using NKGSlate;
namespace Slate
{
public class CutsceneEditor : EditorWindow
{
enum EditorPlaybackState
{
Stoped,
PlayingForwards,
PlayingBackwards
}
struct GuideLine
{
public float time;
public Color color;
public GuideLine(float time, Color color)
{
this.time = time;
this.color = color;
}
}
///----------------------------------------------------------------------------------------------
public static CutsceneEditor current;
public static event System.Action OnStopInEditor;
private Cutscene _cutscene;
private int _cutsceneID;
//Layout variables
private static float LEFT_MARGIN
{
//caps for consistency. margin on the left side. The width of the group/tracks list.
get { return Prefs.trackListLeftMargin; }
set { Prefs.trackListLeftMargin = Mathf.Clamp(value, 230, 400); }
}
private const float RIGHT_MARGIN = 16; //margin on the right side
private const float TOOLBAR_HEIGHT = 20; //the height of the toolbar
private const float TOP_MARGIN = 40; //top margin AFTER the toolbar
private const float GROUP_HEIGHT = 21; //height of group headers
private const float TRACK_MARGINS = 4; //margin between tracks of same group (top/bottom)
private const float GROUP_RIGHT_MARGIN = 4; //margin at the right side of groups
private const float TRACK_RIGHT_MARGIN = 4; //margin at the right side of tracks
private const float FIRST_GROUP_TOP_MARGIN = 22; //initial top margin
private static readonly Color LIST_SELECTION_COLOR = new Color(0.5f, 0.5f, 1, 0.3f);
private static readonly Color GROUP_COLOR = new Color(0f, 0f, 0f, 0.25f);
private Color HIGHLIGHT_COLOR
{
get { return isProSkin ? new Color(0.65f, 0.65f, 1) : new Color(0.1f, 0.1f, 0.1f); }
}
private float MAGNET_SNAP_INTERVAL
{
get { return viewTime * 0.01f; }
}
//Layout Rects
private Rect topLeftRect; //for playback controls
private Rect topMiddleRect; //for time info
private Rect leftRect; //for group/track list
private Rect centerRect; //for timeline
[System.NonSerialized] private Dictionary<int, ActionClipWrapper> clipWrappers;
[System.NonSerialized] private Dictionary<ActionClip, ActionClipWrapper> clipWrappersMap;
[System.NonSerialized] private EditorPlaybackState editorPlaybackState = EditorPlaybackState.Stoped;
[System.NonSerialized] private Cutscene.WrapMode editorPlaybackWrapMode = Cutscene.WrapMode.Loop;
[System.NonSerialized] private ActionClipWrapper interactingClip;
[System.NonSerialized] private bool isMovingScrubCarret;
[System.NonSerialized] private bool isMovingEndCarret;
[System.NonSerialized] private bool isMouseButton2Down;
[System.NonSerialized] private Vector2 scrollPos;
[System.NonSerialized] private float totalHeight;
[System.NonSerialized] private CutsceneTrack pickedTrack;
[System.NonSerialized] private CutsceneGroup pickedGroup;
[System.NonSerialized] private float lastStartPlayTime;
[System.NonSerialized] private float editorPreviousTime;
[System.NonSerialized] private Vector2? multiSelectStartPos;
[System.NonSerialized] private List<ActionClipWrapper> multiSelection;
[System.NonSerialized] private Rect preMultiSelectionRetimeMinMax;
[System.NonSerialized] private int multiSelectionScaleDirection;
[System.NonSerialized] private Vector2 mousePosition;
[System.NonSerialized] private Section draggedSection;
[System.NonSerialized] private bool willRepaint;
[System.NonSerialized] private bool willDirty;
[System.NonSerialized] private bool willResample;
[System.NonSerialized] private System.Action onDoPopup;
[System.NonSerialized] private bool isResizingLeftMargin;
[System.NonSerialized] private bool isHelpButtonPressed;
[System.NonSerialized] private bool showDragDropInfo;
[System.NonSerialized] private string searchString;
[System.NonSerialized] private float[] magnetSnapTimesCache;
[System.NonSerialized] private List<GuideLine> pendingGuides;
[System.NonSerialized] private System.Action postWindowsGUI;
[System.NonSerialized] private CutsceneTrack copyTrack;
[System.NonSerialized] private float timeInfoStart;
[System.NonSerialized] private float timeInfoEnd;
[System.NonSerialized] private float timeInfoInterval;
[System.NonSerialized] private float timeInfoHighMod;
///----------------------------------------------------------------------------------------------
//The current cutscene reference
public Cutscene cutscene
{
get
{
if (_cutscene == null)
{
_cutscene = EditorUtility.InstanceIDToObject(_cutsceneID) as Cutscene;
}
return _cutscene;
}
private set
{
_cutscene = value;
if (value != null)
{
_cutsceneID = value.GetInstanceID();
}
}
}
///----------------------------------------------------------------------------------------------
//The length of the cutscene reference
public float length
{
get { return cutscene.length; }
set { cutscene.length = value; }
}
//The min view time
public float viewTimeMin
{
get { return cutscene.viewTimeMin; }
set { cutscene.viewTimeMin = value; }
}
//The max view time
public float viewTimeMax
{
get { return cutscene.viewTimeMax; }
set { cutscene.viewTimeMax = value; }
}
//The max time currently in view
public float maxTime
{
get { return Mathf.Max(viewTimeMax, length); }
}
//The "length" of the currently viewing time
public float viewTime
{
get { return viewTimeMax - viewTimeMin; }
}
///----------------------------------------------------------------------------------------------
//SHORTCUTS//
//Is Unity editor pro skin?
private static bool isProSkin
{
get { return EditorGUIUtility.isProSkin; }
}
//A white texture
private static Texture2D whiteTexture
{
get { return Slate.Styles.whiteTexture; }
}
//Is cutscene reference an asset in project?
private bool isCutsceneAsset
{
get { return cutscene != null && UnityEditor.EditorUtility.IsPersistent(cutscene); }
}
//Screen Width. Handles retina.
private static float screenWidth
{
get { return Screen.width / EditorGUIUtility.pixelsPerPoint; }
}
//Screen Height. Hanldes retina.
private static float screenHeight
{
get { return Screen.height / EditorGUIUtility.pixelsPerPoint; }
}
//The color used in scruber
private Color scruberColor
{
get { return cutscene.isActive ? Color.yellow : new Color(1, 0.3f, 0.3f); }
}
///----------------------------------------------------------------------------------------------
//UTILITIES
//Convert time to position
float TimeToPos(float time)
{
return (time - viewTimeMin) / viewTime * centerRect.width;
}
//Convert position to time
float PosToTime(float pos)
{
return (pos - LEFT_MARGIN) / centerRect.width * viewTime + viewTimeMin;
}
//Round time to nearest working snap interval
float SnapTime(float time)
{
//holding control for precision (ignore snap intervals)
if (Event.current.control)
{
return time;
}
return (Mathf.Round(time / Prefs.snapInterval) * Prefs.snapInterval);
}
//Do action safely (stop cutscene, do, resample)
void SafeDoAction(System.Action call)
{
var time = cutscene.currentTime;
Stop(true);
call();
cutscene.currentTime = time;
}
//Is directable filtered out by search string?
bool IsFilteredOutBySearch(IDirectable directable, string search)
{
if (string.IsNullOrEmpty(search))
{
return false;
}
if (string.IsNullOrEmpty(directable.name))
{
return true;
}
return !directable.name.ToLower().Contains(search.ToLower());
}
//Draw a vertical guide line at time with color
void DrawGuideLine(float time, Color color)
{
if (time >= viewTimeMin && time <= viewTimeMax)
{
var xPos = TimeToPos(time);
var guideRect = new Rect(xPos + centerRect.x - 1, centerRect.y, 2, centerRect.height);
GUI.color = color;
GUI.DrawTexture(guideRect, whiteTexture);
GUI.color = Color.white;
}
}
//Add a cursor type at rect
void AddCursorRect(Rect rect, MouseCursor type)
{
EditorGUIUtility.AddCursorRect(rect, type);
willRepaint = true;
}
//Pop action GUI calls in popup
void DoPopup(System.Action call)
{
onDoPopup = call;
}
//Cache an array of snap times for clip (clip times are excluded)
//Saved in property .magnetSnapTimesCache
void CacheMagnetSnapTimes(ActionClip clip = null)
{
var result = new List<float>();
result.Add(0);
result.Add(length);
result.Add(cutscene.currentTime);
if (cutscene.directorGroup != null)
{
result.AddRange(cutscene.directorGroup.sections.Select(s => s.time));
}
foreach (var cw in clipWrappers)
{
var action = cw.Value.action;
//exclude the target clip and only include the same group
if (clip == null || (action != clip && action.parent.parent == clip.parent.parent))
{
result.Add(action.startTime);
result.Add(action.endTime);
}
}
magnetSnapTimesCache = result.Distinct().ToArray();
}
//Find best snap time (closest)
float? MagnetSnapTime(float time, float[] snapTimes)
{
if (snapTimes == null)
{
return null;
}
var bestDistance = float.PositiveInfinity;
var bestTime = float.PositiveInfinity;
for (var i = 0; i < snapTimes.Length; i++)
{
var snapTime = snapTimes[i];
var distance = Mathf.Abs(snapTime - time);
if (distance < bestDistance)
{
bestDistance = distance;
bestTime = snapTime;
}
}
if (Mathf.Abs(bestTime - time) <= MAGNET_SNAP_INTERVAL)
{
return bestTime;
}
return null;
}
///----------------------------------------------------------------------------------------------
///Opens the editor :)
public static void ShowWindow()
{
ShowWindow(null);
}
public static void ShowWindow(Cutscene newCutscene)
{
var window = EditorWindow.GetWindow(typeof(CutsceneEditor)) as CutsceneEditor;
window.InitializeAll(newCutscene);
window.Show();
}
//...
void OnEnable()
{
Styles.Load();
#if UNITY_2018_3_OR_NEWER
UnityEditor.Experimental.SceneManagement.PrefabStage.prefabStageClosing += (stage) =>
{
if (cutscene != null && stage.IsPartOfPrefabContents(cutscene.gameObject))
{
Stop(true);
}
};
#endif
UnityEditor.SceneManagement.EditorSceneManager.sceneSaving -= OnWillSaveScene;
UnityEditor.SceneManagement.EditorSceneManager.sceneSaving += OnWillSaveScene;
#pragma warning disable 618
EditorApplication.playmodeStateChanged -= InitializeAll;
EditorApplication.playmodeStateChanged += InitializeAll;
#pragma warning restore
EditorApplication.update -= OnEditorUpdate;
EditorApplication.update += OnEditorUpdate;
#if UNITY_2019_3_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
SceneView.duringSceneGui += OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
#endif
Tools.hidden = false;
titleContent = new GUIContent("SLATE", Styles.cutsceneIconOpen);
wantsMouseMove = true;
autoRepaintOnSceneChange = true;
minSize = new Vector2(500, 250);
willRepaint = true;
showDragDropInfo = true;
pendingGuides = new List<GuideLine>();
current = this;
InitializeAll();
}
//...
void OnDisable()
{
UnityEditor.SceneManagement.EditorSceneManager.sceneSaving -= OnWillSaveScene;
#pragma warning disable 618
EditorApplication.playmodeStateChanged -= InitializeAll;
#pragma warning restore
EditorApplication.update -= OnEditorUpdate;
#if UNITY_2019_3_OR_NEWER
SceneView.duringSceneGui -= OnSceneGUI;
#else
SceneView.onSceneGUIDelegate -= OnSceneGUI;
#endif
Tools.hidden = false;
if (cutscene != null && !Application.isPlaying)
{
Stop(true);
}
current = null;
}
//Set a new view when a script is selected in Unity's tab
void OnSelectionChange()
{
if (Selection.activeGameObject != null)
{
var cut = Selection.activeGameObject.GetComponent<Cutscene>();
if (cut != null && cutscene != cut)
{
InitializeAll(cut);
}
}
}
//Before scene is saved we need to stop so that cutscene changes are reverted.
void OnWillSaveScene(UnityEngine.SceneManagement.Scene scene, string path)
{
if (cutscene != null && cutscene.currentTime > 0)
{
Stop(true);
Debug.LogWarning(
"Scene Saved while a cutscene was in preview mode. Cutscene was reverted before saving the scene along with changes it affected.");
}
}
///Initialize everything
void InitializeAll()
{
InitializeAll(cutscene);
}
void InitializeAll(Cutscene newCutscene)
{
//first stop current cut if any
if (cutscene != null)
{
if (!Application.isPlaying)
{
Stop(true);
}
}
//set the new
if (newCutscene != null)
{
cutscene = newCutscene;
CutsceneUtility.selectedObject = null;
multiSelection = null;
InitClipWrappers();
if (!Application.isPlaying)
{
Stop(true);
}
}
willRepaint = true;
}
//initialize the action clip wrappers
void InitClipWrappers()
{
if (cutscene == null)
{
return;
}
multiSelection = null;
var lastTime = cutscene.currentTime;
if (!Application.isPlaying)
{
Stop(true);
}
cutscene.Validate();
clipWrappers = new Dictionary<int, ActionClipWrapper>();
clipWrappersMap = new Dictionary<ActionClip, ActionClipWrapper>();
for (int g = 0; g < cutscene.groups.Count; g++)
{
for (int t = 0; t < cutscene.groups[g].tracks.Count; t++)
{
for (int a = 0; a < cutscene.groups[g].tracks[t].clips.Count; a++)
{
var id = UID(g, t, a);
if (clipWrappers.ContainsKey(id))
{
Debug.LogError("Collided UIDs. This should really not happen but it did!");
continue;
}
var clip = cutscene.groups[g].tracks[t].clips[a];
var wrapper = new ActionClipWrapper(clip);
clipWrappers[id] = wrapper;
clipWrappersMap[clip] = wrapper;
}
}
}
if (lastTime > 0)
{
cutscene.currentTime = lastTime;
}
}
//An integer UID out of list indeces (group, track, action clip)
int UID(int g, int t, int a)
{
var A = g.ToString("D3");
var B = t.ToString("D3");
var C = a.ToString("D4");
return int.Parse(A + B + C);
}
//Play button pressed or otherwise started
public void Play(Cutscene.WrapMode wrapMode = Cutscene.WrapMode.Loop, System.Action callback = null)
{
titleContent = new GUIContent("SLATE", Styles.cutsceneIconClose);
if (Application.isPlaying)
{
var temp = cutscene.currentTime == length ? 0 : cutscene.currentTime;
cutscene.Play(0, length, cutscene.defaultWrapMode, callback, Cutscene.PlayingDirection.Forwards);
cutscene.currentTime = temp;
return;
}
editorPlaybackWrapMode = wrapMode;
editorPlaybackState = EditorPlaybackState.PlayingForwards;
editorPreviousTime = Time.realtimeSinceStartup;
lastStartPlayTime = cutscene.currentTime;
OnStopInEditor = callback != null ? callback : OnStopInEditor;
}
//Play reverse button pressed
public void PlayReverse()
{
titleContent = new GUIContent("SLATE", Styles.cutsceneIconClose);
if (Application.isPlaying)
{
var temp = cutscene.currentTime == 0 ? length : cutscene.currentTime;
cutscene.Play(0, length, cutscene.defaultWrapMode, null, Cutscene.PlayingDirection.Backwards);
cutscene.currentTime = temp;
return;
}
editorPlaybackState = EditorPlaybackState.PlayingBackwards;
editorPreviousTime = Time.realtimeSinceStartup;
if (cutscene.currentTime == 0)
{
cutscene.currentTime = length;
lastStartPlayTime = 0;
}
else
{
lastStartPlayTime = cutscene.currentTime;
}
}
//Pause button pressed
public void Pause()
{
titleContent = new GUIContent("SLATE", Styles.cutsceneIconOpen);
if (Application.isPlaying)
{
if (cutscene.isActive)
{
cutscene.Pause();
return;
}
}
editorPlaybackState = EditorPlaybackState.Stoped;
if (OnStopInEditor != null)
{
OnStopInEditor();
OnStopInEditor = null;
}
}
//Stop button pressed or otherwise reset the scrubbing/previewing
public void Stop(bool forceRewind)
{
titleContent = new GUIContent("SLATE", Styles.cutsceneIconOpen);
if (Application.isPlaying)
{
if (cutscene.isActive)
{
cutscene.Stop();
return;
}
}
if (OnStopInEditor != null)
{
OnStopInEditor();
OnStopInEditor = null;
}
//Super important to Sample instead of setting time here, so that we rewind correct if need be. 0 rewinds.
cutscene.Sample(editorPlaybackState != EditorPlaybackState.Stoped && !forceRewind ? lastStartPlayTime : 0);
editorPlaybackState = EditorPlaybackState.Stoped;
willRepaint = true;
}
///Steps time forward to the next key time
void StepForward()
{
var keyable = CutsceneUtility.selectedObject as IKeyable;
if (keyable != null)
{
var time = keyable.animationData.GetKeyNext(keyable.RootTimeToLocalTimeUnclamped());
cutscene.currentTime = time + keyable.startTime;
return;
}
if (cutscene.currentTime == cutscene.length)
{
cutscene.currentTime = 0;
return;
}
cutscene.currentTime = cutscene.GetPointerTimes().FirstOrDefault(t => t > cutscene.currentTime + 0.01f);
}
///Steps time backwards to the previous key time
void StepBackward()
{
var keyable = CutsceneUtility.selectedObject as IKeyable;
if (keyable != null)
{
var time = keyable.animationData.GetKeyPrevious(keyable.RootTimeToLocalTimeUnclamped());
cutscene.currentTime = time + keyable.startTime;
return;
}
if (cutscene.currentTime == 0)
{
cutscene.currentTime = cutscene.length;
return;
}
cutscene.currentTime = cutscene.GetPointerTimes().LastOrDefault(t => t < cutscene.currentTime - 0.01f);
}
//Sample the cutscene
void OnEditorUpdate()
{
//if cutscene playmode active, it will sample and update itself.
if (cutscene == null || cutscene.isActive)
{
return;
}
if (EditorApplication.isCompiling)
{
Stop(true);
return;
}
var delta = (Time.realtimeSinceStartup - editorPreviousTime) * Time.timeScale;
delta *= cutscene.playbackSpeed;
editorPreviousTime = Time.realtimeSinceStartup;
//Sample at it's current time.
cutscene.Sample();
//Nothing.
if (editorPlaybackState == EditorPlaybackState.Stoped)
{
return;
}
//Playback.
if (cutscene.currentTime >= length && editorPlaybackState == EditorPlaybackState.PlayingForwards)
{
if (editorPlaybackWrapMode == Cutscene.WrapMode.Once)
{
Stop(true);
return;
}
if (editorPlaybackWrapMode == Cutscene.WrapMode.Loop)
{
cutscene.Sample(0);
cutscene.Sample(delta);
return;
}
}
if (cutscene.currentTime <= 0 && editorPlaybackState == EditorPlaybackState.PlayingBackwards)
{
Stop(true);
return;
}
cutscene.currentTime += editorPlaybackState == EditorPlaybackState.PlayingForwards ? delta : -delta;
}
//...
void OnSceneGUI(SceneView sceneView)
{
if (cutscene == null)
{
return;
}
//Shortcuts for scene gui only
var e = Event.current;
if (e.type == EventType.KeyDown)
{
if (e.keyCode == KeyCode.Space && !e.shift)
{
GUIUtility.keyboardControl = 0;
if (editorPlaybackState != EditorPlaybackState.Stoped)
{
Stop(false);
}
else
{
Play();
}
e.Use();
}
if (e.keyCode == KeyCode.Comma)
{
GUIUtility.keyboardControl = 0;
StepBackward();
e.Use();
}
if (e.keyCode == KeyCode.Period)
{
GUIUtility.keyboardControl = 0;
StepForward();
e.Use();
}
}
///Forward OnSceneGUI
if (cutscene.directables != null)
{
for (var i = 0; i < cutscene.directables.Count; i++)
{
var directable = cutscene.directables[i];
directable.SceneGUI(CutsceneUtility.selectedObject == directable);
}
}
///
///No need to show tools of cutscene object, plus handles are shown per clip when required
Tools.hidden = (Selection.activeObject == cutscene || Selection.activeGameObject == cutscene.gameObject) &&
CutsceneUtility.selectedObject != null;
///Cutscene Root info and gizmos
Handles.color = Prefs.gizmosColor;
Handles.Label(cutscene.transform.position + new Vector3(0, 0.4f, 0), "Cutscene Root");
Handles.DrawLine(cutscene.transform.position + cutscene.transform.forward,
cutscene.transform.position + cutscene.transform.forward * -1);
Handles.DrawLine(cutscene.transform.position + cutscene.transform.right,
cutscene.transform.position + cutscene.transform.right * -1);
Handles.color = Color.white;
Handles.BeginGUI();
if (cutscene.currentTime > 0 && (cutscene.currentTime < cutscene.length || !Application.isPlaying))
{
///view frame. Red = scrubbing, yellow = active in playmode
var cam = sceneView.camera;
var lineWidth = 3f;
var top = new Rect(0, 0, cam.pixelWidth, lineWidth);
var bottom = new Rect(0, cam.pixelHeight - lineWidth - 10, cam.pixelWidth, lineWidth + 10);
var left = new Rect(0, 0, lineWidth, cam.pixelHeight);
var right = new Rect(cam.pixelWidth - lineWidth, 0, lineWidth, cam.pixelHeight);
var texture = whiteTexture;
GUI.color = cutscene.isActive ? Color.green : Color.red;
GUI.DrawTexture(top, texture);
GUI.DrawTexture(bottom, texture);
GUI.DrawTexture(left, texture);
GUI.DrawTexture(right, texture);
//
//Info
GUI.color = Color.black.WithAlpha(0.7f);
if (cutscene.isActive)
{
GUI.Label(bottom, string.Format(" Active '{0}'", cutscene.name), GUIStyle.none);
}
else
{
GUI.Label(bottom,
string.Format(
" Previewing '{0}'. Non animatable changes made to actor components will be reverted.",
cutscene.name), GUIStyle.none);
}
}
GUI.color = Color.white;
Handles.EndGUI();
}
//...
void Update()
{
if (willRepaint)
{
willRepaint = false;
Repaint();
}
}
//...
void OnGUI()
{
GUI.skin.label.richText = true;
GUI.skin.label.alignment = TextAnchor.UpperLeft;
EditorStyles.label.richText = true;
EditorStyles.textField.wordWrap = true;
EditorStyles.foldout.richText = true;
var e = Event.current;
mousePosition = e.mousePosition;
current = this;
if (cutscene == null || isHelpButtonPressed)
{
ShowWelcome();
return;
}
//avoid edit when compiling
if (EditorApplication.isCompiling)
{
Stop(true);
ShowNotification(new GUIContent("Compiling\n...Please wait..."));
return;
}
//handle undo/redo shortcuts
if (e.type == EventType.ValidateCommand && e.commandName == "UndoRedoPerformed")
{
GUIUtility.hotControl = 0;
GUIUtility.keyboardControl = 0;
multiSelection = null;
cutscene.Validate();
InitClipWrappers();
e.Use();
return;
}
//prefab editing is not allowed
if (isCutsceneAsset)
{
ShowNotification(new GUIContent(
"Editing Prefab Assets is not allowed\nPlease add an instance in the scene, or open the prefab for editing"));
return;
// if ( e.isMouse || e.isKey ) {
// e.Use();
// }
}
//remove notifications quickly
if (e.type == EventType.MouseDown)
{
RemoveNotification();
}
//button 2 seems buggy
if (e.button == 2 && e.type == EventType.MouseDown)
{
isMouseButton2Down = true;
}
if (e.button == 2 && e.rawType == EventType.MouseUp)
{
isMouseButton2Down = false;
}
//Record Undo and dirty? This is an overal fallback. Certain actions register undo as well.
var doRecordUndo = e.rawType == EventType.MouseDown && (e.button == 0 || e.button == 1);
doRecordUndo |= e.type == EventType.DragPerform;
if (doRecordUndo)
{
Undo.RegisterFullObjectHierarchyUndo(cutscene.groupsRoot.gameObject, "Cutscene Change");
Undo.RecordObject(cutscene, "Cutscene Change");
willDirty = true;
}
//reorder clips lists for better UI. This is strictly a UI thing.
if (interactingClip == null && e.type == EventType.Layout)
{
foreach (var group in cutscene.groups)
{
foreach (var track in group.tracks)
{
track.clips = track.clips.OrderBy(a => a.startTime).ToList();
}
}
}
//make the layout rects
topLeftRect = new Rect(0, TOOLBAR_HEIGHT, LEFT_MARGIN, TOP_MARGIN);
topMiddleRect = new Rect(LEFT_MARGIN, TOOLBAR_HEIGHT, screenWidth - LEFT_MARGIN - RIGHT_MARGIN, TOP_MARGIN);
leftRect = new Rect(0, TOOLBAR_HEIGHT + TOP_MARGIN, LEFT_MARGIN,
screenHeight - TOOLBAR_HEIGHT - TOP_MARGIN + scrollPos.y);
centerRect = new Rect(LEFT_MARGIN, TOP_MARGIN + TOOLBAR_HEIGHT, screenWidth - LEFT_MARGIN - RIGHT_MARGIN,
screenHeight - TOOLBAR_HEIGHT - TOP_MARGIN + scrollPos.y);
//...
DoKeyboardShortcuts();
ShowPlaybackControls(topLeftRect);
ShowTimeInfo(topMiddleRect);
ShowToolbar();
DoScrubControls();
DoZoomAndPan();
//Dirty and Resample flags?
if (e.rawType == EventType.MouseUp && e.button == 0)
{
willDirty = true;
willResample = true;
}
//Timelines
var scrollRect1 = Rect.MinMaxRect(0, centerRect.yMin, screenWidth, screenHeight - 5);
var scrollRect2 = Rect.MinMaxRect(0, centerRect.yMin, screenWidth, totalHeight + 150);
scrollPos = GUI.BeginScrollView(scrollRect1, scrollPos, scrollRect2);
ShowGroupsAndTracksList(leftRect);
ShowTimeLines(centerRect);
GUI.EndScrollView();
///---
DrawGuides();
AcceptDrops();
///Final stuff...
//clean selection and hotcontrols
if (e.type == EventType.MouseDown && e.button == 0 && GUIUtility.hotControl == 0)
{
if (centerRect.Contains(mousePosition))
{
CutsceneUtility.selectedObject = null;
multiSelection = null;
}
GUIUtility.keyboardControl = 0;
showDragDropInfo = false;
}
//just some info for the user to drag/drop gameobject in editor
if (showDragDropInfo && cutscene.groups.Find(g => g.GetType() == typeof(ActorGroup)) == null)
{
var label = "Drag & Drop GameObjects or Prefabs in this window to create Actor Groups";
var size = new GUIStyle("label").CalcSize(new GUIContent(label));
var notificationRect = new Rect(0, 0, size.x, size.y);
notificationRect.center =