From d95f71b5e3bd87952cc2cb1e7faeb69b2d74b344 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Tue, 6 May 2025 16:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=BB=E7=BA=BF=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Draw/Scripts/ScreenShotPainter.cs | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Assets/Draw/Scripts/ScreenShotPainter.cs b/Assets/Draw/Scripts/ScreenShotPainter.cs index 0e7c4921..69da6734 100644 --- a/Assets/Draw/Scripts/ScreenShotPainter.cs +++ b/Assets/Draw/Scripts/ScreenShotPainter.cs @@ -7,7 +7,6 @@ using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.Rendering; using UnityEngine.UI; -using static UnityEditor.Progress; [RequireComponent(typeof(Camera))] public class ScreenShotPainter : MonoBehaviour @@ -621,6 +620,7 @@ public class ScreenShotPainter : MonoBehaviour ChangeToEraser(this.status == Status.Eraser); } + Vector2 lineStart = Vector2.zero; private void OnPaintBeginDrag(BaseEventData arg0) { if (_enabled && _haveRegion) @@ -631,15 +631,15 @@ public class ScreenShotPainter : MonoBehaviour break; case Status.Line: - if (Input.GetMouseButton(0)) + if (_currentLine == null) { - if (_currentLine == null) - { - _currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag); - } - LerpPaint(Input.mousePosition, _eraserFlag); + _currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag); + Graphics.Blit(_currentRenderTexture, _currentLine.Texture); } + lineStart = Input.mousePosition; + _lastPoint = lineStart; + break; case Status.Circle: @@ -677,6 +677,16 @@ public class ScreenShotPainter : MonoBehaviour } LerpPaint(Input.mousePosition, _eraserFlag); break; + case Status.Line: + if (_lastPoint != default && Vector2.Distance(lineStart, Input.mousePosition) > 2f) + { + Graphics.Blit(_currentLine.Texture, _currentRenderTexture); + _paintCanvasImg.texture = _currentRenderTexture; + _lastPoint = lineStart; + Paint(_eraserFlag, lineStart); + LerpPaint(Input.mousePosition, _eraserFlag); + } + break; case Status.Rect: Graphics.Blit(_currentLine.Texture, _currentRenderTexture); _paintCanvasImg.texture = _currentRenderTexture; @@ -709,8 +719,8 @@ public class ScreenShotPainter : MonoBehaviour case Status.Line: if (_currentLine != null) { - LerpPaint(Input.mousePosition, false); FinishedRaw(); + lineStart = Vector2.zero; } break;