コード例 #1
0
    public void SetTrapezoidal(bool val)
    {
        if (val != IsTrapezoidal)
        {
            AttChange change = new AttChange();

            List <float> prop = new List <float>();
            prop.Add((float)this.GetId());
            prop.Add((float)0.0);
            prop.Add((float)0.0);
            prop.Add((float)1.0);                   // value of attribute index,, not nessesary but just frameword for case of adding attributes
            prop.Add((float)1.0);                   // value as a sign of revertion of bool attribute

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

            GUICircuitComponent.globalUndoList.AddUndo(undoAction);
        }
        IsTrapezoidal = val;
        if (GameObject.Find("PlayToggle").GetComponent <UnityEngine.UI.Toggle>().isOn)
        {
            GameObject.Find("PlayButton").GetComponent <GUICircuit>().RunSimulation();
        }
    }
コード例 #2
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();
        }
    }
コード例 #3
0
    public void SetInductance(double val)
    {
        if (Inductance != val)
        {
            AttChange change = new AttChange();

            List <float> prop = new List <float>();
            prop.Add((float)this.GetId());
            prop.Add((float)1.0);                   // value of attribute index,, not nessesary but just frameword for case of adding attributes
            prop.Add((float)(Inductance - val));
            prop.Add((float)0.0);                   // hodnoty ostatnych atributov sa nezmenia
            prop.Add((float)0.0);

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

            GUICircuitComponent.globalUndoList.AddUndo(undoAction);
        }
        Inductance = val;
        if (GameObject.Find("PlayToggle").GetComponent <UnityEngine.UI.Toggle>().isOn)
        {
            GameObject.Find("PlayButton").GetComponent <GUICircuit>().RunSimulation();
        }
    }
コード例 #4
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();
        }
    }
