Beispiel #1
0
    // Update is called once per frame
    protected void Update()
    {
        #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        _touches = Input.touches;
        #endif
        if (_gui.GetCurrentMode () == PoolDesignerMode.PolygonEdition)
        {
            _cursor = _planTransformation.GetTransformedMousePosition ();

            // on cherche le point et l'edge qui sont sous le curseur
            FindIntersectedPoint ();
            FindIntersectedEdge ();

        //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        //            if(Input.touchCount == 1)
        //            {
        //                _firstTouch = _planTransformation.GetTouches()[0];
        //                Touch testouch = _touches[0];
        //
        //            if (!_gui.isOnUI () && _firstTouch.phase == TouchPhase.Began)
        //            {
        //                Debug.Log("---------> firstTouch "+_firstTouch.deltaTime+", "+_firstTouch.position+", "+_firstTouch.deltaPosition+", "+_firstTouch.phase);
        //                Debug.Log("---------> testTouch  "+testouch.deltaTime+", "+testouch.position+", "+testouch.deltaPosition+", "+testouch.phase);
        //#else
          //if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_EDITOR
            if (!_gui.isOnUI () && _planTransformation.GetClickBegan()/*PC.In.Click1Down()*/ && !_gui.IsOpen())
            {
        //#endif
                if(_gui.IsJustCloseMenu())
                {
                    _gui.setIsJustCloseMenu(false);
                    return;
                }
                if (_selectedPointIndexCandidate >= 0) // selection
                {
                    _selectedPointIndex = _selectedPointIndexCandidate;
                    _selectedPoint = _polygon.GetPoints ()[_selectedPointIndex];

                    if (!_polygon.IsClosed () && _selectedPointIndex == 0 /*&& _polygon.GetPoints ().Count > 2*/)
                    {
                        _polygon.Close ();
                        _selectedPointIndex = _polygon.GetPoints ().IndexOf (_selectedPoint);
                    }

                    _canMove = true;
                }
                else if (_selectedEdgeIndexCandidate >= 0) // insert point
                {
                    _selectedEdgeIndex = _selectedEdgeIndexCandidate;
                    _selectedEdge = _polygon.GetEdges ()[_selectedEdgeIndex];

                    Point2 newPoint = new Point2 (_cursor);
                    newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight);
                    _polygon.InsertPoint (_selectedEdgeIndex, newPoint);

                    _selectedPointIndex = _polygon.GetPoints ().IndexOf (newPoint);
                    _selectedPoint = newPoint;

                    _canMove = true;
                }

                else if (!_polygon.IsClosed ()) // add point
                {
                    Point2 newPoint = new Point2 (_cursor);
                    newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight);
                    _polygon.AddPoint (newPoint);

                    _selectedPointIndex = _polygon.GetPoints ().Count - 1;
                    _selectedPoint = newPoint;

                    _canMove = true;

                }
                else // deselection
                {
                    _selectedPointIndex = -1;
                    _selectedPoint = null;

                    _selectedEdgeIndex = -1;
                    _selectedEdge = null;
                }

                if (_selectedPointIndex >= 0) // update radius slider values
                {
                    _pointOffset = (Vector2)_selectedPoint - _cursor;

                    if (_selectedPoint.GetJunction () == JunctionType.Broken)
                    {
                        _gui.SetSliderValues (0, 1);
                    }
                    else if (_selectedPoint.GetJunction () == JunctionType.Curved)
                    {
                        ArchedPoint2 ar = _selectedPoint as ArchedPoint2;
                        _gui.SetSliderValues (ar.GetMeasuredRadius () / 100, ar.GetMaxRadius () / 100);
                    }
                }
            }
        //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        //            }
        //#endif
            if (PC.In.Click1Up()) //Input.GetMouseButtonUp (0))
            {
                _canMove = false;

                if (!_polygon.IsClosed () &&
                    _polygon.GetPoints ().Count > 2 &&
                    _selectedPointIndex == _polygon.GetPoints ().Count - 1) // close polygon
                {
                    Vector2 firstPoint = _polygon.GetPoints ()[0];
                    float rectSize = 100;
                    Rect closeRect = new Rect (
                        firstPoint.x - rectSize/2,
                        firstPoint.y - rectSize/2,
                        rectSize, rectSize);

                    if (closeRect.Contains (_cursor))
                    {
                        _polygon.CloseAndFusion ();

                        _selectedPointIndex = -1;
                        _selectedPoint = null;

                        _selectedEdgeIndex = -1;
                        _selectedEdge = null;
                    }
                }
            }

            if(PC.In.Click1Hold() && _selectedPointIndex >= 0 && _canMove) // move selected point
            {
                _snapper.SetExclusionPoint (_selectedPoint);
                Vector2 pointPosition = _cursor + _pointOffset;

                if (_snapper.IsAngleSnapActivate () && _snapper.IsAngleSnapped ())
                {
                    pointPosition = _snapper.GetAngleSnapPosition ();
                }

                if (_snapper.IsAlignedPointSnapActivate ())
                {
                    if (_snapper.IsHSnapped ())
                    {
                        pointPosition.y = _snapper.GetHSnapY () /*+ _offsetHeight*/;
                    }

                    if (_snapper.IsVSnapped ())
                    {
                        pointPosition.x = _snapper.GetVSnapX () /*+ _offsetWidth*/;
                    }
                }

                if (_snapper.IsPointSnapActivate () && _snapper.IsIntersectedSnapped ())
                {
                    pointPosition = _snapper.GetIntersectedSnapPosition ();
            //		pointPosition.Set(pointPosition.x + _offsetWidth, pointPosition.y + _offsetHeight);
                }

                _polygon.MovePoint (_selectedPointIndex, pointPosition);
            }
        //#endif
        }
        if(m_isModifyingH || m_isModifyingW)
        {
            if (PC.In.Click1Up() && !PC.In.CursorOnUIs(m_cotationH,m_cotationW))
            {

                m_isModifyingW = m_isModifyingH = false;
            }
        }
    }