Merge remote-tracking branch 'origin/master' into AnHui_BaoShi

This commit is contained in:
李浩 2025-03-18 10:36:13 +08:00
commit 99c1d330eb
2 changed files with 88 additions and 89 deletions

View File

@ -472,12 +472,10 @@ public class ScreenShotPainter : MonoBehaviour
void OnPostRender() void OnPostRender()
{ {
Debug.LogError(" OnPostRender");
if (!enabled) if (!enabled)
return; return;
if (_drawRegionRect) if (_drawRegionRect)
{ {
Debug.LogError("111");
//如果材质球不存在 //如果材质球不存在
if (!_lineMaterial) if (!_lineMaterial)
{ {
@ -548,10 +546,6 @@ public class ScreenShotPainter : MonoBehaviour
_drawRegionRect = false; _drawRegionRect = false;
float width = _rightUpConnerPoint.x - _leftDownConnerPoint.x; float width = _rightUpConnerPoint.x - _leftDownConnerPoint.x;
float height = _rightUpConnerPoint.y - _leftDownConnerPoint.y; float height = _rightUpConnerPoint.y - _leftDownConnerPoint.y;
Debug.LogError(_leftDownConnerPoint.x.ToString("0.00"));
Debug.LogError(_leftDownConnerPoint.y.ToString("0.00"));
Debug.LogError("width:" + width);
Debug.LogError("width:" + height);
Rect rect = new Rect(_leftDownConnerPoint.x, Screen.height - _leftUpConnerPoint.y, width, height); Rect rect = new Rect(_leftDownConnerPoint.x, Screen.height - _leftUpConnerPoint.y, width, height);
@ -619,6 +613,13 @@ public class ScreenShotPainter : MonoBehaviour
public void SetStatus(Status status)
{
this.status = status;
ChangeToEraser(this.status == Status.Eraser);
}
private void OnPaintBeginDrag(BaseEventData arg0) private void OnPaintBeginDrag(BaseEventData arg0)
{ {
if (_enabled && _haveRegion) if (_enabled && _haveRegion)
@ -658,13 +659,6 @@ public class ScreenShotPainter : MonoBehaviour
} }
} }
} }
public void SetStatus(Status status)
{
this.status = status;
ChangeToEraser(this.status == Status.Eraser);
}
private void PaintDragging(BaseEventData data) private void PaintDragging(BaseEventData data)
{ {
if (_enabled && _haveRegion) if (_enabled && _haveRegion)
@ -698,53 +692,6 @@ public class ScreenShotPainter : MonoBehaviour
} }
} }
} }
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");
}
}
private void OnPaintEndDrag(BaseEventData data) private void OnPaintEndDrag(BaseEventData data)
{ {
if (_enabled && _haveRegion) if (_enabled && _haveRegion)
@ -796,6 +743,69 @@ public class ScreenShotPainter : MonoBehaviour
} }
} }
} }
public void FinishedRaw()
{
if (_currentLine != null)
{
// 保存当前纹理到 LineSegment
RenderTexture.active = _currentLine.Texture;
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
RenderTexture.active = null;
_lineStack.Push(_currentLine);
_currentLine = null;
}
_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)
{ {
List<Vector2> points = new List<Vector2>(); List<Vector2> points = new List<Vector2>();
@ -868,25 +878,18 @@ public class ScreenShotPainter : MonoBehaviour
} }
public void FinishedRaw() public void Clear()
{ {
if (_currentLine != null) // 重新分配 RenderTexture
{ _currentRenderTexture = RenderTexture.GetTemporary(_screenWidth, _screenHeight, 24);
// 保存当前纹理到 LineSegment
RenderTexture.active = _currentLine.Texture;
Graphics.Blit(_currentRenderTexture, _currentLine.Texture);
RenderTexture.active = null;
_lineStack.Push(_currentLine); // 更新画布的纹理
_paintCanvasImg.texture = _currentLine.Texture; _paintCanvasImg.texture = _currentRenderTexture;
_currentLine = null;
}
_lastPoint = Vector2.zero;
// 清空线条栈
_lineStack.Clear();
} }
public void Undo() public void Undo()
{ {
if (_lineStack.Count > 0) if (_lineStack.Count > 0)
@ -898,10 +901,13 @@ public class ScreenShotPainter : MonoBehaviour
if (_lineStack.Count > 0) if (_lineStack.Count > 0)
{ {
var previousLine = _lineStack.Peek(); var previousLine = _lineStack.Peek();
RenderTexture.active = _currentRenderTexture; //RenderTexture.active = _currentRenderTexture;
Graphics.Blit(previousLine.Texture, _currentRenderTexture); //Graphics.Blit(previousLine.Texture, _currentRenderTexture);
RenderTexture.active = null; //RenderTexture.active = null;
_currentRenderTexture = previousLine.Texture;
_paintCanvasImg.texture = previousLine.Texture; _paintCanvasImg.texture = previousLine.Texture;
} }
else else
{ {
@ -909,17 +915,7 @@ public class ScreenShotPainter : MonoBehaviour
} }
} }
} }
public void Clear()
{
// 重新分配 RenderTexture
_currentRenderTexture = RenderTexture.GetTemporary(_screenWidth, _screenHeight, 24);
// 更新画布的纹理
_paintCanvasImg.texture = _currentRenderTexture;
// 清空线条栈
_lineStack.Clear();
}
/// <summary> /// <summary>
/// 绘画进行插值 /// 绘画进行插值
/// </summary> /// </summary>
@ -967,7 +963,6 @@ public class ScreenShotPainter : MonoBehaviour
material = _paintBrushMat; material = _paintBrushMat;
} }
_commandBuffer.Blit(_currentRenderTexture, _currentRenderTexture, material); _commandBuffer.Blit(_currentRenderTexture, _currentRenderTexture, material);
Graphics.ExecuteCommandBuffer(_commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer);

View File

@ -92,7 +92,11 @@ namespace QFramework.Example
protected override void OnHide() protected override void OnHide()
{ {
mData = null; mData = null;
StringEventSystem.Global.Send(this.GetType().Name + "Hide"); // 防止后面紧接着的Action接收不到此消息 延迟0.1秒发送
ActionKit.Delay(0.1f, () =>
{
StringEventSystem.Global.Send(this.GetType().Name + "Hide");
}).StartGlobal();
} }
protected override void OnClose() protected override void OnClose()