示例#1
0
        public void SetEdge(EdgeID edgeID, bool state)
        {
            if (state)
            {
                _activeEdgeIDs |= (byte)edgeID;
            }
            else
            {
                _activeEdgeIDs &= (byte)~(byte)edgeID;
            }

            UpdateCurrentEdgeCount();
        }
示例#2
0
 ///<summary>Try to Remove Polygon Edge</summary>
 public (bool, PolygonID) TryToRemovePolygonEdge(EdgeID EdgeID) =>
示例#3
0
 ///<summary>Split Edge</summary>
 public IReadOnlyCollection <VertexID> SplitEdge(EdgeID EdgeID, byte Splits /*TODO: array TArray */) =>
 EditableMesh_methods.SplitEdge_method.Invoke(ObjPointer, EdgeID, Splits);
示例#4
0
 ///<summary>Returns whether the given edge ID is valid</summary>
 public bool IsValidEdge(EdgeID EdgeID) =>
 EditableMesh_methods.IsValidEdge_method.Invoke(ObjPointer, EdgeID);
示例#5
0
 ///<summary>Insert Edge Loop</summary>
 public IReadOnlyCollection <EdgeID> InsertEdgeLoop(EdgeID EdgeID, byte Splits /*TODO: array TArray */) =>
 EditableMesh_methods.InsertEdgeLoop_method.Invoke(ObjPointer, EdgeID, Splits);
示例#6
0
 ///<summary>Get Edge Vertices</summary>
 public (VertexID, VertexID) GetEdgeVertices(EdgeID EdgeID) =>
示例#7
0
 ///<summary>Returns the given indexed vertex for this edge. EdgeVertexNumber must be 0 or 1.</summary>
 public VertexID GetEdgeVertex(EdgeID EdgeID, int EdgeVertexNumber) =>
 EditableMesh_methods.GetEdgeVertex_method.Invoke(ObjPointer, EdgeID, EdgeVertexNumber);
示例#8
0
 ///<summary>Get Edge Loop Elements</summary>
 public IReadOnlyCollection <EdgeID> GetEdgeLoopElements(EdgeID EdgeID) =>
 EditableMesh_methods.GetEdgeLoopElements_method.Invoke(ObjPointer, EdgeID);
示例#9
0
 ///<summary>Get Edge Connected Polygons</summary>
 public IReadOnlyCollection <PolygonID> GetEdgeConnectedPolygons(EdgeID EdgeID) =>
 EditableMesh_methods.GetEdgeConnectedPolygons_method.Invoke(ObjPointer, EdgeID);
示例#10
0
 ///<summary>Returns the number of polygons connected to this edge</summary>
 public int GetEdgeConnectedPolygonCount(EdgeID EdgeID) =>
 EditableMesh_methods.GetEdgeConnectedPolygonCount_method.Invoke(ObjPointer, EdgeID);
示例#11
0
 ///<summary>Returns the indexed polygon connected to this edge</summary>
 public PolygonID GetEdgeConnectedPolygon(EdgeID EdgeID, int ConnectedPolygonNumber) =>
 EditableMesh_methods.GetEdgeConnectedPolygon_method.Invoke(ObjPointer, EdgeID, ConnectedPolygonNumber);
示例#12
0
 ///<summary>Find Polygon Loop</summary>
 public (IReadOnlyCollection <EdgeID>, IReadOnlyCollection <EdgeID>, IReadOnlyCollection <EdgeID>, IReadOnlyCollection <PolygonID>) FindPolygonLoop(EdgeID EdgeID) =>
 EditableMesh_methods.FindPolygonLoop_method.Invoke(ObjPointer, EdgeID);
示例#13
0
 ///<summary>Delete Edge and Connected Polygons</summary>
 public void DeleteEdgeAndConnectedPolygons(EdgeID EdgeID, bool bDeleteOrphanedEdges, bool bDeleteOrphanedVertices, bool bDeleteOrphanedVertexInstances, bool bDeleteEmptyPolygonGroups) =>
 EditableMesh_methods.DeleteEdgeAndConnectedPolygons_method.Invoke(ObjPointer, EdgeID, bDeleteOrphanedEdges, bDeleteOrphanedVertices, bDeleteOrphanedVertexInstances, bDeleteEmptyPolygonGroups);
