private void OnBoxSelection(Vector2Int min, Vector2Int max)
        {
            m_pointer.IsDragInProgress = false;

            Dopesheet.DsAnimationClip clip = Clip;
            int rows = clip.VisibleRowsCount;
            int cols = clip.ColsCount;

            min.y = Mathf.Clamp(min.y, 0, rows);
            //min.x = Mathf.Clamp(min.x, 0, cols - 1);
            max.y = Mathf.Clamp(max.y, 0, rows - 1);
            //max.x = Mathf.Clamp(max.x, 0, cols - 1);

            Dopesheet.DsRow minRow = clip.GetRowByVisibleIndex(min.y);
            if (minRow == null)
            {
                return;
            }
            min.y = minRow.Index;

            Dopesheet.DsRow maxRow = clip.GetRowByVisibleIndex(max.y);
            max.y = maxRow.Index;
            if (maxRow.Children != null)
            {
                max.y += maxRow.Children.Count;
            }

            Select(min, max);
        }
        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 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;
        }
        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;
        }
 private void UnselectAll()
 {
     Dopesheet.DsAnimationClip clip = Clip;
     clip.UnselectKeyframes(clip.SelectedKeyframes.ToArray());
     m_renderGraphics = true;
 }
        protected override void Awake()
        {
            base.Awake();
            if (!Application.isPlaying)
            {
                return;
            }

            if (m_textPanel == null)
            {
                m_textPanel = GetComponentInChildren <TimelineTextPanel>(true);
            }

            if (m_pointer == null)
            {
                m_pointer = GetComponentInChildren <TimelinePointer>(true);
            }

            m_scrollRect = GetComponentInChildren <ScrollRect>(true);
            m_scrollRect.scrollSensitivity = 0;
            m_scrollRect.onValueChanged.AddListener(OnInitScrollRectValueChanged);

            m_hScrollbarListener          = m_scrollRect.horizontalScrollbar.GetComponentInChildren <DragAndDropListener>(true);
            m_vScrollbarListener          = m_scrollRect.verticalScrollbar.GetComponentInChildren <DragAndDropListener>(true);
            m_hScrollbarListener.Drop    += OnHorizontalScrollbarDrop;
            m_hScrollbarListener.EndDrag += OnHorizontalScrollbarDrop;
            m_vScrollbarListener.Drop    += OnVerticalScrolbarDrop;
            m_vScrollbarListener.EndDrag += OnVerticalScrolbarDrop;

            if (FixedHeight > -1)
            {
                ScrollbarResizer[] resizers = m_scrollRect.verticalScrollbar.GetComponentsInChildren <ScrollbarResizer>(true);
                for (int i = 0; i < resizers.Length; ++i)
                {
                    resizers[i].gameObject.SetActive(false);
                }
            }

            m_rtListener = m_scrollRect.gameObject.AddComponent <RectTransformChangeListener>();
            m_rtListener.RectTransformChanged += OnRectTransformChanged;

            if (m_output == null)
            {
                m_output = m_scrollRect.content.GetComponentInChildren <RawImage>(true);
            }

            GameObject cameraGo = RenderCameraPrefab != null?Instantiate(RenderCameraPrefab) : new GameObject();

            cameraGo.name = "TimelineGraphicsCamera";
            cameraGo.SetActive(false);

#if USE_RTE
            IRTE editor = IOC.Resolve <IRTE>();
            cameraGo.transform.SetParent(editor.Root, false);
#endif
            m_camera = cameraGo.GetComponent <Camera>();
            if (m_camera == null)
            {
                m_camera = cameraGo.AddComponent <Camera>();
            }
            m_camera.enabled          = false;
            m_camera.orthographic     = true;
            m_camera.orthographicSize = 0.5f;
            m_camera.clearFlags       = CameraClearFlags.SolidColor;
            m_camera.backgroundColor  = m_backgroundColor;
            m_camera.cullingMask      = 0;

            m_rtCamera            = cameraGo.AddComponent <RenderTextureCamera>();
            m_rtCamera.Fullscreen = false;
            m_rtCamera.Output     = m_output;

            cameraGo.SetActive(true);
            m_rtCamera.enabled = false;

            if (m_timelineGridParams == null)
            {
                CreateDefaultTimelineGridParams();
                m_timelineGridParams.HorLines          = 1;
                m_timelineGridParams.HorLinesSecondary = 2;
            }

            m_timelineGrid = m_output.GetComponent <TimelineGrid>();
            if (m_timelineGrid == null)
            {
                m_timelineGrid = m_output.gameObject.AddComponent <TimelineGrid>();
            }
            m_timelineGrid.Init(m_camera);


            m_dopesheet = m_output.gameObject.GetComponent <Dopesheet>();
            if (m_dopesheet == null)
            {
                m_dopesheet = m_output.gameObject.AddComponent <Dopesheet>();
            }
            m_dopesheet.Init(m_camera);
            SetTimelineGridParameters();

            Clip = new Dopesheet.DsAnimationClip();

            m_pointer.SampleChanged += OnTimelineSampleChanged;
            m_pointer.PointerDown   += OnTimlineClick;
            m_pointer.BeginDrag     += OnTimelineBeginDrag;
            m_pointer.Drag          += OnTimelineDrag;
            m_pointer.Drop          += OnTimelineDrop;

            if (m_boxSelection == null)
            {
                m_boxSelection = GetComponentInChildren <TimelineBoxSelection>();
            }

            if (m_boxSelection != null)
            {
                m_boxSelection.BeginSelection += OnBeginBoxSelection;
                m_boxSelection.Selection      += OnBoxSelection;
            }

            RenderGraphics();
        }