示例#1
0
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW: No graph to initialize!");
            return;
        }
        nodeViews = new NodeView[graph.GetWidth(), graph.GetHeight()];

        foreach (Node node in graph.nodes)
        {
            GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                nodeView.Init(node);
                nodeViews[node.xIndex, node.yIndex] = nodeView;

                if (node.nodeType == NodeType.Blocked)
                {
                    nodeView.ChangeNodeColor(wallColor);
                }
                else
                {
                    nodeView.ChangeNodeColor(baseColor);
                }
            }
        }
    }
示例#2
0
    private void ShowColors(GraphView graphView, Node startNode, Node endNode)
    {
        if (frontierNodes != null)
        {
            graphView.ColorNodes(frontierNodes.ToList(), frontierColor);
        }

        if (exploredNodes != null)
        {
            graphView.ColorNodes(exploredNodes, exploredColor);
        }


        if (pathNodes != null && pathNodes.Count > 0)
        {
            graphView.ColorNodes(pathNodes, pathColor);
        }

        NodeView startNodeView = graphView.nodeViews[startNode.xIndex, startNode.yIndex];

        if (startNodeView != null)
        {
            startNodeView.ChangeNodeColor(startColor);
        }

        NodeView endNodeView = graphView.nodeViews[endNode.xIndex, endNode.yIndex];

        if (endNodeView != null)
        {
            endNodeView.ChangeNodeColor(endColor);
        }
    }
示例#3
0
    public void ColorNodes(List <Node> nodes, Color color)
    {
        foreach (Node node in nodes)
        {
            if (node != null)
            {
                NodeView nodeView = nodeViews[node.xIndex, node.yIndex];

                if (nodeView != null)
                {
                    nodeView.ChangeNodeColor(color);
                }
            }
        }
    }