修改矩形实时显示

This commit is contained in:
shenjianxing 2025-05-06 15:05:56 +08:00
parent 90976a33f2
commit 3456c16110
4 changed files with 24 additions and 143 deletions

View File

@ -271,81 +271,6 @@ MonoBehaviour:
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!1 &412908320554838416
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7278440663883465532}
- component: {fileID: 4859354734233530742}
- component: {fileID: 8598899778490155455}
m_Layer: 0
m_Name: Temp
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &7278440663883465532
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412908320554838416}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5248266707218333243}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &4859354734233530742
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412908320554838416}
m_CullTransparentMesh: 1
--- !u!114 &8598899778490155455
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 412908320554838416}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.4117647}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 074cc869ee40c5148b26753fe02c6aec, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!1 &437928408945815704
GameObject:
m_ObjectHideFlags: 0
@ -381,7 +306,6 @@ RectTransform:
- {fileID: 7982209487117141860}
- {fileID: 8910459249382205206}
- {fileID: 2461520360039377224}
- {fileID: 7278440663883465532}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
@ -401,7 +325,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ec04d319ffe11bf449631785ba9df2ca, type: 3}
m_Name:
m_EditorClassIdentifier:
mask: {fileID: 2913638650655750658}
captureBGImg: {fileID: 1613795782999759057}
RawImg: {fileID: 3350589312635769069}
Content: {fileID: 6174875567737795578}
@ -436,7 +359,9 @@ MonoBehaviour:
CirCleImg: {fileID: 2203796515819680784}
RectImg: {fileID: 1594643944354670706}
ColorArea: {fileID: 2022575599177353385}
mask: {fileID: 2913638650655750658}
colorPicker: {fileID: 3336535175933943458}
TempDraw: {fileID: 0}
--- !u!1 &572013391981846340
GameObject:
m_ObjectHideFlags: 0

View File

@ -7,6 +7,7 @@ using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UI;
using static UnityEditor.Progress;
[RequireComponent(typeof(Camera))]
public class ScreenShotPainter : MonoBehaviour
@ -650,11 +651,8 @@ public class ScreenShotPainter : MonoBehaviour
break;
case Status.Rect:
_currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag);
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
_lastPoint = Input.mousePosition;
//rectImg.gameObject.SetActive(true);
// TODO: 这样会使UI位置有偏差 后续修改
//rectImg.transform.position = Input.mousePosition;
isRect = true;
break;
}
}
@ -680,7 +678,9 @@ public class ScreenShotPainter : MonoBehaviour
LerpPaint(Input.mousePosition, _eraserFlag);
break;
case Status.Rect:
Graphics.Blit(_currentLine.Texture, _currentRenderTexture);
_paintCanvasImg.texture = _currentRenderTexture;
RectFactory();
break;
case Status.Circle:
var dis = Vector2.Distance(_lastPoint, Input.mousePosition) * 2;
@ -710,14 +710,12 @@ public class ScreenShotPainter : MonoBehaviour
if (_currentLine != null)
{
LerpPaint(Input.mousePosition, false);
FinishedRaw();
}
break;
case Status.Rect:
isRect = false;
RectFactory();
FinishedRaw();
break;
case Status.Circle:
@ -759,52 +757,6 @@ public class ScreenShotPainter : MonoBehaviour
_lastPoint = Vector2.zero;
}
bool isRect = false;
private void OnGUI()
{
if (isRect)
{
var points = GenerateRectanglePoints(_lastPoint, Input.mousePosition);
float minX = float.MaxValue;
float minY = float.MaxValue;
float maxX = float.MinValue;
float maxY = float.MinValue;
// 找出最小和最大的 x、y 坐标
foreach (Vector2 point in points)
{
if (point.x < minX)
{
minX = point.x;
}
if (point.x > maxX)
{
maxX = point.x;
}
if (point.y < minY)
{
minY = point.y;
}
if (point.y > maxY)
{
maxY = point.y;
}
}
float x = minX;
float y = maxY;
float width = maxX - minX;
float height = maxY - minY;
Rect rect = new Rect(x, y, width, height);
GUI.backgroundColor = Color.blue;
GUI.color = Color.yellow;
GUI.Box(rect, "我帮你绘制了个 Rect Box");
}
}
List<Vector2> GenerateCirclePoints(Vector2 center, float r, int numPoints = 36)
{
@ -825,14 +777,14 @@ public class ScreenShotPainter : MonoBehaviour
{
if (_lastPoint != default)
{
var points = GenerateRectanglePoints(_lastPoint, Input.mousePosition);
var rectPoints = GenerateRectanglePoints(_lastPoint, Input.mousePosition);
LerpPaint(points[0], false);
LerpPaint(points[1], false);
LerpPaint(points[2], false);
LerpPaint(points[3], false);
LerpPaint(points[0], false);
FinishedRaw();
LerpPaint(rectPoints[0], false);
LerpPaint(rectPoints[1], false);
LerpPaint(rectPoints[2], false);
LerpPaint(rectPoints[3], false);
LerpPaint(rectPoints[0], false);
//FinishedRaw();
}
}
@ -890,6 +842,7 @@ public class ScreenShotPainter : MonoBehaviour
_lineStack.Clear();
}
public void Undo()
{
if (_lineStack.Count > 0)

View File

@ -372,7 +372,7 @@ MonoBehaviour:
m_Bits: 1
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
m_RenderPostProcessing: 0
m_Antialiasing: 0
m_AntialiasingQuality: 2
m_StopNaN: 0

View File

@ -5,13 +5,11 @@ using QFramework;
namespace QFramework.Example
{
// Generate Id:c3372197-dece-4bdd-8b25-56df5c08aa5f
// Generate Id:b01e72d6-bd06-47a4-8be3-054bae1344f3
public partial class UIDraw
{
public const string Name = "UIDraw";
[SerializeField]
public UnityEngine.UI.Button mask;
[SerializeField]
public UnityEngine.UI.RawImage captureBGImg;
[SerializeField]
@ -81,13 +79,16 @@ namespace QFramework.Example
[SerializeField]
public UnityEngine.UI.Image ColorArea;
[SerializeField]
public UnityEngine.UI.Button mask;
[SerializeField]
public UnityEngine.UI.Image colorPicker;
[SerializeField]
public UnityEngine.UI.RawImage TempDraw;
private UIDrawData mPrivateData = null;
protected override void ClearUIComponents()
{
mask = null;
captureBGImg = null;
RawImg = null;
Content = null;
@ -122,7 +123,9 @@ namespace QFramework.Example
CirCleImg = null;
RectImg = null;
ColorArea = null;
mask = null;
colorPicker = null;
TempDraw = null;
mData = null;
}