예제 #1
0
    //Rotate functionality to invoke rotation from button, -90 degrees
    public void RoateCounterClockWise()
    {
        if (SelectObject.SelectedObjects.Count == 1)
        {
            foreach (GameObject objectSelected in SelectObject.SelectedObjects)
            {
                Vector3 curentPos = objectSelected.transform.position;

                objectSelected.transform.Rotate(new Vector3(0, 0, +90));

                Vector3 finalPos = objectSelected.transform.position;

                List <float> properties = new List <float>();
                properties.Add(objectSelected.GetComponent <GUICircuitComponent>().GetId());
                properties.Add(curentPos[0] - finalPos[0]);
                properties.Add(curentPos[1] - finalPos[1]);
                properties.Add(-90);

                PosChange change = new PosChange();
                change.SetChange(properties);

                UndoAction undoAction = new UndoAction();
                undoAction.AddChange(change);

                GUICircuitComponent.globalUndoList.AddUndo(undoAction);
            }

            //transform position of each lines in scene
            Line.TransformLines();
        }
    }
예제 #2
0
    public void RotateMultiObjectClockWise()
    {
        Vector3 point = CalculateCenterPoint();

        if (SelectObject.SelectedObjects.Count > 1)
        {
            UndoAction undoAction = new UndoAction();
            foreach (GameObject objectSelected in SelectObject.SelectedObjects)
            {
                Vector3 curentPos = objectSelected.transform.position;

                objectSelected.transform.RotateAround(point, new Vector3(0, 0, 1), -90);

                Vector3 finalPos = objectSelected.transform.position;

                finalPos *= 2;
                finalPos  = new Vector3(Mathf.Round(finalPos.x), Mathf.Round(finalPos.y));
                finalPos /= 2;

                objectSelected.transform.position = finalPos;

                List <float> properties = new List <float>();
                properties.Add(objectSelected.GetComponent <GUICircuitComponent>().GetId());
                properties.Add(0);
                properties.Add(0);
                properties.Add(+90);
                properties.Add(0);

                PosChange change = new PosChange();
                change.SetChange(properties);
                change.SetPoint(point);

                undoAction.AddChange(change);
            }

            GUICircuitComponent.globalUndoList.AddUndo(undoAction);

            //checking colision
            GameObject.Find("" +
                            "Canvas" +
                            "").GetComponent <Draggable>().Colision();

            //transform position of each lines in scene
            Line.TransformLines();
        }
    }
예제 #3
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        if (_draggingItem != null)
        {
            dragging = false;

            // Snapping by 0.5f.
            Vector3 finalPos = _draggingItem.transform.position;

            finalPos *= 2;
            finalPos  = new Vector3(Mathf.Round(finalPos.x), Mathf.Round(finalPos.y));
            finalPos /= 2;

            _draggingItem.transform.position = finalPos;
            _draggingItem.transform.position = new Vector3(_draggingItem.transform.position.x, _draggingItem.transform.position.y, -6);


            if (tbitem == false)
            {
                List <float> properties = new List <float>();
                properties.Add(_draggingItem.GetComponent <GUICircuitComponent>().GetId());
                properties.Add(curentPos[0][0] - finalPos[0]);
                properties.Add(curentPos[0][1] - finalPos[1]);

                PosChange change = new PosChange();
                change.SetChange(properties);

                UndoAction undoAction = new UndoAction();
                undoAction.AddChange(change);

                GUICircuitComponent.globalUndoList.AddUndo(undoAction);
            }
            else
            {
                GUICircuitComponent.globalUndoList.undoList.First.Value.changes[GUICircuitComponent.globalUndoList.undoList.Last.Value.changes.Count - 1].position = finalPos;
            }
            curentPos.Clear();
            tbitem = false;

            //checking colision
            Colision();
            _draggingItem.transform.position = new Vector3(_draggingItem.transform.position.x, _draggingItem.transform.position.y, -6);
            _draggingItem = null;
        }
        else if (SelectObject.SelectedObjects.Count > 1)
        {
            dragging = false;
            int        i          = 0;
            UndoAction undoAction = new UndoAction();

            foreach (GameObject objectSelected in SelectObject.SelectedObjects)
            {
                Vector3 finalPos = objectSelected.transform.position;

                finalPos *= 2;
                finalPos  = new Vector3(Mathf.Round(finalPos.x), Mathf.Round(finalPos.y));
                finalPos /= 2;

                objectSelected.transform.position = finalPos;
                List <float> properties = new List <float>();
                properties.Add(objectSelected.GetComponent <GUICircuitComponent>().GetId());
                properties.Add(curentPos[i][0] - finalPos[0]);
                properties.Add(curentPos[i][1] - finalPos[1]);

                PosChange change = new PosChange();
                change.SetChange(properties);
                undoAction.AddChange(change);
                i++;

                //checking colision
                Colision();
            }
            GUICircuitComponent.globalUndoList.AddUndo(undoAction);
            curentPos.Clear();
        }

        _itemPoss.Clear();

        //transform position of each lines in scene
        Line.TransformLines();

        if (_arrow != null)
        {
            dragging = false;
            _arrow.transform.position = new Vector3(_arrow.transform.position.x, _arrow.transform.position.y, -6);
            _connectorPotentiometer.transform.position = new Vector3(_connectorPotentiometer.transform.position.x, _connectorPotentiometer.transform.position.y, 0);
            _connectorPotentiometer = null;
            _arrow = null;
        }
    }