コード例 #5
0
    public void DuplicateComponent()
    {
        List <GameObject> cloneComponents = new List <GameObject>();
        List <GameObject> cloneLines      = new List <GameObject>();

        // Get all game objects and find the top-left and bottom-right most components
        foreach (GameObject objectSelected in SelectObject.SelectedObjects)
        {
            if (objectSelected.tag.Equals("ActiveItem") || objectSelected.tag.Equals("ActiveNode"))
            {
                // Instantiate new copy GameObject
                GameObject copy =
                    (GameObject)Instantiate(objectSelected, objectSelected.transform.position, objectSelected.transform.rotation);
                copy.GetComponent <GUICircuitComponent>()
                .CopyValues(objectSelected.GetComponent <GUICircuitComponent>());
                copy.transform.FindChild("SelectionBox").GetComponent <SpriteRenderer>().enabled = false;

                // Clear connections of component's Plus and Minus connectors
                Connectable[] connectableScripts = copy.GetComponentsInChildren <Connectable>();
                foreach (Connectable connectableScript in connectableScripts)
                {
                    connectableScript.Connected.Clear();
                }

                // Add newly created clone to the list of clones
                cloneComponents.Add(copy);
            }
        }

        // Duplicate each line and interconnect clone objects
        foreach (GameObject line in SelectObject.SelectedLines)
        {
            GameObject duplicateLine = Instantiate(line);
            duplicateLine.GetComponent <Line>().KeepColiders();

            // Set the Begin of the duplicated line
            GameObject beginComponent = line.GetComponent <Line>().Begin.transform.parent.gameObject;
            // Get the index of Connector among component children
            int        beginChildConnectorIndex = -1;
            GameObject beginConnector           = line.GetComponent <Line>().Begin;
            for (int i = 0; i < beginComponent.transform.childCount; i++)
            {
                if (beginComponent.transform.GetChild(i).gameObject.GetInstanceID() == beginConnector.GetInstanceID())
                {
                    beginChildConnectorIndex = i;
                }
            }
            // Get index of component in the List of SelectedObjects
            int        beginComponentIndex = SelectObject.SelectedObjects.IndexOf(beginComponent);
            GameObject cloneBegin          = cloneComponents[beginComponentIndex];
            duplicateLine.GetComponent <Line>().Begin = cloneBegin.transform.GetChild(beginChildConnectorIndex).gameObject;

            // Set the End of the duplicated line
            GameObject endComponent = line.GetComponent <Line>().End.transform.parent.gameObject;
            // Get the index of Connector among component children
            int        endChildConnectorIndex = -1;
            GameObject endConnector           = line.GetComponent <Line>().End;
            for (int i = 0; i < endComponent.transform.childCount; i++)
            {
                if (endComponent.transform.GetChild(i).gameObject.GetInstanceID() == endConnector.GetInstanceID())
                {
                    endChildConnectorIndex = i;
                }
            }
            // Get index of component in the List of SelectedObjects
            int        endComponentIndex = SelectObject.SelectedObjects.IndexOf(endComponent);
            GameObject cloneEnd          = cloneComponents[endComponentIndex];
            duplicateLine.GetComponent <Line>().End = cloneEnd.transform.GetChild(endChildConnectorIndex).gameObject;

            // Add references of each other to both newly connected connectors of the duplicated objects
            duplicateLine.GetComponent <Line>().Begin.GetComponent <Connectable>().AddConnected(duplicateLine.GetComponent <Line>().End);
            duplicateLine.GetComponent <Line>().End.GetComponent <Connectable>().AddConnected(duplicateLine.GetComponent <Line>().Begin);

            duplicateLine.GetComponent <Line>().Begin.GetComponent <Connector>().ConnectedConnectors.Add(duplicateLine.GetComponent <Line>().End.GetComponent <Connector>());
            duplicateLine.GetComponent <Line>().End.GetComponent <Connector>().ConnectedConnectors.Add(duplicateLine.GetComponent <Line>().Begin.GetComponent <Connector>());

            // Add new line to the list of duplicated lines
            cloneLines.Add(duplicateLine);
        }

        SelectObject selectionComponent = GameObject.Find("Canvas").GetComponent <SelectObject>();

        selectionComponent.DeselectObject();
        selectionComponent.DeselectLine();
        SelectObject.AddItemsToSelection(cloneComponents);
        SelectObject.AddLinesToSelection(cloneLines);

        // Check for collisions - duplicated are placed on the same position as their originals so there MUST BE a collision
        GetComponent <Draggable>().Colision();

        UndoAction undoAction = new UndoAction();

        foreach (GameObject objectSelected in SelectObject.SelectedObjects)
        {
            if (objectSelected.tag.Equals("ActiveItem") || objectSelected.tag.Equals("ActiveNode"))
            {
                GUICircuitComponent component = objectSelected.GetComponent <GUICircuitComponent>();
                List <float>        prop      = new List <float>();
                prop.Add((float)1.0);
                prop.Add((float)component.GetId());
                prop.Add((float)objectSelected.gameObject.transform.GetChild(0).GetComponent <Connectable>().GetID());
                prop.Add((float)objectSelected.gameObject.transform.GetChild(1).GetComponent <Connectable>().GetID());

                CreateDeleteCompChange change = new CreateDeleteCompChange();
                change.SetPosition(objectSelected.transform.position);
                change.SetChange(prop);
                change.SetType(objectSelected.gameObject.GetComponent <GUICircuitComponent>().GetType());
                change.RememberConnectorsToFirst(objectSelected.gameObject.transform.GetChild(0).GetComponent <Connectable>().Connected);
                change.RememberConnectorsToSecond(objectSelected.gameObject.transform.GetChild(1).GetComponent <Connectable>().Connected);

                undoAction.AddChange(change);
            }
        }
        GUICircuitComponent.globalUndoList.AddUndo(undoAction);
    }
コード例 #6
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        GameObject end = null;

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

        //if gameobject is in desktop, not in toolbox
        if (this.gameObject.transform.parent.tag == "ActiveItem" || this.gameObject.transform.parent.tag == "ActiveNode")
        {
            //browse all connestors in scene
            GameObject[] objs = GameObject.FindGameObjectsWithTag("Connector");
            foreach (GameObject go in objs)
            {
                Vector3 conPos = go.transform.position * 2;
                conPos  = new Vector3(Mathf.Round(conPos.x), Mathf.Round(conPos.y));
                conPos /= 2;

                //searching connector in mouse position in the end of drag
                if (conPos == _endPos)
                {
                    end = go;
                    break;
                }
            }

            //cant connect with himself or with connector belonging to the same component
            if (end != null &&
                end != this.gameObject &&
                !Connected.Contains(end) &&
                end.transform.parent.gameObject != this.gameObject.transform.parent.gameObject &&
                end.transform.parent.gameObject.tag != "ToolboxItemActive")
            {
                //connecting these two object with line
                _line.End = end;
                Connected.Add(_line.End);
                _line.End.SendMessage("AddConnected", this.gameObject);
                GameObject newLine = Instantiate(Obj);
                newLine.tag = "ActiveLine";
                newLine.transform.position = new Vector2((_line.Begin.transform.position.x + _line.EndPos.x) / 2,
                                                         (_line.Begin.transform.position.y + _line.EndPos.y) / 2);

                Connector con1 = _line.End.GetComponent <Connector>();
                Connector con2 = gameObject.GetComponent <Connector>();
                con1.ConnectedConnectors.Add(con2);
                con2.ConnectedConnectors.Add(con1);

                UndoAction undoAction = new UndoAction();

                List <float> prop = new List <float>();
                prop.Add((float)1.0);
                prop.Add((float)_line.End.GetComponent <Connectable>().GetID());
                prop.Add((float)_line.Begin.GetComponent <Connectable>().GetID());

                CreateDeleteLineChange change = new CreateDeleteLineChange();
                change.SetChange(prop);
                undoAction.AddChange(change);
                GUICircuitComponent.globalUndoList.AddUndo(undoAction);
            }

            //destroy all lines which dont connect two connectors except parental Line
            Destroy(_line);
            GameObject[] killEmAll;
            killEmAll = GameObject.FindGameObjectsWithTag("Line");
            foreach (GameObject t in killEmAll)
            {
                if (t.GetComponent <Line>().End == null && t.transform.name != "Line")
                {
                    Destroy(t.gameObject);
                }
                else
                {
                    //set invisible parental Line
                    t.GetComponent <LineRenderer>().SetPosition(1, this.gameObject.transform.position);
                }
            }
        }
    }
