Exemple #1
0
    private IEnumerator OnDrag()
    {
        while (m_isBeingDragged)
        {
            //Drag Logic

            Vector2 mousePosition = m_visualGridManager.GetSnapPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y), m_visualGate);
            m_rectTransform.anchoredPosition = mousePosition;

            if (Input.GetMouseButtonUp(1))
            {
                VisualGate visualGate = GetComponent <VisualGate>();
                if (visualGate != null)
                {
                    visualGate.Rotate(true);
                }
            }

            yield return(null);
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        if (justExited > 0.0f)
        {
            justExited -= Time.deltaTime;
        }

        if (IsInWireEditMode())
        {
            Vector2    mousePosition = m_visualGridManager.GetSnapPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
            Vector2Int oGridoob      = Vector2Int.zero;
            Vector2Int oGrid         = Vector2Int.zero;

            bool foundGrid    = m_visualGridManager.GetGridCoordinates(mousePosition, ref oGrid, false, true);                                                // In bounds for dragging
            bool foundGridOOB = m_visualGridManager.GetGridCoordinates(mousePosition, ref oGridoob, false, false) &&
                                oGridoob.x >= 0 && oGridoob.x < m_gridManager.DimensionX + 2 && oGridoob.y >= 0 && oGridoob.y < m_gridManager.DimensionY + 2; // Allow oob for start/end

            if (m_isDragging)
            {
                CellCoordinates cell  = new CellCoordinates();
                bool            found = false;
                if (foundGridOOB)
                {
                    CellCoordinates oobCell = new CellCoordinates((uint)oGridoob.x, (uint)oGridoob.y);
                    GridObject      o       = m_gridManager.GetCell(oobCell);
                    if (o != null)
                    {
                        cell  = oobCell;
                        found = true;
                    }
                }
                if (!found && foundGrid)
                {
                    cell  = new CellCoordinates((uint)oGrid.x, (uint)oGrid.y);
                    found = true;
                }

                if (found)
                {
                    PassThroughCell(cell);
                    string log = "WireManager: Current path - ";
                    foreach (CellCoordinates x in m_passedThrough.ToArray())
                    {
                        log += x.ToString() + " ";
                    }
                    if (LogVerbose)
                    {
                        Log(log);
                    }
                }
            }

            // Start drag
            if (Input.GetMouseButtonDown(0) && !m_isDragging)
            {
                if (foundGridOOB)
                {
                    CellCoordinates cell = new CellCoordinates((uint)oGridoob.x, (uint)oGridoob.y);
                    // Valid start point, begin
                    StartDragging(cell);
                    if (!m_isDragging)
                    {
                        EndMode();
                    }
                }
                else
                {
                    EndMode();
                }
            }

            // End Drag/Mode
            if (Input.GetMouseButtonUp(0) && m_isDragging)
            {
                TryCommit();
            }

            // Delete
            if (Input.GetMouseButtonUp(1) && !m_isDragging)
            {
                if (foundGrid)
                {
                    CellCoordinates cell = new CellCoordinates((uint)oGrid.x, (uint)oGrid.y);;
                    GridObject      o    = m_gridManager.GetCell(cell);
                    if (o != null && o.ObjectType == GridObjectType.Wire)
                    {
                        m_wireVisualManager.ClearWire(cell);
                        m_gridManager.ClearCell(cell);
                    }
                    else
                    {
                        EndMode();
                    }
                }
                else
                {
                    EndMode();
                }
            }
        }
    }