コード例 #1
0
ファイル: Pathfinding.cs プロジェクト: Glecun/automata
    private PathNode getPathNodeOfNearest(int startX, int startY, IGridObjectType gridObjectType)
    {
        PathNode startNode = grid.GetGridObject(startX, startY);

        if (startNode == null)
        {
            // Invalid Path
            return(null);
        }

        openList = new List <PathNode> {
            startNode
        };
        closedList = new List <PathNode>();

        while (openList.Count > 0)
        {
            PathNode currentNode = GetLowestFCostNode(openList);

            openList.Remove(currentNode);
            closedList.Add(currentNode);

            if (currentNode.referenceToObjects.Exists(referenceToObject =>
                                                      referenceToObject.gridObjectType.Equals(gridObjectType)))
            {
                return(currentNode);
            }

            foreach (PathNode neighbourNode in GetNeighbourList(currentNode))
            {
                if (closedList.Contains(neighbourNode))
                {
                    continue;
                }

                if (!neighbourNode.isWalkable && !neighbourNode.referenceToObjects.Exists(referenceToObject =>
                                                                                          referenceToObject.gridObjectType.Equals(gridObjectType)))
                {
                    closedList.Add(neighbourNode);
                    continue;
                }

                if (!openList.Contains(neighbourNode))
                {
                    openList.Add(neighbourNode);
                }
            }
        }

        // Out of nodes on the openList
        return(null);
    }
コード例 #2
0
ファイル: PathInProgress.cs プロジェクト: Glecun/automata
    public static PathInProgress setPathToNearest(int2 start, IGridObjectType gridObjectType, Pathfinding pathfinding)
    {
        List <Vector3> pathVectorList;
        MonoBehaviour  objectController;

        pathfinding.FindPathToNearest(start.x, start.y, gridObjectType, out pathVectorList, out objectController);

        if (pathVectorList != null && pathVectorList.Count > 1)
        {
            pathVectorList.RemoveAt(0);
        }

        return(new PathInProgress(0, pathVectorList, objectController));
    }
コード例 #3
0
ファイル: Pathfinding.cs プロジェクト: Glecun/automata
    public void FindPathToNearest(int startX, int startY, IGridObjectType gridObjectType, out List <Vector3> vectorPath,
                                  out MonoBehaviour monoBehaviour)
    {
        var pathNodeOfNearest = getPathNodeOfNearest(startX, startY, gridObjectType);

        if (pathNodeOfNearest != null)
        {
            vectorPath    = FindPath(startX, startY, pathNodeOfNearest.x, pathNodeOfNearest.y);
            monoBehaviour = pathNodeOfNearest.referenceToObjects
                            .Find(referenceToObject => referenceToObject.gridObjectType.Equals(gridObjectType)).objectController;
        }
        else
        {
            vectorPath    = null;
            monoBehaviour = null;
        }
    }
コード例 #4
0
ファイル: GridScript.cs プロジェクト: Glecun/automata
    public PathInProgress calculatePathToNearest(int2 start, IGridObjectType gridObjectType)
    {
        var pathfinding = new Pathfinding(width, height, cellSize, grid);

        return(PathInProgress.setPathToNearest(start, gridObjectType, pathfinding));
    }
コード例 #5
0
    public MonoBehaviour getIfInRange(IGridObjectType gridObject)
    {
        var pathInProgress = goToNearest(gridObject);

        return(isInRange(pathInProgress) ? pathInProgress.destinationobj : null);
    }
コード例 #6
0
    public PathInProgress goToNearest(IGridObjectType gridObjectType)
    {
        var start = getPosition();

        return(gameSceneController.grid.calculatePathToNearest(start, gridObjectType));
    }
コード例 #7
0
ファイル: GridObject.cs プロジェクト: Glecun/automata
 public ReferenceToObject(IGridObjectType gridObjectType, MonoBehaviour objectController)
 {
     this.gridObjectType   = gridObjectType;
     this.objectController = objectController;
 }