修改矩形实时显示
This commit is contained in:
parent
90976a33f2
commit
3456c16110
@ -271,81 +271,6 @@ MonoBehaviour:
|
|||||||
m_hasFontAssetChanged: 0
|
m_hasFontAssetChanged: 0
|
||||||
m_baseMaterial: {fileID: 0}
|
m_baseMaterial: {fileID: 0}
|
||||||
m_maskOffset: {x: 0, y: 0, z: 0, w: 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
|
--- !u!1 &437928408945815704
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -381,7 +306,6 @@ RectTransform:
|
|||||||
- {fileID: 7982209487117141860}
|
- {fileID: 7982209487117141860}
|
||||||
- {fileID: 8910459249382205206}
|
- {fileID: 8910459249382205206}
|
||||||
- {fileID: 2461520360039377224}
|
- {fileID: 2461520360039377224}
|
||||||
- {fileID: 7278440663883465532}
|
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
m_AnchorMin: {x: 0, y: 0}
|
m_AnchorMin: {x: 0, y: 0}
|
||||||
@ -401,7 +325,6 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ec04d319ffe11bf449631785ba9df2ca, type: 3}
|
m_Script: {fileID: 11500000, guid: ec04d319ffe11bf449631785ba9df2ca, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
mask: {fileID: 2913638650655750658}
|
|
||||||
captureBGImg: {fileID: 1613795782999759057}
|
captureBGImg: {fileID: 1613795782999759057}
|
||||||
RawImg: {fileID: 3350589312635769069}
|
RawImg: {fileID: 3350589312635769069}
|
||||||
Content: {fileID: 6174875567737795578}
|
Content: {fileID: 6174875567737795578}
|
||||||
@ -436,7 +359,9 @@ MonoBehaviour:
|
|||||||
CirCleImg: {fileID: 2203796515819680784}
|
CirCleImg: {fileID: 2203796515819680784}
|
||||||
RectImg: {fileID: 1594643944354670706}
|
RectImg: {fileID: 1594643944354670706}
|
||||||
ColorArea: {fileID: 2022575599177353385}
|
ColorArea: {fileID: 2022575599177353385}
|
||||||
|
mask: {fileID: 2913638650655750658}
|
||||||
colorPicker: {fileID: 3336535175933943458}
|
colorPicker: {fileID: 3336535175933943458}
|
||||||
|
TempDraw: {fileID: 0}
|
||||||
--- !u!1 &572013391981846340
|
--- !u!1 &572013391981846340
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -7,6 +7,7 @@ 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
|
||||||
@ -650,11 +651,8 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
break;
|
break;
|
||||||
case Status.Rect:
|
case Status.Rect:
|
||||||
_currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag);
|
_currentLine = new LineSegment(_paintBrushMat.GetColor("_Color"), _brushSize, _eraserFlag);
|
||||||
|
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
|
||||||
_lastPoint = Input.mousePosition;
|
_lastPoint = Input.mousePosition;
|
||||||
//rectImg.gameObject.SetActive(true);
|
|
||||||
// TODO: 这样会使UI位置有偏差 后续修改
|
|
||||||
//rectImg.transform.position = Input.mousePosition;
|
|
||||||
isRect = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -680,7 +678,9 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
LerpPaint(Input.mousePosition, _eraserFlag);
|
LerpPaint(Input.mousePosition, _eraserFlag);
|
||||||
break;
|
break;
|
||||||
case Status.Rect:
|
case Status.Rect:
|
||||||
|
Graphics.Blit(_currentLine.Texture, _currentRenderTexture);
|
||||||
|
_paintCanvasImg.texture = _currentRenderTexture;
|
||||||
|
RectFactory();
|
||||||
break;
|
break;
|
||||||
case Status.Circle:
|
case Status.Circle:
|
||||||
var dis = Vector2.Distance(_lastPoint, Input.mousePosition) * 2;
|
var dis = Vector2.Distance(_lastPoint, Input.mousePosition) * 2;
|
||||||
@ -710,14 +710,12 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
if (_currentLine != null)
|
if (_currentLine != null)
|
||||||
{
|
{
|
||||||
LerpPaint(Input.mousePosition, false);
|
LerpPaint(Input.mousePosition, false);
|
||||||
|
|
||||||
FinishedRaw();
|
FinishedRaw();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Status.Rect:
|
case Status.Rect:
|
||||||
isRect = false;
|
FinishedRaw();
|
||||||
RectFactory();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Status.Circle:
|
case Status.Circle:
|
||||||
@ -759,52 +757,6 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
_lastPoint = Vector2.zero;
|
_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)
|
List<Vector2> GenerateCirclePoints(Vector2 center, float r, int numPoints = 36)
|
||||||
{
|
{
|
||||||
@ -825,14 +777,14 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (_lastPoint != default)
|
if (_lastPoint != default)
|
||||||
{
|
{
|
||||||
var points = GenerateRectanglePoints(_lastPoint, Input.mousePosition);
|
var rectPoints = GenerateRectanglePoints(_lastPoint, Input.mousePosition);
|
||||||
|
|
||||||
LerpPaint(points[0], false);
|
LerpPaint(rectPoints[0], false);
|
||||||
LerpPaint(points[1], false);
|
LerpPaint(rectPoints[1], false);
|
||||||
LerpPaint(points[2], false);
|
LerpPaint(rectPoints[2], false);
|
||||||
LerpPaint(points[3], false);
|
LerpPaint(rectPoints[3], false);
|
||||||
LerpPaint(points[0], false);
|
LerpPaint(rectPoints[0], false);
|
||||||
FinishedRaw();
|
//FinishedRaw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -890,6 +842,7 @@ public class ScreenShotPainter : MonoBehaviour
|
|||||||
_lineStack.Clear();
|
_lineStack.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Undo()
|
public void Undo()
|
||||||
{
|
{
|
||||||
if (_lineStack.Count > 0)
|
if (_lineStack.Count > 0)
|
||||||
|
|||||||
@ -372,7 +372,7 @@ MonoBehaviour:
|
|||||||
m_Bits: 1
|
m_Bits: 1
|
||||||
m_VolumeTrigger: {fileID: 0}
|
m_VolumeTrigger: {fileID: 0}
|
||||||
m_VolumeFrameworkUpdateModeOption: 2
|
m_VolumeFrameworkUpdateModeOption: 2
|
||||||
m_RenderPostProcessing: 1
|
m_RenderPostProcessing: 0
|
||||||
m_Antialiasing: 0
|
m_Antialiasing: 0
|
||||||
m_AntialiasingQuality: 2
|
m_AntialiasingQuality: 2
|
||||||
m_StopNaN: 0
|
m_StopNaN: 0
|
||||||
|
|||||||
11
Assets/Scripts/UI/UIDraw.Designer.cs
generated
11
Assets/Scripts/UI/UIDraw.Designer.cs
generated
@ -5,13 +5,11 @@ using QFramework;
|
|||||||
|
|
||||||
namespace QFramework.Example
|
namespace QFramework.Example
|
||||||
{
|
{
|
||||||
// Generate Id:c3372197-dece-4bdd-8b25-56df5c08aa5f
|
// Generate Id:b01e72d6-bd06-47a4-8be3-054bae1344f3
|
||||||
public partial class UIDraw
|
public partial class UIDraw
|
||||||
{
|
{
|
||||||
public const string Name = "UIDraw";
|
public const string Name = "UIDraw";
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
public UnityEngine.UI.Button mask;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public UnityEngine.UI.RawImage captureBGImg;
|
public UnityEngine.UI.RawImage captureBGImg;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
@ -81,13 +79,16 @@ namespace QFramework.Example
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
public UnityEngine.UI.Image ColorArea;
|
public UnityEngine.UI.Image ColorArea;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
public UnityEngine.UI.Button mask;
|
||||||
|
[SerializeField]
|
||||||
public UnityEngine.UI.Image colorPicker;
|
public UnityEngine.UI.Image colorPicker;
|
||||||
|
[SerializeField]
|
||||||
|
public UnityEngine.UI.RawImage TempDraw;
|
||||||
|
|
||||||
private UIDrawData mPrivateData = null;
|
private UIDrawData mPrivateData = null;
|
||||||
|
|
||||||
protected override void ClearUIComponents()
|
protected override void ClearUIComponents()
|
||||||
{
|
{
|
||||||
mask = null;
|
|
||||||
captureBGImg = null;
|
captureBGImg = null;
|
||||||
RawImg = null;
|
RawImg = null;
|
||||||
Content = null;
|
Content = null;
|
||||||
@ -122,7 +123,9 @@ namespace QFramework.Example
|
|||||||
CirCleImg = null;
|
CirCleImg = null;
|
||||||
RectImg = null;
|
RectImg = null;
|
||||||
ColorArea = null;
|
ColorArea = null;
|
||||||
|
mask = null;
|
||||||
colorPicker = null;
|
colorPicker = null;
|
||||||
|
TempDraw = null;
|
||||||
|
|
||||||
mData = null;
|
mData = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user