Exemplo n.º 1
0
        public void StopTrackDrag()
        {
            if (_trackDragged == null)
            {
                return;
            }

            Rect trackRect = _rect;

            trackRect.yMin  += HEADER_HEIGHT;
            trackRect.height = TRACK_HEIGHT;

            int newPos = -1;

            float mouseY = Event.current.mousePosition.y;

            for (int i = 0; i != _trackEditors.Count; ++i)
            {
                if (mouseY >= trackRect.yMin && mouseY <= trackRect.yMax)
                {
                    newPos = i;
                    break;
                }

                trackRect.y += TRACK_HEIGHT;
            }

            string undoMoveTrackStr = "move Track";

            if (newPos == -1)
            {
                Undo.SetTransformParent(_trackDragged._track.transform, _timeline.transform, undoMoveTrackStr);
                _trackEditors.RemoveAt(_trackDragged.GetRuntimeObject().GetId());
                if (mouseY > trackRect.yMin)
                {
                    _trackDragged._track.transform.SetAsLastSibling();
                    _trackEditors.Add(_trackDragged);
                }
                else
                {
                    _trackDragged._track.transform.SetAsFirstSibling();
                    _trackEditors.Insert(0, _trackDragged);
                }
            }
            else
            {
                if (newPos != _trackDragged._track.GetId())
                {
                    Undo.SetTransformParent(_trackDragged._track.transform, _timeline.transform, undoMoveTrackStr);
                    _trackDragged._track.transform.SetSiblingIndex(newPos);

                    _trackEditors[_trackDragged.GetRuntimeObject().GetId()] = null;
                    _trackEditors.Insert(newPos, _trackDragged);
                    _trackEditors.Remove(null);
                }
            }

            _trackDragged = null;

            for (int i = 0; i != _trackEditors.Count; ++i)
            {
                _trackEditors[i].SetOffset(Vector2.zero, true);
            }

            _sequenceEditor.CancelTimelineDrag();
        }