// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { _painterCanvas.isErase = true; tempPainter.sourceTexture = _painterCanvas.sourceTexture; tempPainter.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); tempPainter.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); } else if (Input.GetMouseButton(0)) { tempPainter.Drawing(Input.mousePosition); _painterCanvas.Drawing(Input.mousePosition); } else if (Input.GetMouseButtonUp(0)) { tempPainter.EndDraw(); _painterCanvas.EndDraw(); tempPainter.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.One); tempPainter.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.Zero); //draw temp paint canvas to paint canvas _painterCanvas.isErase = false; _painterCanvas.ClickDraw(Camera.main.WorldToScreenPoint(tempPainter.transform.position), Camera.main, _painterCanvas.renderTexture, 1f, tempPainter.canvasMat); //clear temp canvas tempPainter.ClearCanvas(); } }
private void DoEndFingerMoveAction() { LoopPainter((RenderTexturePainter painter) => { painter.EndDraw(); }); if (_operation == Operation.Replace || _operation == Operation.ReplaceErase) { RenderTexturePainter mainPainter = _listPainter[0]; RenderTexturePainter tempPainter = _listPainter[1]; tempPainter.CanvasMat.SetFloat("_BlendSrc", (float)BlendMode.One); tempPainter.CanvasMat.SetFloat("_BlendDst", (float)BlendMode.Zero); mainPainter.IsErase = false; Camera cmain = Camera.main; mainPainter.ClickDraw(cmain.WorldToScreenPoint(tempPainter.transform.position), cmain, mainPainter.RednerTex, 1, tempPainter.CanvasMat); tempPainter.ClearCanvas(); if (_operation == Operation.ReplaceErase) { for (int i = 2; i < _listPainter.Count; i++) { RenderTexturePainter painter = _listPainter[i]; painter.IsErase = false; } } } else if (_operation == Operation.CutShape) { LoopPainter((RenderTexturePainter painter) => { painter.IsErase = !painter.IsErase; }); } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (painter && m_clickDraw) { painter.ClickDraw(Input.mousePosition, null, null, painter.brushScale); } } if (Input.GetMouseButton(0)) { if (painter) { if (!m_clickDraw) { painter.Drawing(Input.mousePosition); } } } if (Input.GetMouseButtonUp(0)) { if (painter) { painter.EndDraw(); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { if (painter && m_clickDraw) { painter.ClickDraw(Input.mousePosition); if (enableCheckComplete && checker) { checker.ClickDraw(Input.mousePosition); } } } if (Input.GetMouseButton(0)) { if (painter) { if (!m_clickDraw) { painter.Drawing(Input.mousePosition); } } if (enableCheckComplete && checker) { checker.Drawing(Input.mousePosition); } } if (Input.GetMouseButtonUp(0)) { if (painter) { painter.EndDraw(); } if (enableCheckComplete && checker) { checker.EndDraw(); } } }
void Update() { if (Input.GetMouseButtonDown(0)) { _isMouseDown = true; //Draw once when mouse down. painterCanvas.ClickDraw(Input.mousePosition, Camera.main, painterCanvas.penTex, painterCanvas.brushScale, painterCanvas.penMat, painterCanvas.renderTexture); } else if (Input.GetMouseButton(0)) { if (_isMouseDown) { //draw on mouse drag. painterCanvas.Drawing(Input.mousePosition, Camera.main); } } else if (Input.GetMouseButtonUp(0) && _isMouseDown) { painterCanvas.EndDraw(); _isMouseDown = false; } }
void Update() { if (InputUtil.CheckMouseOnUI()) { return; } //下面是两种涂法,两种都可以使用,只是有一些区域 //第一种是每次都会将临时画布的结果Draw到最终画布上,效率低一些,但是涂抹过程中效果好一些,适用于要涂抹的对象透明度和区域一不样的情况 //第二种是在最后才把涂抹的结果Draw到最终画布,效率要高一些 if (isDifferent) { if (Input.GetMouseButtonDown(0)) { tempPaintCanvas.gameObject.SetActive(true); } else if (Input.GetMouseButton(0)) { paintCanvas.isErase = true; tempPaintCanvas.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); tempPaintCanvas.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); tempPaintCanvas.Drawing(Input.mousePosition); if (isDifferent) { paintCanvas.Drawing(Input.mousePosition); } tempPaintCanvas.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.One); tempPaintCanvas.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.Zero); //draw temp paint canvas to paint canvas paintCanvas.isErase = false; paintCanvas.ClickDraw(Camera.main.WorldToScreenPoint(tempPaintCanvas.transform.position), Camera.main, paintCanvas.renderTexture, 1f, tempPaintCanvas.canvasMat); //clear temp canvas tempPaintCanvas.ClearCanvas(); } else if (Input.GetMouseButtonUp(0)) { tempPaintCanvas.EndDraw(); paintCanvas.EndDraw(); tempPaintCanvas.gameObject.SetActive(false); } } else { if (Input.GetMouseButtonDown(0)) { if (isDifferent) { //主画布当前为擦除模式 paintCanvas.isErase = true; } tempPaintCanvas.gameObject.SetActive(true); tempPaintCanvas.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); tempPaintCanvas.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); } else if (Input.GetMouseButton(0)) { if (isDifferent) { paintCanvas.Drawing(Input.mousePosition); } tempPaintCanvas.Drawing(Input.mousePosition); } else if (Input.GetMouseButtonUp(0)) { paintCanvas.EndDraw(); tempPaintCanvas.EndDraw(); tempPaintCanvas.canvasMat.SetFloat("_BlendSrc", (int)UnityEngine.Rendering.BlendMode.One); tempPaintCanvas.canvasMat.SetFloat("_BlendDst", (int)UnityEngine.Rendering.BlendMode.Zero); //将tempPaintCanvas画的draw到paintCavas上 paintCanvas.isErase = false; paintCanvas.ClickDraw(Camera.main.WorldToScreenPoint(tempPaintCanvas.transform.position), Camera.main, paintCanvas.renderTexture, 1f, tempPaintCanvas.canvasMat); //清空临时画布 tempPaintCanvas.ClearCanvas(); tempPaintCanvas.gameObject.SetActive(false); } } }