示例#14
0
    void Update()
    {
        timer.Update();

        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.E))
        {
            inEditMode = !inEditMode;
            puzzleEditText.gameObject.SetActive(inEditMode);
            timer.SetVisibility(!inEditMode);
            return;
        }

        if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.C))
        {
            InitializeBoard();
            return;
        }

        if (Input.GetKeyDown(KeyCode.F5))
        {
            SaveData();
            return;
        }

        if (Input.GetKeyDown(KeyCode.F9))
        {
            LoadData();
            timer.Reset(false);
            return;
        }

        if (Input.GetKey(KeyCode.S))
        {
            if (showSolution != true)
            {
                ShowSolution(true);
            }
        }
        else
        {
            if (showSolution == true)
            {
                ShowSolution(false);
            }
        }

        // Update cursor position and validity
        _cursorXY   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        _cursorXY.z = 0f;
        if (_cursorXY.x > 0f && _cursorXY.x < (float)sizeX && _cursorXY.y > 0f && _cursorXY.y < (float)sizeY)
        {
            _cursorValidity = CursorValidity.InsideCell;
        }
        else if (_cursorXY.x > 0f - edgeTolerance && _cursorXY.x < (float)sizeX + edgeTolerance &&
                 _cursorXY.y > 0f - edgeTolerance && _cursorXY.y < (float)sizeY + edgeTolerance)
        {
            _cursorValidity = CursorValidity.CloseToCell;
        }
        else
        {
            _cursorValidity = CursorValidity.Outside;
        }

        // Find cell nearest to cursor (assumes normalized cell size)
        Vector3 cellXY = new Vector3(Mathf.Clamp(_cursorXY.x, 0f, (float)(sizeX - 1)), Mathf.Clamp(_cursorXY.y, 0f, (float)(sizeY - 1)), 0f);

        _hoverCellX = (int)Mathf.Floor(cellXY.x);
        _hoverCellY = (int)Mathf.Floor(cellXY.y);

        _nearestEdgeID = EdgeID.None;
        if (_cursorValidity != CursorValidity.Outside)
        {
            Vector3 cellCenter = new Vector3(_hoverCellX + 0.5f, _hoverCellY + 0.5f, 0f);
            Vector3 ofs        = _cursorXY - cellCenter;

            if (ofs.y >= Mathf.Abs(ofs.x))
            {
                _nearestEdgeID = EdgeID.Top;
            }
            else if (ofs.y < -Mathf.Abs(ofs.x))
            {
                _nearestEdgeID = EdgeID.Bottom;
            }
            else if (ofs.x < 0f)
            {
                _nearestEdgeID = EdgeID.Left;
            }
            else
            {
                _nearestEdgeID = EdgeID.Right;
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            if (_nearestEdgeID != EdgeID.None)
            {
                int i = xyToIndex(_hoverCellX, _hoverCellY);
                // Debug.Log(string.Format("Cell {0}: [{1},{2}] {3}", i, _hoverCellX, _hoverCellY, _nearestEdgeID));

                int    neighborIndex  = -1;
                EdgeID neighborEdgeID = EdgeID.None;
                switch (_nearestEdgeID)
                {
                case EdgeID.Left:
                    if (_hoverCellX > 0)
                    {
                        neighborIndex = i - 1; neighborEdgeID = EdgeID.Right;
                    }
                    break;

                case EdgeID.Right:
                    if (_hoverCellX < sizeX - 1)
                    {
                        neighborIndex = i + 1; neighborEdgeID = EdgeID.Left;
                    }
                    break;

                case EdgeID.Bottom:
                    if (_hoverCellY > 0)
                    {
                        neighborIndex = i - sizeX; neighborEdgeID = EdgeID.Top;
                    }
                    break;

                case EdgeID.Top:
                    if (_hoverCellY < sizeY - 1)
                    {
                        neighborIndex = i + sizeX; neighborEdgeID = EdgeID.Bottom;
                    }
                    break;

                default:
                    break;
                }

                if (Input.GetKey(KeyCode.LeftControl))
                {
                    if (inEditMode)
                    {
                        // hide/show numbers
                        bool state = !_cells[i].showRequiredEdgeCount;
                        _cells[i].showRequiredEdgeCount = state;
                        _cellNumberMeshFilters[i].gameObject.SetActive(state);
                    }
                }
                else
                {
                    // update edge display
                    _cells[i].ToggleEdge(_nearestEdgeID);
                    _cellEdgeMeshFilters[i].sharedMesh = cellEdgeMeshes[(int)_cells[i].ActiveEdgeIDs];
                    if (neighborIndex != -1)
                    {
                        _cells[neighborIndex].ToggleEdge(neighborEdgeID);
                        _cellEdgeMeshFilters[neighborIndex].sharedMesh = cellEdgeMeshes[(int)_cells[neighborIndex].ActiveEdgeIDs];
                    }

                    if (inEditMode)
                    {
                        // only update edge count numbers in edit mode
                        _cellNumberMeshFilters[i].sharedMesh = cellNumberMeshes[_cells[i].CurrentEdgeCount];
                        if (neighborIndex != -1)
                        {
                            _cellNumberMeshFilters[neighborIndex].sharedMesh = cellNumberMeshes[_cells[neighborIndex].CurrentEdgeCount];
                        }
                    }
                    else
                    {
                        if (IsPuzzleClear())
                        {
                            Debug.Log("Puzzle is clear! Well done, you're a genius!");
                            timer.paused = true;
                        }
                    }
                }
            }
        }
    }
示例#15
0
        public void ToggleEdge(EdgeID edgeID)
        {
            bool state = ((_activeEdgeIDs & (byte)edgeID) > 0) ? false : true;

            SetEdge(edgeID, state);
        }