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 ClipCtrlDragOperate(FrameLineView view, FrameClipHitResult hitResult) : base(view) { this.hitResult = hitResult; lastFrame = this.hitResult.Frame; }