/// <summary>
    /// 恢复寻路新增节点导致的变化
    /// </summary>
    private void RestoreNodeBackup(HierarchicalMap map, int nodeId, NodeBackup backup)
    {
        AbstractGraph graph = map.AbstractGraph;
        AbstractNode  node  = graph.GetNode(nodeId);

        //恢复节点的级别
        node.Level = backup.Level;

        //恢复相关的边
        graph.RemoveEdgeFromAndToNode(nodeId);
        foreach (var edge in backup.Edges)
        {
            int targetNodeId = edge.TargetNodeId;
            var targetNode   = map.GetAbstractNode(targetNodeId);

            AbstractEdge abstractEdge = HPADemo.Instance.CreateEdge(node.Pos, targetNode.Pos, edge.Level, edge.IsInterEdge);
            abstractEdge.Init(targetNodeId, edge.Cost, edge.Level, edge.IsInterEdge);
            abstractEdge.SetInnerLowerLevelPath(edge.InnerLowerLevelPath);
            graph.AddEdge(nodeId, abstractEdge);

            edge.InnerLowerLevelPath?.Reverse();

            abstractEdge = HPADemo.Instance.CreateEdge(targetNode.Pos, node.Pos, edge.Level, edge.IsInterEdge);
            abstractEdge.Init(nodeId, edge.Cost, edge.Level, edge.IsInterEdge);
            abstractEdge.SetInnerLowerLevelPath(edge.InnerLowerLevelPath);
            graph.AddEdge(targetNodeId, abstractEdge);
        }

        m_backupDict.Remove(nodeId);
    }
示例#2
0
    /// <summary>
    /// 构建指定层级节点间的边
    /// </summary>
    private void AddEdgesBetweenAbstractNodes(int absId1, int absId2, int level)
    {
        var node1 = AbstractGraph.GetNode(absId1);
        var node2 = AbstractGraph.GetNode(absId2);

        var planner = new PathPlanner(this, null);
        var path    = planner.Search(node1, node2);

        if (path != null && path.Nodes.Count > 0)
        {
            AbstractEdge edge = HPADemo.Instance.CreateEdge(node1.Pos, node2.Pos, level, false);
            edge.Init(absId2, path.Cost, level, false);
            edge.SetInnerLowerLevelPath(path.Nodes);
            AbstractGraph.AddEdge(absId1, edge);

            path.Nodes.Reverse();

            edge = HPADemo.Instance.CreateEdge(node2.Pos, node1.Pos, level, false);
            edge.Init(absId1, path.Cost, level, false);
            edge.SetInnerLowerLevelPath(path.Nodes);
            AbstractGraph.AddEdge(absId2, edge);
        }
    }