void Update()
    {
        bool flag = true;

        if (isCheckOnUGUI && InputUtil.CheckMouseOnUI())
        {
            flag = false;
        }
        if (flag && Input.touchCount < 2)
        {
            if (Input.GetMouseButtonDown(0))
            {
                m_isTouchDown = true;
                OnTouchDown();
            }
            else if (m_isTouchDown && Input.GetMouseButtonUp(0))
            {
                m_isTouchDown = false;
                OnTouchUp();
            }

            if (m_isTouchDown && Input.GetMouseButton(0))
            {
                OnTouchMove();
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!this.isActiveAndEnabled)
        {
            return;
        }
        if (Input.touchCount < 2)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (!m_isDown && !InputUtil.isOnUI)
                {
                    if (dragCheckUGUI && InputUtil.CheckMouseOnUI())
                    {
                        return;
                    }

                    RaycastHit2D[] hits = Physics2D.RaycastAll(rayCastCamera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero, 0, dragRayCastMask);
                    if (hits != null && hits.Length > 0)
                    {
                        foreach (RaycastHit2D hit in hits)
                        {
                            if (hit.collider.gameObject == gameObject)
                            {
                                m_isDown             = true;
                                m_downTime           = Time.realtimeSinceStartup;
                                m_mousePressPosition = Input.mousePosition;
                                break;
                            }
                            if (dragIgnoreTop)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else if (m_isDown && Input.GetMouseButton(0))
            {
                OnMouseDragHandler();
            }
            else if (m_isDown && Input.GetMouseButtonUp(0))
            {
                OnMouseUpHandler();
            }
        }
    }
Exemplo n.º 3
0
 // Update is called once per frame
 void Update()
 {
     if (m_isAutoMoved)
     {
         transform.localPosition = Vector3.Lerp(transform.localPosition, m_endPos, m_autoDamp * Time.deltaTime);
         if (Vector3.Distance(transform.localPosition, m_endPos) < 0.02f)
         {
             m_isAutoMoved = false;
             if (m_movedCallback != null)
             {
                 System.Action action = m_movedCallback;
                 m_movedCallback = null;
                 action();
             }
         }
     }
     else
     {
         if (Input.touchCount < 2)
         {
             if (dragEnable)
             {
                 if (Input.GetMouseButtonDown(0) && !InputUtil.CheckMouseOnUI())
                 {
                     OnTouchDown();
                 }
                 if (Input.GetMouseButton(0))
                 {
                     OnTouchMove();
                 }
                 if (Input.GetMouseButtonUp(0))
                 {
                     this.OnTouchUp();
                 }
             }
         }
         else if (multiScaleEnable && !InputUtil.CheckMouseOnUI())
         {
             m_reset = true;
             Touch   touch    = Input.touches[0];
             Touch   touch2   = Input.touches[1];
             Vector2 a        = touch.deltaPosition + touch.position;
             Vector2 b        = touch2.deltaPosition + touch2.position;
             float   sizeDiff = Vector2.Distance(a, b) / Vector2.Distance(touch.position, touch2.position);
             sizeDiff *= sizeDiff;
             Vector3 vector3 = m_viewPort.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
             FixScaleSize(sizeDiff, vector3.x, vector3.y);
         }
         if (dragEnable && (Input.GetAxis("Mouse ScrollWheel") != 0f))
         {
             float   num2    = 1f + Input.GetAxis("Mouse ScrollWheel");
             Vector3 vector4 = m_viewPort.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
             FixScaleSize(num2, vector4.x, vector4.y);
         }
         if (m_endPos.x > 0f)
         {
             m_endPos.x = 0f;
         }
         else if (m_endPos.x < ((-size.x * transform.localScale.x) + (m_viewPort.viewPort.width / transform.root.localScale.x)))
         {
             m_endPos.x = (-size.x * transform.localScale.x) + (m_viewPort.viewPort.width / transform.root.localScale.x);
         }
         if (m_endPos.y > 0f)
         {
             m_endPos.y = 0f;
         }
         else if (m_endPos.y < ((-size.y * transform.localScale.y) + (m_viewPort.viewPort.height / transform.root.localScale.y)))
         {
             m_endPos.y = (-size.y * transform.localScale.y) + (m_viewPort.viewPort.height / transform.root.localScale.y);
         }
         if (freezeY)
         {
             m_endPos.y = m_initPos.y;
         }
         if (freezeX)
         {
             m_endPos.x = m_initPos.x;
         }
         transform.localPosition = Vector3.Lerp(transform.localPosition, m_endPos, m_moveDamp);
     }
 }
Exemplo n.º 4
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);
            }
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (m_col == null || m_col.enabled == false)
        {
            return;
        }

        if (supportMultiTouch && (m_fingerId > -1 || Input.touchCount > 0))
        {
            foreach (Touch touch in Input.touches)
            {
                if (touch.phase == TouchPhase.Began && (!checkOnUGUI || !InputUtil.CheckMouseOnUI()))
                {
                    Collider2D col = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(touch.position), layerMask);
                    if (col == m_col)
                    {
                        m_fingerId       = touch.fingerId;
                        m_touchTimeDelta = Time.realtimeSinceStartup;
                        m_onDown.Invoke();
                        break;
                    }
                }
            }

            if (m_fingerId > -1)
            {
                foreach (Touch touch in Input.touches)
                {
                    if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
                    {
                        Collider2D col = Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(touch.position), layerMask);
                        if (touch.fingerId == m_fingerId)
                        {
                            m_fingerId = -1;
                            if (col == m_col && Time.realtimeSinceStartup - m_touchTimeDelta < 0.5f)
                            {
                                m_onClick.Invoke();
                            }
                            m_onUp.Invoke();
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetMouseButtonDown(0) && (!checkOnUGUI || !InputUtil.CheckMouseOnUI()))
            {
                Collider2D[] cols = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), layerMask);
                if (cols != null && cols.Length > 0 && cols[0] == m_col)
                {
                    m_isDown         = true;
                    m_touchTimeDelta = Time.realtimeSinceStartup;
                    m_onDown.Invoke();
                }
            }

            if (m_isDown && Input.GetMouseButtonUp(0))
            {
                if (Time.realtimeSinceStartup - m_touchTimeDelta < 0.5f)
                {
                    Collider2D[] cols = Physics2D.OverlapPointAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), layerMask);
                    if (cols != null && cols.Length > 0 && cols[0] == m_col)
                    {
                        m_onClick.Invoke();
                    }
                }
                m_isDown = false;
                m_onUp.Invoke();
            }
        }
    }
