优化画线逻辑

This commit is contained in:
shenjianxing 2025-05-06 16:37:47 +08:00
parent 5ca2c9ce43
commit d95f71b5e3

View File

@ -7,7 +7,6 @@ using UnityEngine.Events;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using UnityEngine.UI; using UnityEngine.UI;
using static UnityEditor.Progress;
[RequireComponent(typeof(Camera))] [RequireComponent(typeof(Camera))]
public class ScreenShotPainter : MonoBehaviour public class ScreenShotPainter : MonoBehaviour
@ -621,6 +620,7 @@ public class ScreenShotPainter : MonoBehaviour
ChangeToEraser(this.status == Status.Eraser); ChangeToEraser(this.status == Status.Eraser);
} }
Vector2 lineStart = Vector2.zero;
private void OnPaintBeginDrag(BaseEventData arg0) private void OnPaintBeginDrag(BaseEventData arg0)
{ {
if (_enabled && _haveRegion) if (_enabled && _haveRegion)
@ -631,14 +631,14 @@ public class ScreenShotPainter : MonoBehaviour
break; break;
case Status.Line: case Status.Line:
if (Input.GetMouseButton(0))
{
if (_currentLine == null) if (_currentLine == null)
{ {
_currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag); _currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag);
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
} }
LerpPaint(Input.mousePosition, _eraserFlag);
} lineStart = Input.mousePosition;
_lastPoint = lineStart;
break; break;
@ -677,6 +677,16 @@ public class ScreenShotPainter : MonoBehaviour
} }
LerpPaint(Input.mousePosition, _eraserFlag); LerpPaint(Input.mousePosition, _eraserFlag);
break; 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: case Status.Rect:
Graphics.Blit(_currentLine.Texture, _currentRenderTexture); Graphics.Blit(_currentLine.Texture, _currentRenderTexture);
_paintCanvasImg.texture = _currentRenderTexture; _paintCanvasImg.texture = _currentRenderTexture;
@ -709,8 +719,8 @@ public class ScreenShotPainter : MonoBehaviour
case Status.Line: case Status.Line:
if (_currentLine != null) if (_currentLine != null)
{ {
LerpPaint(Input.mousePosition, false);
FinishedRaw(); FinishedRaw();
lineStart = Vector2.zero;
} }
break; break;