public FrameClipHitResult HitTest(Vector2 point) { int hitFrame = FrameUtil.PosToFrame(point.x); FrameClipHitResult result = new FrameClipHitResult() { Frame = hitFrame, ClickPos = point }; if (hitFrame < FrameCount && hitFrame >= 0) { int hitTrackIndex = Mathf.FloorToInt(point.y / ViewStyles.TrackHeight); int preTrackCount = 0; for (int i = 0; i < Asset.Tracks.Count; ++i) { var track = Asset.Tracks[i]; int hitSubIndex = hitTrackIndex - preTrackCount; if (hitSubIndex < 0) { break; } int subTrakCount = track.Foldout ? track.Count : 1; preTrackCount += subTrakCount; if (hitSubIndex >= subTrakCount) { continue; } foreach (var clipRef in track.Clips) { var clip = clipRef.Clip; if (clip.StartFrame >= hitFrame) { int endFrame = clip.StartFrame + clip.Length - 1; if (clip.Length <= 0 || endFrame >= FrameCount) { endFrame = FrameCount - 1; } if (endFrame >= hitFrame) { float frameOffset = point.x % ViewStyles.FrameWidth; if (frameOffset <= ViewStyles.ClipCtrlWidth && clip.StartFrame == hitFrame) { result.HitPart = FrameClipHitPartType.LeftCtrl; } else if (endFrame == hitFrame && (frameOffset >= (ViewStyles.FrameWidth - ViewStyles.ClipCtrlWidth))) { result.HitPart = FrameClipHitPartType.RightCtrl; } break; } } } if (result.Clip) { break; } } } return(result); }
public override void OnDrag(Vector2 pos) { int frame = FrameUtil.PosToFrame(pos.x); if (!hasModify) { if (frame != hitResult.Frame) { hasModify = true; view.RegistUndo("move clip"); } } if (hasModify) { if (hitResult.HitPart == FrameClipHitPartType.LeftCtrl) { foreach (var clipRef in view.SelectedClips) { int startFrame = clipRef.Clip.StartFrame - (frame - lastFrame); startFrame = Mathf.Clamp(startFrame, 0, view.FrameCount - 1); clipRef.Clip.StartFrame = startFrame; } } else if (hitResult.HitPart == FrameClipHitPartType.RightCtrl) { } lastFrame = frame; TrackUtil.UpdateAllTrack(view.Asset); } }