コード例 #7
0
ファイル: Draggable.cs プロジェクト: mjartanm/NEWTON---EDUSIM
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        GameObject           propertiesContainer = GameObject.Find("PropertiesWindowContainer");
        EditObjectProperties script = propertiesContainer.GetComponent <EditObjectProperties>();

        // Deselect selected item first.
        if (SelectObject.SelectedObjects.Count != 0 && !SelectObject.SelectedObjects.Contains(this.gameObject))
        {
            //deselect item
            GameObject item = GameObject.Find("Canvas");
            item.GetComponent <SelectObject>().DeselectObject();

            // Deselect line
            GameObject line = GameObject.Find("Line(Clone)");
            if (line != null)
            {
                GameObject.Find("Canvas").GetComponent <SelectObject>().DeselectLine();
            }
        }
        else if (SelectObject.SelectedObjects.Count > 1 && SelectObject.SelectedObjects.Contains(this.gameObject))
        {
            // Setting starting positions for every selected elements
            _mousePos = Camera.main.ScreenToWorldPoint(eventData.position);
            foreach (GameObject objectSelected in SelectObject.SelectedObjects)
            {
                _itemPoss.Add(objectSelected.transform.position);
            }
        }
        //deselect line
        else
        {
            GameObject line = GameObject.Find("Line(Clone)");
            if (line != null)
            {
                GameObject.Find("Canvas").GetComponent <SelectObject>().DeselectLine();
            }
        }

        // Setting starting posiitons.
        _mousePos = Camera.main.ScreenToWorldPoint(eventData.position);
        _itemPos  = this.gameObject.transform.position;

        // ToolboxItemActive tagged GameObjects are used to generate new instances for the working panel.
        if (this.gameObject.tag == "Arrow" && this.gameObject.transform.parent.tag != "ToolboxItemActive")
        {
            _arrow    = this.gameObject;
            _arrowPos = new Vector2(this.gameObject.transform.parent.transform.position.x, _arrow.transform.position.y);
            _connectorPotentiometer    = this.gameObject.transform.parent.gameObject.transform.FindChild("PlusConnector").gameObject;
            _connectorPotentiometerPos = new Vector2(this.gameObject.transform.parent.transform.position.x, _connectorPotentiometer.transform.position.y);
        }
        else if ((this.gameObject.tag == "Arrow" && this.gameObject.transform.parent.tag == "ToolboxItemActive") ||
                 this.gameObject.tag == "ToolboxItemActive")
        {
            // Debug.Log(this.gameObject.transform.parent);
            GameObject item = this.gameObject;
            if (this.gameObject.transform.parent.tag == "ToolboxItemActive")
            {
                item = item.gameObject.transform.parent.gameObject;
            }

            tbitem = true;
            item.gameObject.tag = "ActiveItem";
            // Awake() function of every script is called when GameObject is instatiated. We need it to be instantiated as ActiveItem.
            _draggingItem       = Instantiate(item.gameObject);
            item.gameObject.tag = "ToolboxItemActive";
            _draggingItem.tag   = "ActiveItem";
            _draggingItem.layer = 8; //Name of 8th layer is ActiveItem
            _draggingItem.transform.localScale = new Vector3(1, 1, 0);
            _draggingItem.GetComponent <SpriteRenderer>().enabled          = true;
            _draggingItem.GetComponent <SpriteRenderer>().sortingLayerName = "ActiveItem";

            for (int i = 0; i < _draggingItem.transform.childCount; i++)
            {
                _draggingItem.transform.GetChild(i).GetComponent <SpriteRenderer>().sortingLayerName = "ActiveItem";
                _draggingItem.transform.GetChild(i).GetComponent <SpriteRenderer>().enabled          = true;
                _draggingItem.transform.GetChild(i).gameObject.layer = 8;
            }
            // Newly created component needs to be selected otherwise an error will occur
            SelectObject.AddItemToSelection(_draggingItem);

            UndoAction          undoAction = new UndoAction();
            GUICircuitComponent component  = _draggingItem.GetComponent <GUICircuitComponent>();
            List <float>        prop       = new List <float>();
            prop.Add((float)1.0);
            prop.Add((float)component.GetId());
            prop.Add((float)_draggingItem.gameObject.transform.GetChild(0).GetComponent <Connectable>().GetID());
            prop.Add((float)_draggingItem.gameObject.transform.GetChild(1).GetComponent <Connectable>().GetID());
            CreateDeleteCompChange change = new CreateDeleteCompChange();
            change.SetPosition(_draggingItem.transform.position);
            change.SetChange(prop);
            change.SetType(_draggingItem.gameObject.GetComponent <GUICircuitComponent>().GetType());
            change.RememberConnectorsToFirst(_draggingItem.gameObject.transform.GetChild(0).GetComponent <Connectable>().Connected);
            change.RememberConnectorsToSecond(_draggingItem.gameObject.transform.GetChild(1).GetComponent <Connectable>().Connected);
            undoAction.AddChange(change);
            GUICircuitComponent.globalUndoList.AddUndo(undoAction);
        }
        else if (this.gameObject.tag == "Node")
        {
            _draggingItem       = Instantiate(this.gameObject);
            _draggingItem.tag   = "ActiveNode";
            _draggingItem.layer = 8; //Name of 8th layer is ActiveItem
            _draggingItem.transform.localScale = new Vector3(1, 1, 0);
            _draggingItem.GetComponent <SpriteRenderer>().enabled          = true;
            _draggingItem.GetComponent <SpriteRenderer>().sortingLayerName = "ActiveItem";

            for (int i = 0; i < _draggingItem.transform.childCount; i++)
            {
                _draggingItem.transform.GetChild(i).GetComponent <SpriteRenderer>().sortingLayerName     = "ActiveItem";
                _draggingItem.transform.GetChild(i).GetComponent <SpriteRenderer>().transform.localScale = new Vector3(1, 1, 0);
                _draggingItem.transform.GetChild(i).GetComponent <SpriteRenderer>().enabled = true;
                _draggingItem.transform.GetChild(i).gameObject.layer = 8;
            }

            // Newly created component needs to be selected otherwise an error will occur
            SelectObject.AddItemToSelection(_draggingItem);
        }
        else if (SelectObject.SelectedObjects.Count == 0 || SelectObject.SelectedObjects.Count == 1 && SelectObject.SelectedObjects[0] == this.gameObject)
        {
            _draggingItem = this.gameObject;
            if (SelectObject.SelectedObjects.Count == 0)
            {
                // Select new object.
                SelectObject.SelectedObjects.Add(_draggingItem);
                _draggingItem.GetComponent <SelectObject>().SelectionBox.GetComponent <SpriteRenderer>().enabled = true;
            }

            // Clear the Properties Window
            script.Clear();

            // Call the script from component that fills the Properties Window
            GUICircuitComponent componentScript = _draggingItem.GetComponent <GUICircuitComponent>();
            componentScript.GetProperties();
        }

        _tbu.EnableToolbarButtons();
    }
