Пример #1
0
    void OnGUI()
    {
        m_isEraser = GUI.Toggle(new Rect(5, 5, 100, 40), m_isEraser, "Is Earse", "Button");
        if (lipstick && eyelash)
        {
            if (m_isEraser != lipstick.isErase)
            {
                lipstick.isErase = m_isEraser;
                eyelash.isErase  = m_isEraser;
            }
        }

        if (GUI.Button(new Rect(5, 55, 100, 40), "Clear Canvas"))
        {
            if (lipstick && eyelash)
            {
                lipstick.ClearCanvas();
                eyelash.ClearCanvas();
            }
        }

        if (lipstick && eyelash)
        {
            GUI.color = Color.white;
            GUI.Label(new Rect(5, 100, 150, 40), "Brush Scale :" + lipstick.brushScale.ToString("N2"));
            lipstick.brushScale = GUI.HorizontalSlider(new Rect(5, 120, 150, 40), lipstick.brushScale, 0.1F, 2F);
            eyelash.brushScale  = lipstick.brushScale;
        }
    }
Пример #2
0
    // 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();
        }
    }
Пример #3
0
 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;
         });
     }
 }
Пример #4
0
    void OnGUI()
    {
        if (painter)
        {
            if (GUI.Button(new Rect(10, 10, 100, 40), "Clear Canvas"))
            {
                painter.ClearCanvas();
            }
            m_isEraser = GUI.Toggle(new Rect(120, 10, 100, 40), m_isEraser, "Is Earse", "Button");
            if (m_isEraser != painter.isErase)
            {
                painter.isErase = m_isEraser;
            }
            if (!m_isColorfulLine)
            {
                m_clickDraw = GUI.Toggle(new Rect(240, 10, 100, 40), m_clickDraw, "Click Draw", "Button");
            }
            else
            {
                m_clickDraw = false;
            }
            if (!m_isColorfulLine && GUI.Button(new Rect(350, 10, 100, 40), "Random Color"))
            {
                painter.penColor = Random.ColorHSV();
            }

            GUI.color = Color.white;
            GUI.Label(new Rect(10, 60, 200, 40), "Brush Scale :" + painter.brushScale.ToString("N2"));
            painter.brushScale = GUI.HorizontalSlider(new Rect(10, 80, 200, 40), painter.brushScale, 0.1F, 5F);

            GUI.color = Color.white;
            GUI.Label(new Rect(10, 100, 200, 40), "Canvas Alpha :" + m_alpha.ToString("N2"));
            m_alpha             = GUI.HorizontalSlider(new Rect(10, 120, 200, 40), m_alpha, 0F, 1F);
            painter.canvasAlpha = m_alpha;

            if (penTexs.Length > 1 && GUI.Button(new Rect(220, 60, 110, 40), "Change PenTex"))
            {
                ++m_penTexIndex;
                if (m_penTexIndex >= penTexs.Length)
                {
                    m_penTexIndex = 0;
                }
                painter.penTex = penTexs[m_penTexIndex];
            }
            m_isColorfulLine = GUI.Toggle(new Rect(340, 60, 110, 40), m_isColorfulLine, "Is ColorfulLine", "Button");
            if (m_isColorfulLine)
            {
                painter.paintType = RenderTexturePainter.PaintType.DrawColorfulLine;
            }
            else
            {
                painter.paintType = RenderTexturePainter.PaintType.DrawLine;
            }
        }
    }
Пример #5
0
    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);
            }
        }
    }
Пример #6
0
 public void OnClickClearCanvas()
 {
     //clear the paint canvas.
     painterCanvas.ClearCanvas();
 }