Exemplo n.º 1
0
        private bool HasLiberties(Topology.Face face)
        {
            var color = _faceBoardStates[face];

            if (color == BoardState.Empty)
            {
                return(true);
            }

            bool hasLiberties = false;

            TopologyVisitor.VisitFaces(face, (FaceVisitor visitor) =>
            {
                var visitColor = _faceBoardStates[visitor.face];
                if (visitColor == BoardState.Empty)
                {
                    hasLiberties = true;
                    visitor.Break();
                }
                else if (visitColor == color)
                {
                    visitor.VisitInternalNeighbors();
                }
            });

            return(hasLiberties);
        }
 private IEnumerable <Topology.FaceEdge> EnumerateFaceNeighborEdges(Topology.Face face)
 {
     foreach (var edge in face.edges)
     {
         yield return(edge);
     }
 }
Exemplo n.º 3
0
 private float CostHeuristic(Topology.Face source, Topology.Face target, int pathLength)
 {
     if (source.isExternal || target.isExternal)
     {
         return(float.PositiveInfinity);
     }
     return(Vector3.Distance(_facePositions[source], _facePositions[target]));
 }
Exemplo n.º 4
0
 public void OnPickStart(Topology.Face face, int button)
 {
     if (button == 0 && face.isInternal)
     {
         ClearPreviousPickState();
         _startFace = face;
         DrawCurrentPickState(face);
         _dynamicMesh.RebuildMesh(DynamicMesh.VertexAttributes.Normal | DynamicMesh.VertexAttributes.Color);
     }
 }
Exemplo n.º 5
0
 private void PickEnd(int button)
 {
     if (_picking[button] == true)
     {
         var endFace = _currentFace;
         _picking[button] = false;
         if ((_picking[0] || _picking[1] || _picking[2]) == false)
         {
             _currentFace = Topology.Face.none;
         }
         OnPickEnd.Invoke(endFace, button);
     }
 }
Exemplo n.º 6
0
 public void OnPickChange(Topology.Face previousFace, Topology.Face currentFace)
 {
     if (_activeFace)
     {
         if (currentFace == _activeFace)
         {
             Select(_activeFace);
         }
         else
         {
             Deselect(_activeFace);
         }
     }
 }
Exemplo n.º 7
0
        private void PickChange(Vector2 mousePosition)
        {
            GeneralUtility.DisableAndThrowOnUnassignedReference(this, partitioning, "The FaceSpatialPartitioningPicker component requires a reference to a UniversalFaceSpatialPartitioning scriptable object.  Either create a saved asset using generators available in the Assets/Create/Topology menu, or create and assign one at runtime before the picker's Start() event runs.");

            var ray  = Geometry.InverseTransformRay(transform, camera.ScreenPointToRay(mousePosition));
            var face = partitioning.FindFace(ray);

            if (face && _currentFace != face)
            {
                var previousFace = _currentFace;
                _currentFace = face;
                OnPickChange.Invoke(previousFace, face);
            }
        }
Exemplo n.º 8
0
        public void OnPickEnd(Topology.Face endFace, int button)
        {
            if (button == 0)
            {
                if (endFace == _activeFace && IsLegalMove(_activeFace))
                {
                    MakeMove(_activeFace);
                }

                if (_activeFace)
                {
                    Deselect(_activeFace);
                    _activeFace = Topology.Face.none;
                }
            }
        }
Exemplo n.º 9
0
        public void OnPickStart(Topology.Face startFace, int button)
        {
            if (!_gameActive || startFace.isExternal)
            {
                return;
            }

            if (button == 0)
            {
                if (_activeFace && _activeFace != startFace)
                {
                    Deselect(_activeFace);
                }
                Select(startFace);
                _activeFace = startFace;
            }
        }
Exemplo n.º 10
0
 private void DrawCurrentPickState(Topology.Face currentFace)
 {
     if (_startFace)
     {
         if (_startFace == currentFace)
         {
             _dynamicMesh.RebuildFace(_startFace, _triangulationPressed);
         }
         else if (_path != null && _path.Count > 0)
         {
             foreach (var face in _path.AsFacePath())
             {
                 _dynamicMesh.RebuildFace(face, _triangulationPath);
             }
         }
     }
 }
Exemplo n.º 11
0
        public void OnPickChange(Topology.Face oldFace, Topology.Face newFace)
        {
            if (_startFace)
            {
                ClearPreviousPickState();

                if (newFace == _startFace || newFace.isExternal || _faceBlockedStates[_startFace] == true || _faceBlockedStates[newFace] == true)
                {
                    _path = null;
                }
                else
                {
                    _path = _pathFinder.FindPath(_startFace, newFace, CostHeuristic, Cost, _path);
                }

                DrawCurrentPickState(newFace);
                _dynamicMesh.RebuildMesh(DynamicMesh.VertexAttributes.Normal | DynamicMesh.VertexAttributes.Color);
            }
        }
Exemplo n.º 12
0
        private void PickStart(Vector2 mousePosition, int button)
        {
            GeneralUtility.DisableAndThrowOnUnassignedReference(this, partitioning, "The FaceSpatialPartitioningPicker component requires a reference to a UniversalFaceSpatialPartitioning scriptable object.  Either create a saved asset using generators available in the Assets/Create/Topology menu, or create and assign one at runtime before the picker's Start() event runs.");

            var ray       = Geometry.InverseTransformRay(transform, camera.ScreenPointToRay(mousePosition));
            var startFace = partitioning.FindFace(ray);

            if (startFace)
            {
                _currentFace     = startFace;
                _picking[button] = true;
                OnPickStart.Invoke(startFace, button);
            }
            else
            {
                _picking[button] = false;
                _currentFace     = Topology.Face.none;
            }
        }
Exemplo n.º 13
0
        private void ClearBlockedFaces(Topology.Face face)
        {
            _faceBlockedStates[face] = false;
            _dynamicMesh.RebuildFace(face, _triangulationNormal);

            TopologyVisitor.VisitFacesInBreadthFirstOrder(face,
                                                          (FaceVisitor visitor) =>
            {
                if (_faceBlockedStates[visitor.face] == true)
                {
                    _faceBlockedStates[visitor.face] = false;
                    _dynamicMesh.RebuildFace(visitor.face, _triangulationNormal);
                }

                if (visitor.depth < clearRadius)
                {
                    visitor.VisitInternalNeighbors();
                }
            });
        }
Exemplo n.º 14
0
        public void OnPickEnd(Topology.Face face, int button)
        {
            if (button == 0 && _startFace)
            {
                ClearPreviousPickState();

                if (face == _startFace)
                {
                    ClearBlockedFaces(_startFace);
                }
                else if (_path != null && _path.Count > 0)
                {
                    BlockPathFaces(_path);
                }

                _path      = null;
                _startFace = Topology.Face.none;
                _dynamicMesh.RebuildMesh(DynamicMesh.VertexAttributes.Normal | DynamicMesh.VertexAttributes.Color);
            }
        }