コード例 #8
0
ファイル: Draggable.cs プロジェクト: mjartanm/NEWTON---EDUSIM
    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;
        }
    }
コード例 #9
0
    public void DeleteSelected()
    {
        if (SelectObject.SelectedObjects.Count != 0)
        {
            UndoAction undoAction = new UndoAction();
            foreach (GameObject objectSelected in SelectObject.SelectedObjects)
            {
                GUICircuitComponent component = objectSelected.GetComponent <GUICircuitComponent>();
                List <float>        prop      = new List <float>();
                prop.Add((float)0.0);
                prop.Add((float)component.GetId());
                prop.Add((float)objectSelected.gameObject.transform.GetChild(0).GetComponent <Connectable>().GetID());
                prop.Add((float)objectSelected.gameObject.transform.GetChild(1).GetComponent <Connectable>().GetID());

                CreateDeleteCompChange change = new CreateDeleteCompChange();
                change.SetPosition(objectSelected.transform.position);
                change.SetChange(prop);
                change.SetType(objectSelected.gameObject.GetComponent <GUICircuitComponent>().GetType());
                change.RememberConnectorsToFirst(objectSelected.gameObject.transform.GetChild(0).GetComponent <Connectable>().Connected);
                change.RememberConnectorsToSecond(objectSelected.gameObject.transform.GetChild(1).GetComponent <Connectable>().Connected);

                undoAction.AddChange(change);

                if (objectSelected.tag.Equals("ActiveItem"))
                {
                    // List connected connectors with plusconnector
                    List <GameObject> connected1 =
                        objectSelected.transform.GetChild(0).GetComponent <Connectable>().Connected;

                    // List connected connectors with minusconnector
                    List <GameObject> connected2 =
                        objectSelected.transform.GetChild(1).GetComponent <Connectable>().Connected;

                    Connector con1 = objectSelected.transform.GetChild(0).GetComponent <Connector>();
                    Connector con2 = objectSelected.transform.GetChild(1).GetComponent <Connector>();

                    // First update list of connected connectors in connected component with this component
                    foreach (GameObject c in connected1)
                    {
                        c.gameObject.GetComponent <Connectable>().Connected.Remove(objectSelected.transform.GetChild(0).gameObject);
                        c.gameObject.GetComponent <Connector>().ConnectedConnectors.Remove(con1);
                    }

                    foreach (GameObject c in connected2)
                    {
                        c.gameObject.GetComponent <Connectable>().Connected.Remove(objectSelected.transform.GetChild(1).gameObject);
                        c.gameObject.GetComponent <Connector>().ConnectedConnectors.Remove(con2);
                    }

                    // For each lines in scene
                    GameObject[] lines = GameObject.FindGameObjectsWithTag("ActiveLine");

                    foreach (GameObject currentLine in lines)
                    {
                        // For every line connected to this component
                        if (objectSelected.transform.GetChild(0).gameObject ==
                            currentLine.GetComponent <Line>().Begin
                            ||
                            objectSelected.transform.GetChild(1).gameObject ==
                            currentLine.GetComponent <Line>().Begin
                            ||
                            objectSelected.transform.GetChild(0).gameObject ==
                            currentLine.GetComponent <Line>().End
                            ||
                            objectSelected.transform.GetChild(1).gameObject ==
                            currentLine.GetComponent <Line>().End)
                        {
                            Destroy(currentLine.gameObject);
                        }
                    }
                    Destroy(objectSelected);
                }
            }
            GUICircuitComponent.globalUndoList.AddUndo(undoAction);
            SelectObject.SelectedLines.Clear();
            GetComponent <SelectObject>().DeselectObject();
        }


        // Destroy selected line when delete key was pressed
        if (SelectObject.SelectedLines.Count != 0 && SelectObject.SelectedLines.Contains(this.gameObject))
        {
            UndoAction undoAction = new UndoAction();

            List <float> prop = new List <float>();
            prop.Add((float)0.0);
            prop.Add(this.gameObject.GetComponent <Line>().Begin.GetComponent <Connectable>().GetID());
            prop.Add(this.gameObject.GetComponent <Line>().End.GetComponent <Connectable>().GetID());

            CreateDeleteLineChange change = new CreateDeleteLineChange();
            change.SetChange(prop);
            undoAction.AddChange(change);
            GUICircuitComponent.globalUndoList.AddUndo(undoAction);

            // Delete connected connectors from lists of connectors
            this.gameObject.GetComponent <Line>().Begin.GetComponent <Connectable>().Connected.Remove(this.gameObject.GetComponent <Line>().End.gameObject);
            this.gameObject.GetComponent <Line>().End.GetComponent <Connectable>().Connected.Remove(this.gameObject.GetComponent <Line>().Begin.gameObject);

            this.gameObject.GetComponent <Line>().Begin.GetComponent <Connector>().ConnectedConnectors.Remove(this.gameObject.GetComponent <Line>().End.GetComponent <Connector>());
            this.gameObject.GetComponent <Line>().End.GetComponent <Connector>().ConnectedConnectors.Remove(this.gameObject.GetComponent <Line>().Begin.GetComponent <Connector>());

            Destroy(this.gameObject);
            SelectObject.SelectedLines.Remove(this.gameObject);
        }
    }