Пример #1
0
    // If we let go of the left mouse button, end selection
    public void OnPointerUp(PointerEventData eventData)
    {
        if (eventData.button != PointerEventData.InputButton.Left)
        {
            return;
        }

        //select every item in selection bounds
        foreach (GameObject selectableObject in GameObject.FindGameObjectsWithTag("ActiveItem"))
        {
            if (IsWithinSelectionBounds(selectableObject.gameObject))
            {
                SelectObject.SelectedObjects.Add(selectableObject);
                selectableObject.GetComponent <SelectObject>().SelectionBox.GetComponent <SpriteRenderer>().enabled = true;
            }
        }

        foreach (GameObject selectableObject in GameObject.FindGameObjectsWithTag("ActiveNode"))
        {
            if (IsWithinSelectionBounds(selectableObject.gameObject))
            {
                SelectObject.SelectedObjects.Add(selectableObject);
                selectableObject.GetComponent <SelectObject>().SelectionBox.GetComponent <SpriteRenderer>().enabled = true;
            }
        }

        foreach (GameObject selectableObject in GameObject.FindGameObjectsWithTag("ActiveLine"))
        {
            if (IsWithinSelectionBounds(selectableObject.gameObject))
            {
                SelectObject.SelectedLines.Add(selectableObject);
                selectableObject.GetComponent <LineRenderer>().SetColors(Color.red, Color.red);
            }
        }

        //end of selecting
        _isSelecting = false;

        // Call the script from component that fills the Properties Window
        if (SelectObject.SelectedObjects.Count == 1)
        {
            GUICircuitComponent componentScript = SelectObject.SelectedObjects[0].GetComponent <GUICircuitComponent>();
            componentScript.GetProperties();
        }

        //enabling or disabling buttons in toolbar panel
        if (SelectObject.SelectedObjects.Count != 0)
        {
            _tbu.EnableToolbarButtons();
        }
        else
        {
            _tbu.DisableToolbarButtons();
        }
    }
Пример #2
0
    // Add a new item to the selection
    public static void AddItemToSelection(GameObject go)
    {
        SelectedObjects.Add(go);
        go.transform.FindChild("SelectionBox").GetComponent <SpriteRenderer>().enabled = true;

        // Call the script from component that fills the Properties Window
        if (SelectedObjects.Count == 1)
        {
            GUICircuitComponent componentScript = SelectedObjects[0].GetComponent <GUICircuitComponent>();
            componentScript.GetProperties();
        }
    }
Пример #3
0
    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Middle || this.gameObject.tag == "ToolboxItem" || this.gameObject.tag == "Node" || this.gameObject.tag == "ToolboxItemActive" || this.gameObject.tag == "Untagged")
        {
            return;
        }

        // Deselect selected item first.
        if (!SelectedObjects.Contains(this.gameObject))
        {
            DeselectObject();
        }

        // Deselect line
        if (!SelectedObjects.Contains(this.gameObject))
        {
            GameObject line = GameObject.Find("Line(Clone)");
            if (line != null)
            {
                DeselectLine();
            }
        }

        // Select new object.
        if (!SelectedObjects.Contains(this.gameObject))
        {
            SelectedObjects.Add(this.gameObject);
            SelectionBox.GetComponent <SpriteRenderer>().enabled = true;
        }

        _tbu.EnableToolbarButtons();

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

        // Call the script from component that fills the Properties Window
        if (SelectedObjects.Count == 1)
        {
            GUICircuitComponent componentScript = SelectedObjects[0].GetComponent <GUICircuitComponent>();
            componentScript.GetProperties();
        }
    }
Пример #4
0
    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();
    }