public void SetKeyframeValue(float value, int row, int sample) { Dopesheet.DsKeyframe keyframe = Clip.GetKeyframe(row, sample); if (keyframe == null) { keyframe = Clip.GetSelectedKeyframe(row, sample); } if (keyframe == null) { Dopesheet.DsRow dopesheetRow = Clip.Rows[row]; AddKeyframe(value, row, sample); dopesheetRow = dopesheetRow.Parent; while (dopesheetRow != null) { AddKeyframe(0, dopesheetRow.Index, sample); dopesheetRow = dopesheetRow.Parent; } } else { keyframe.Value = value; if (m_raiseCurveModified) { Clip.RaiseCurveModified(keyframe.Row.Index); } } }
private void Select(Vector2Int min, Vector2Int max) { Dopesheet.DsAnimationClip clip = Clip; int rows = clip.RowsCount; int cols = clip.ColsCount; max.x = Mathf.Min(max.x, cols - 1); min.x = Mathf.Max(min.x, 0); List <Dopesheet.DsKeyframe> selectKeyframes = new List <Dopesheet.DsKeyframe>(); for (int i = min.y; i <= max.y; i++) { for (int j = min.x; j <= max.x; j++) { if (!clip.IsSelected(i, j)) { Dopesheet.DsKeyframe kf = clip.GetKeyframe(i, j); if (kf != null) { selectKeyframes.Add(kf); } } } } clip.SelectKeyframes(selectKeyframes.ToArray()); m_renderGraphics = true; }
private void OnTimelineBeginDrag() { Select(); Dopesheet.DsAnimationClip clip = Clip; IList <Dopesheet.DsKeyframe> selectedKeyframes = clip.SelectedKeyframes; if (selectedKeyframes != null && selectedKeyframes.Count > 0) { BeginRefresh(); } List <Dopesheet.DsKeyframe> keyframesWithUnselectedChildren = new List <Dopesheet.DsKeyframe>(); for (int i = 0; i < selectedKeyframes.Count; ++i) { Dopesheet.DsKeyframe selectedKeyframe = selectedKeyframes[i]; if (HasUnselectedDescendants(selectedKeyframe)) { Dopesheet.DsKeyframe keyframe = new Dopesheet.DsKeyframe(selectedKeyframe.Row, selectedKeyframe.Col, selectedKeyframe.Value); keyframesWithUnselectedChildren.Add(keyframe); } } clip.AddKeyframes(keyframesWithUnselectedChildren.ToArray()); }
private bool HasUnselectedDescendants(Dopesheet.DsKeyframe kf) { if (kf.Row.Children != null) { for (int i = 0; i < kf.Row.Children.Count; ++i) { if (Clip.HasKeyframe(kf.Row.Children[i].Index, kf.Col)) { if (!Clip.IsSelected(kf.Row.Children[i].Index, kf.Col)) { return(true); } else { Dopesheet.DsKeyframe childKf = Clip.GetSelectedKeyframe(kf.Row.Children[i].Index, kf.Col); if (HasUnselectedDescendants(childKf)) { return(true); } } } } } return(false); }
private void OnTimelineDrag(int delta) { Dopesheet.DsAnimationClip clip = Clip; IList <Dopesheet.DsKeyframe> selectedKeyframes = clip.SelectedKeyframes; for (int i = 0; i < selectedKeyframes.Count; ++i) { Dopesheet.DsKeyframe kf = selectedKeyframes[i]; kf.Col += delta; } clip.ResizeClip(selectedKeyframes); m_renderGraphics = true; }
public void AddRow(bool isVisible, bool isNew, int parentRowIndex, float initialValue, AnimationCurve curve) { Dopesheet.DsRow row = Clip.AddRow(isVisible, parentRowIndex, initialValue, curve); row.Curve = curve; if (isNew) { Dopesheet.DsKeyframe kf0 = new Dopesheet.DsKeyframe(row, 0, initialValue); Dopesheet.DsKeyframe kf1 = new Dopesheet.DsKeyframe(row, Clip.ColsCount - 1, initialValue); Clip.AddKeyframes(kf0, kf1); row.RefreshCurve(Clip.FrameRate); } if (isVisible) { VisibleRowsCount++; } }
public void RemoveSelectedKeyframes() { BeginRefresh(); List <Dopesheet.DsKeyframe> keyframesList = Clip.SelectedKeyframes.ToList(); HashSet <int> keyframesHs = new HashSet <int>(keyframesList.Select(kf => kf.Row.Index * Clip.ColsCount + kf.Col)); List <Dopesheet.DsKeyframe> notRemovedKeyframesList = new List <Dopesheet.DsKeyframe>(); for (int i = keyframesList.Count - 1; i >= 0; --i) { Dopesheet.DsKeyframe kf = keyframesList[i]; if (kf.Row.Children != null) { for (int j = 0; j < kf.Row.Children.Count; ++j) { Dopesheet.DsRow childRow = kf.Row.Children[j]; Dopesheet.DsKeyframe childKf = Clip.GetKeyframe(childRow.Index, kf.Col); if (childKf != null && !keyframesHs.Contains(childKf.Row.Index * Clip.ColsCount + childKf.Col)) { keyframesList.RemoveAt(i); notRemovedKeyframesList.Add(kf); break; } } } } if (notRemovedKeyframesList.Count > 0) { Dopesheet.DsKeyframe topRowKeyframe = keyframesList.Where(kf => kf.Row.Index == 0).FirstOrDefault(); if (topRowKeyframe != null && !notRemovedKeyframesList.Contains(topRowKeyframe)) { notRemovedKeyframesList.Add(topRowKeyframe); keyframesList.Remove(topRowKeyframe); } Clip.UnselectKeyframes(notRemovedKeyframesList.ToArray()); } Clip.RemoveKeyframes(true, keyframesList.ToArray()); Clip.Refresh(false, true, true); RenderGraphics(); }
private void AddKeyframe(float value, int row, int sample) { if (sample < 0 || row < 0) { return; } Dopesheet.DsRow dopesheetRow = Clip.Rows[row]; Dopesheet.DsKeyframe newKeyframe = new Dopesheet.DsKeyframe(dopesheetRow, sample, value); Clip.ResizeClip(new[] { newKeyframe }); if (!Clip.HasKeyframe(row, sample)) { Clip.AddKeyframes(newKeyframe); } if (m_raiseCurveModified) { Clip.RefreshCurve(row); } m_renderGraphics = true; }
private void OnTimelineDrop() { Dopesheet.DsAnimationClip clip = Clip; Dopesheet.DsKeyframe[] selectedKeyframes = clip.SelectedKeyframes.ToArray(); Dictionary <int, Dopesheet.DsKeyframe> selectedKfDictionary = new Dictionary <int, Dopesheet.DsKeyframe>(); for (int i = 0; i < selectedKeyframes.Length; ++i) { Dopesheet.DsKeyframe keyframe = selectedKeyframes[i]; if (keyframe.Col < 0) { keyframe.Col = 0; } if (keyframe.Col >= m_pointer.ColumnsCount) { keyframe.Col = m_pointer.ColumnsCount - 1; } int key = keyframe.Row.Index * clip.ColsCount + keyframe.Col; if (!selectedKfDictionary.ContainsKey(key)) { selectedKfDictionary.Add(key, keyframe); } } clip.RemoveKeyframes(false, selectedKeyframes); clip.ClearSelectedKeyframes(); clip.AddKeyframes(selectedKfDictionary.Values.ToArray()); clip.SelectKeyframes(selectedKfDictionary.Values.ToArray()); clip.Refresh(true, true, true); m_renderGraphics = true; }