diff --git a/Assets/Draw/Scripts/ScreenShotPainter.cs b/Assets/Draw/Scripts/ScreenShotPainter.cs index 4e7f297f..19cc6bc8 100644 --- a/Assets/Draw/Scripts/ScreenShotPainter.cs +++ b/Assets/Draw/Scripts/ScreenShotPainter.cs @@ -472,12 +472,10 @@ public class ScreenShotPainter : MonoBehaviour void OnPostRender() { - Debug.LogError(" OnPostRender"); if (!enabled) return; if (_drawRegionRect) { - Debug.LogError("111"); //如果材质球不存在 if (!_lineMaterial) { @@ -548,10 +546,6 @@ public class ScreenShotPainter : MonoBehaviour _drawRegionRect = false; float width = _rightUpConnerPoint.x - _leftDownConnerPoint.x; 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); @@ -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) { 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) { 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) { 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 GenerateCirclePoints(Vector2 center, float r, int numPoints = 36) { List points = new List(); @@ -868,25 +878,18 @@ public class ScreenShotPainter : MonoBehaviour } - public void FinishedRaw() + public void Clear() { - if (_currentLine != null) - { - // 保存当前纹理到 LineSegment - RenderTexture.active = _currentLine.Texture; - Graphics.Blit(_currentRenderTexture, _currentLine.Texture); - RenderTexture.active = null; + // 重新分配 RenderTexture + _currentRenderTexture = RenderTexture.GetTemporary(_screenWidth, _screenHeight, 24); - _lineStack.Push(_currentLine); - _paintCanvasImg.texture = _currentLine.Texture; - _currentLine = null; - } - - _lastPoint = Vector2.zero; + // 更新画布的纹理 + _paintCanvasImg.texture = _currentRenderTexture; + // 清空线条栈 + _lineStack.Clear(); } - public void Undo() { if (_lineStack.Count > 0) @@ -898,10 +901,13 @@ public class ScreenShotPainter : MonoBehaviour if (_lineStack.Count > 0) { var previousLine = _lineStack.Peek(); - RenderTexture.active = _currentRenderTexture; - Graphics.Blit(previousLine.Texture, _currentRenderTexture); - RenderTexture.active = null; + //RenderTexture.active = _currentRenderTexture; + //Graphics.Blit(previousLine.Texture, _currentRenderTexture); + //RenderTexture.active = null; + _currentRenderTexture = previousLine.Texture; _paintCanvasImg.texture = previousLine.Texture; + + } else { @@ -909,17 +915,7 @@ public class ScreenShotPainter : MonoBehaviour } } } - public void Clear() - { - // 重新分配 RenderTexture - _currentRenderTexture = RenderTexture.GetTemporary(_screenWidth, _screenHeight, 24); - // 更新画布的纹理 - _paintCanvasImg.texture = _currentRenderTexture; - - // 清空线条栈 - _lineStack.Clear(); - } /// /// 绘画进行插值 /// @@ -967,7 +963,6 @@ public class ScreenShotPainter : MonoBehaviour material = _paintBrushMat; } - _commandBuffer.Blit(_currentRenderTexture, _currentRenderTexture, material); Graphics.ExecuteCommandBuffer(_commandBuffer); diff --git a/Assets/Scripts/UI/UIInstruction.cs b/Assets/Scripts/UI/UIInstruction.cs index 2339eea9..955a7bbe 100644 --- a/Assets/Scripts/UI/UIInstruction.cs +++ b/Assets/Scripts/UI/UIInstruction.cs @@ -92,7 +92,11 @@ namespace QFramework.Example protected override void OnHide() { 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()