Exemplo n.º 6
0
 void Update()
 {
     if (_mode == Mode.DragTool)
     {
         return;
     }
     if (false == _isSelected)
     {
         return;
     }
     if (true == _isStopFingerTouch)
     {
         return;
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (true == _isCheckOnUI && true == InputUtil.CheckMouseOnUI())
         {
             return;
         }
         if (false == _isFingerMoved)
         {
             _hasStartDraw  = true;
             _mousePressPos = Input.mousePosition;
             if (_operation == Operation.DrawLine)
             {
                 LoopPainter((RenderTexturePainter painter) =>
                 {
                     painter.ClickDraw(_mousePressPos, null, null, painter._brushScale);
                 });
             }
             else
             {
                 StartDragPaint();
             }
         }
         _hasDoEndDrawActions = false;
         MouseButtonDownAction();
         OnToolStart.Invoke();
         _drag.PlaySoundStartDrag();
     }
     if (Input.GetMouseButton(0) && false == _hasDoEndDrawActions)
     {
         if (false == _isFingerMoved)
         {
             if (Vector3.Distance(Input.mousePosition, _mousePressPos) > 10)
             {
                 _isFingerMoved = true;
             }
         }
         if (null != _finger && true == _isHideFingerOnMove)
         {
             _finger.DOKill();
             _finger.enabled = false;
         }
         if (true == _isFingerMoved)
         {
             bool isUseChecker = false;
             foreach (PainterChecker checker in _listChecker)
             {
                 if (true == checker._isUseChecker)
                 {
                     isUseChecker = true;
                     break;
                 }
             }
             if (false == isUseChecker)
             {
                 OnInArea.Invoke(true);
                 SetDragEffectPlay(true);
             }
         }
         if (true == _isFingerMoved && null != _finger)
         {
             bool ret = RectTransformUtility.ScreenPointToLocalPointInRectangle(_finger.transform.parent.GetComponent <RectTransform>(), Input.mousePosition, Camera.main, out Vector2 localPoint);
             if (ret)
             {
                 if (_finger.transform.GetSiblingIndex() == _finger.transform.parent.childCount - 1)
                 {
                     _finger.GetComponent <RectTransform>().anchoredPosition = localPoint;
                     Vector3 toPos = Camera.main.WorldToScreenPoint(_finger.transform.position);
                     LoopPainter((RenderTexturePainter painter) =>
                     {
                         painter.Drawing(toPos);
                     });
                     UpdateCheckPoint(toPos);
                 }
             }
         }
         else
         {
             Vector3 toPos = Input.mousePosition;
             if (_arrayDrawMainTex.Length > 0)
             {
                 Texture tex = _arrayDrawMainTex[Random.Range(0, _arrayDrawMainTex.Length)];
                 toPos.x = toPos.x - 5 + 10 * Random.Range(0f, 1f);
                 toPos.y = toPos.y - 5 + 10 * Random.Range(0f, 1f);
                 float scale = 0.8f + Random.Range(0f, 1f);
                 LoopPainter((RenderTexturePainter painter) =>
                 {
                     painter.ClickDraw(toPos, null, tex, scale);
                 });
             }
             else
             {
                 LoopPainter((RenderTexturePainter painter) =>
                 {
                     painter.Drawing(toPos);
                 });
             }
             UpdateCheckPoint(toPos);
         }
         MouseButtonMovingAction();
     }
     if (Input.GetMouseButtonUp(0))
     {
         OnInArea.Invoke(false);
         SetDragEffectPlay(false);
         if (true == _hasStartDraw)
         {
             _hasStartDraw = false;
             _drag.PlaySoundEndDrag();
             if (true == _isFingerMoved)
             {
                 _isFingerMoved = false;
                 MouseButtonUpAction();
                 OnToolEnd.Invoke();
             }
             EndDragPaint();
         }
     }
 }