新增箭头绘制功能
This commit is contained in:
parent
d95f71b5e3
commit
5c9b489242
@ -7670,7 +7670,7 @@ MonoBehaviour:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 8470605304935464912}
|
||||
m_Enabled: 0
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
|
||||
m_Name:
|
||||
@ -7748,7 +7748,7 @@ MonoBehaviour:
|
||||
m_PressedTrigger: Pressed
|
||||
m_SelectedTrigger: Selected
|
||||
m_DisabledTrigger: Disabled
|
||||
m_Interactable: 0
|
||||
m_Interactable: 1
|
||||
m_TargetGraphic: {fileID: 8708082608090175244}
|
||||
toggleTransition: 1
|
||||
graphic: {fileID: 1510141012094268438}
|
||||
|
||||
@ -213,6 +213,7 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
Line,
|
||||
Rect,
|
||||
Circle,
|
||||
Arrow,
|
||||
}
|
||||
public EnterCaptureModeEvent EnterCaptureModeEvent
|
||||
{
|
||||
@ -654,6 +655,12 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
|
||||
_lastPoint = Input.mousePosition;
|
||||
break;
|
||||
case Status.Arrow:
|
||||
_currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag);
|
||||
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
|
||||
lineStart = Input.mousePosition;
|
||||
_lastPoint = lineStart;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -696,6 +703,11 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
var dis = Vector2.Distance(_lastPoint, Input.mousePosition) * 2;
|
||||
circleImg.rectTransform.sizeDelta = new Vector2(dis, dis);
|
||||
break;
|
||||
case Status.Arrow:
|
||||
Graphics.Blit(_currentLine.Texture, _currentRenderTexture);
|
||||
_paintCanvasImg.texture = _currentRenderTexture;
|
||||
ArrowFactory();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
@ -725,7 +737,8 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
break;
|
||||
|
||||
case Status.Rect:
|
||||
FinishedRaw();
|
||||
if (_currentLine != null)
|
||||
FinishedRaw();
|
||||
break;
|
||||
|
||||
case Status.Circle:
|
||||
@ -746,6 +759,13 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
}
|
||||
break;
|
||||
|
||||
case Status.Arrow:
|
||||
if (_currentLine != null)
|
||||
{
|
||||
FinishedRaw();
|
||||
lineStart = Vector2.zero;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -797,6 +817,19 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
//FinishedRaw();
|
||||
}
|
||||
}
|
||||
public void ArrowFactory()
|
||||
{
|
||||
if (lineStart != default)
|
||||
{
|
||||
var points = GenerateArrowPoints(lineStart, Input.mousePosition,0.1f);
|
||||
_lastPoint = lineStart;
|
||||
Paint(_eraserFlag, lineStart);
|
||||
LerpPaint(Input.mousePosition, _eraserFlag);
|
||||
LerpPaint(points[1], false);
|
||||
_lastPoint = Input.mousePosition;
|
||||
LerpPaint(points[3], false);
|
||||
}
|
||||
}
|
||||
|
||||
public Vector2[] GenerateRectanglePoints(Vector2 start, Vector2 thirdPoint)
|
||||
{
|
||||
@ -840,6 +873,31 @@ public class ScreenShotPainter : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Vector2[] GenerateArrowPoints(Vector2 start, Vector2 end, float arrowWidth = 0.3f, float arrowHeadLength = 0.2f)
|
||||
{
|
||||
Vector2[] points = new Vector2[4];
|
||||
|
||||
// 计算方向向量
|
||||
Vector2 direction = end - start;
|
||||
float length = direction.magnitude;
|
||||
Vector2 normalizedDir = direction.normalized;
|
||||
|
||||
// 计算箭头头部的基准点(箭头左右两侧点所在的位置)
|
||||
Vector2 arrowBase = end - normalizedDir * length * arrowHeadLength;
|
||||
|
||||
// 计算垂直于方向的向量(用于确定箭头宽度)
|
||||
Vector2 perpendicular = new Vector2(-normalizedDir.y, normalizedDir.x) * length * arrowWidth;
|
||||
|
||||
// 箭头四个点的位置
|
||||
points[0] = start; // 箭尾
|
||||
points[1] = arrowBase - perpendicular; // 箭头左侧点
|
||||
points[2] = end; // 箭头顶点
|
||||
points[3] = arrowBase + perpendicular; // 箭头右侧点
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
// 重新分配 RenderTexture
|
||||
|
||||
@ -124,6 +124,15 @@ namespace QFramework.Example
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Arrow.onValueChanged.AddListener(isOn =>
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
ScreenShotPainter.instance.SetStatus(ScreenShotPainter.Status.Arrow);
|
||||
}
|
||||
});
|
||||
|
||||
ColorAreaBtn.onClick.AddListener(() =>
|
||||
{
|
||||
ColorArea.gameObject.SetActive(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user