public static void SetLockState(TrackAsset[] tracks, bool shouldLock, WindowState state = null) { if (tracks.Length == 0) { return; } foreach (var track in tracks) { if (TimelineUtility.IsLockedFromGroup(track)) { continue; } if (track as GroupTrack == null) { SetLockState(track.GetChildTracks().ToArray(), shouldLock, state); } TimelineUndo.PushUndo(track, "Lock Tracks"); track.locked = shouldLock; } if (state != null) { // find the tracks we've locked. unselect anything locked and remove recording. foreach (var track in tracks) { if (TimelineUtility.IsLockedFromGroup(track) || !track.locked) { continue; } var flattenedChildTracks = track.GetFlattenedChildTracks(); foreach (var i in track.clips) { SelectionManager.Remove(i); } state.UnarmForRecord(track); foreach (var child in flattenedChildTracks) { SelectionManager.Remove(child); state.UnarmForRecord(child); foreach (var clip in child.GetClips()) { SelectionManager.Remove(clip); } } } // no need to rebuild, just repaint (including inspectors) InspectorWindow.RepaintAllInspectors(); state.editorWindow.Repaint(); } }
float DrawRecordButton(Rect rect, WindowState state) { if (m_TrackDrawData.m_AllowsRecording) { bool isPlayerDisabled = state.editSequence.director != null && !state.editSequence.director.isActiveAndEnabled; GameObject goBinding = m_TrackDrawData.m_TrackBinding as GameObject; if (goBinding == null) { Component c = m_TrackDrawData.m_TrackBinding as Component; if (c != null) { goBinding = c.gameObject; } } bool isTrackBindingValid = goBinding != null; bool trackErrorDisableButton = !string.IsNullOrEmpty(m_TrackDrawOptions.errorText) && isTrackBindingValid && goBinding.activeInHierarchy; bool disableButton = track.lockedInHierarchy || isPlayerDisabled || trackErrorDisableButton || !isTrackBindingValid; using (new EditorGUI.DisabledScope(disableButton)) { if (IsRecording(state)) { state.editorWindow.Repaint(); float remainder = Time.realtimeSinceStartup % 1; var animatedContent = s_ArmForRecordContentOn; if (remainder < 0.22f) { animatedContent = GUIContent.none; } if (GUI.Button(rect, animatedContent, GUIStyle.none) || isPlayerDisabled || !isTrackBindingValid) { state.UnarmForRecord(track); } } else { if (GUI.Button(rect, s_ArmForRecordContentOff, GUIStyle.none)) { state.ArmForRecord(track); } } return(WindowConstants.trackHeaderButtonSize); } } if (showTrackRecordingDisabled) { using (new EditorGUI.DisabledScope(true)) GUI.Button(rect, s_ArmForRecordDisabled, GUIStyle.none); return(k_ButtonSize); } return(0.0f); }
public override bool Execute(WindowState state, TrackAsset[] tracks) { foreach (var animTrack in tracks.OfType <AnimationTrack>()) { state.UnarmForRecord(animTrack); TimelineUndo.PushUndo(animTrack, "Set Transform Offsets"); animTrack.trackOffset = trackOffset; } TimelineEditor.Refresh(RefreshReason.ContentsModified); return(true); }
float DrawRecordButton(Rect rect, WindowState state) { if (m_TrackDrawData.m_AllowsRecording) { bool isPlayerDisabled = state.editSequence.director != null && !state.editSequence.director.isActiveAndEnabled; using (new EditorGUI.DisabledScope(track.lockedInHierarchy || isPlayerDisabled || !string.IsNullOrEmpty(m_TrackDrawOptions.errorText))) { if (IsRecording(state)) { state.editorWindow.Repaint(); float remainder = Time.realtimeSinceStartup % 1; var animatedContent = s_ArmForRecordContentOn; if (remainder < 0.22f) { animatedContent = GUIContent.none; } if (GUI.Button(rect, animatedContent, GUIStyle.none) || isPlayerDisabled) { state.UnarmForRecord(track); } } else { if (GUI.Button(rect, s_ArmForRecordContentOff, GUIStyle.none)) { state.ArmForRecord(track); } } return(WindowConstants.trackHeaderButtonSize); } } if (showTrackRecordingDisabled) { using (new EditorGUI.DisabledScope(true)) GUI.Button(rect, s_ArmForRecordDisabled, GUIStyle.none); return(k_ButtonSize); } return(0.0f); }
public override void OnBuildTrackContextMenu(GenericMenu menu, TrackAsset track, WindowState state) { var animTrack = track as AnimationTrack; if (animTrack == null) { base.OnBuildTrackContextMenu(menu, track, state); return; } if (animTrack.CanConvertFromClipMode() || animTrack.CanConvertToClipMode()) { var canConvertToInfinite = animTrack.CanConvertFromClipMode(); var canConvertToClip = animTrack.CanConvertToClipMode(); if (canConvertToInfinite) { if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly) { menu.AddDisabledItem(Styles.ConvertToInfiniteClipMenuItem, false); } else { menu.AddItem(Styles.ConvertToInfiniteClipMenuItem, false, parentTrack => { animTrack.ConvertFromClipMode(state.editSequence.asset); state.Refresh(); }, track); } } if (canConvertToClip) { if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly) { menu.AddDisabledItem(Styles.ConvertToClipTrackMenuItem, false); } else { menu.AddItem(Styles.ConvertToClipTrackMenuItem, false, parentTrack => { animTrack.ConvertToClipMode(); state.Refresh(); }, track); } } } if (!track.isSubTrack) { var items = Enum.GetValues(typeof(TrackOffset)); foreach (var i in items) { var item = (TrackOffset)i; if (state.editSequence.isReadOnly) { menu.AddDisabledItem(new GUIContent(Styles.TrackOffsetMenuPrefix + TypeUtility.GetMenuItemName(item))); } else { menu.AddItem( new GUIContent(Styles.TrackOffsetMenuPrefix + TypeUtility.GetMenuItemName(item)), animTrack.trackOffset == item, () => { animTrack.trackOffset = item; state.UnarmForRecord(animTrack); state.rebuildGraph = true; } ); } } } base.OnBuildTrackContextMenu(menu, track, state); if (!track.isSubTrack) { menu.AddSeparator(string.Empty); if (track.lockedInHierarchy || TimelineWindow.instance.state.editSequence.isReadOnly) { menu.AddDisabledItem(Styles.AddOverrideTrackMenuItem, false); } else { menu.AddItem(Styles.AddOverrideTrackMenuItem, false, parentTrack => { AddSubTrack(state, typeof(AnimationTrack), "Override " + track.GetChildTracks().Count().ToString(), track); }, track); } } }