Ejemplo n.º 1
0
    public void Initialize(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW No graph to initialize!");
            return;
        }
        nodeViews = new NodeView[graph.Width, graph.Height];

        foreach (Node n in graph.nodes)
        {
            //create a nodeview for each corresponding node
            GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                nodeView.Initialize(n);

                //add each nodeview into array
                nodeViews[n.xIndex, n.yIndex] = nodeView;
                //this way can find each node crresponding to nodeview

                if (n.nodeType == NodeType.Blocked)
                {
                    nodeView.ColorNode(wallColor);
                }
                else
                {
                    nodeView.ColorNode(baseColor);
                }
            }
        }
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    public void Init(Graph graph)
    {
        nodeViews = new NodeView[graph.Width, graph.Height];
        foreach (var node in graph.nodes)
        {
            GameObject instance = Instantiate(nodeViewPrefab, node.position, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();
            if (nodeView == null)
            {
                Debug.LogError("Nodeview is missing");
                return;
            }

            nodeView.Init(node);

            nodeViews[node.xIndex, node.yIndex] = nodeView;

            if (node.nodeType == NodeType.Blocked)
            {
                nodeView.ColorNode(wallColor);
            }

            else if (node.nodeType == NodeType.Open)
            {
                nodeView.ColorNode(baseColor);
            }
        }
    }
Ejemplo n.º 3
0
    //Inicializa la vista del grafo
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHView No graph to initialize!");
            return;
        }

        nodeViews = new NodeView[graph.Width, graph.Height];

        //Recorre todos los nodos del grafo
        foreach (Node n in graph.nodes)
        {
            GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                //Cambia el color dependiendo del tipo
                nodeView.Init(n);
                nodeViews[n.xIndex, n.yIndex] = nodeView;

                if (n.nodeType == NodeType.Blocked)
                {
                    nodeView.ColorNode(wallColor);
                }
                else
                {
                    nodeView.ColorNode(baseColor);
                }
            }
        }
    }
Ejemplo n.º 4
0
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW No Graph to Initialize");
            return;
        }

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

            if (nodeView != null)
            {
                nodeView.Init(n);

                if (n.nodeType == NodeType.Blocked)
                {
                    nodeView.ColorNode(blockColor);
                }
                else
                {
                    nodeView.ColorNode(baseColor);
                }
            }
        }
    }
Ejemplo n.º 5
0
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("Need graph!");
        }
        nodeViews = new NodeView[graph.Width, graph.Height];

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

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

                if (n.nodeType == NodeType.Blocked)
                {
                    nodeView.ColorNode(wallColor);
                }
                else
                {
                    nodeView.ColorNode(baseColor);
                }
            }
        }
    }
Ejemplo n.º 6
0
 private void DebugDiagnostic(Node n, NodeView nodeView)
 {
     if (n.nodeType == NodeType.Blocked)
     {
         nodeView.ColorNode(wallColor);
     }
     else
     {
         nodeView.ColorNode(baseColor);
     }
 }
Ejemplo n.º 7
0
    public void ColorNodes(List <Node> nodes, Color color, bool lerpColor = false, float lerpValue = 0.5f)
    {
        foreach (Node n in nodes)
        {
            if (n != null)
            {
                NodeView nodeView = NodeViews[n.XIndex, n.YIndex];


                Color newColor = color;


                if (lerpColor)
                {
                    Color originalColor = MapData.GetColorFromNodeType(n.NodeType);


                    newColor = Color.Lerp(originalColor, newColor, lerpValue);
                }


                if (nodeView != null)
                {
                    nodeView.ColorNode(newColor);
                }
            }
        }
    }
Ejemplo n.º 8
0
    //public Color baseColor = Color.white;
    //public Color wallColor = Color.black;

    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GraphView No graph to initialise");
            return;
        }

        nodeViews = new NodeView[graph.Width, graph.Height];

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

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

                //if (n.nodeType == NodeType.Blocked)
                //{
                //    nodeView.ColorNode(wallColor);
                //}
                //else
                //{
                //    nodeView.ColorNode(baseColor);
                //}

                Color originalColor = MapData.GetColorFromNodeType(n.nodeType);
                nodeView.ColorNode(originalColor);
            }
        }
    }
Ejemplo n.º 9
0
    public void ShowColors(GraphView _graphView, Node _start, Node _goal, bool lerpColor = false, float lerpValue = 0.5f)
    {
        if (_graphView == null || _start == null || _goal == null)
        {
            return;
        }
        if (this.frontierNodes != null)
        {
            _graphView.ColorNodes(frontierNodes.ToList(), frontierNodesColor, lerpColor, lerpValue);
        }
        if (this.exploredNodes != null)
        {
            _graphView.ColorNodes(exploredNodes, exploredNodesColor, lerpColor, lerpValue);
        }
        if (this.pathNodes != null && pathNodes.Count > 0)
        {
            graphView.ColorNodes(this.pathNodes, pathNodeColor, lerpColor, lerpValue * 2f);
        }
        NodeView startNodeView = graphView.NodeViews[_start.XIndex, _start.YIndex];

        if (startNodeView != null)
        {
            startNodeView.ColorNode(this.startNodesColor);
        }
        NodeView goalNodeView = graphView.NodeViews[_goal.XIndex, _goal.YIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(this.goalNodesColor);
        }
    }
Ejemplo n.º 10
0
    // color a List of NodeViews, given a List of Nodes, optionally blending color with original color
    public void ColorNodes(List <Node> nodes, Color color, bool lerpColor = false, float lerpValue = 0.5f)
    {
        // for each Node...
        foreach (Node n in nodes)
        {
            if (n != null)
            {
                // find the corresponding NodeView
                NodeView nodeView = nodeViews[n.xIndex, n.yIndex];

                // default target color
                Color newColor = color;

                // if we are blending colors...
                if (lerpColor)
                {
                    // ... find the original color
                    Color originalColor = MapData.GetColorFromNodeType(n.nodeType);

                    // calculate the blended color
                    newColor = Color.Lerp(originalColor, newColor, lerpValue);
                }

                // color the NodeView
                if (nodeView != null)
                {
                    nodeView.ColorNode(newColor);
                }
            }
        }
    }
Ejemplo n.º 11
0
    void DisplayColors(GraphView graphView, Node start, Node goal)
    {
        if (graphView == null || start == null || goal == null)
        {
            Debug.Log("DisplayColors returned");
            return;
        }

        if (m_frontierNodes != null)
        {
            graphView.ColorNodes(m_frontierNodes.ToList(), frontierColor);
        }

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

        //Color Path
        if (m_pathNodes != null && m_pathNodes.Count > 0)
        {
            Debug.Log("Coloring Path");
            graphView.ColorNodes(m_pathNodes, pathColor);
        }

        NodeView startNodeView = graphView.nodeViews[start.xIndex, start.yIndex];
        NodeView goalNodeView  = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (startNodeView != null && goalNodeView != null)
        {
            startNodeView.ColorNode(startColor);
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 12
0
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW No graph to initialize!");
            return;
        }


        NodeViews = new NodeView[graph.Width, graph.Height];

        foreach (Node n in graph.Nodes)
        {
            GameObject instance = Instantiate(NodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                nodeView.Init(n);


                NodeViews[n.XIndex, n.YIndex] = nodeView;


                Color originalColor = MapData.GetColorFromNodeType(n.NodeType);


                nodeView.ColorNode(originalColor);
            }
        }
    }
 internal void ColorNodes(Queue <Node> nodes, Color color)
 {
     foreach (var n in nodes)
     {
         if (n != null)
         {
             NodeView nodeView = nodeViews[n.xIndex, n.yIndex];
             nodeView.ColorNode(color);
         }
     }
 }
 public void ColorNodes(List <Node> nodes, Color color)
 {
     foreach (var n in nodes)
     {
         if (n != null)
         {
             NodeView nodeView = nodeViews[n.xIndex, n.yIndex];
             nodeView.ColorNode(color);
         }
     }
 }
Ejemplo n.º 15
0
    ///<summary>Colors specific node to input color</summary>
    public void ColorNode(Node node, Color color)
    {
        if (node != null)
        {
            NodeView nodeView = NodesVisualized[node.XIndex, node.YIndex];
            Color    newColor = color;

            if (nodeView != null)
            {
                nodeView.ColorNode(newColor);
            }
        }
    }
 public void ColorNodes(List <Node> nodes, Color color, float lerValue)
 {
     foreach (var n in nodes)
     {
         if (n != null)
         {
             NodeView nodeView      = nodeViews[n.xIndex, n.yIndex];
             Color    newColor      = color;
             Color    originalColor = MapData.GetColorFromNodeType(n.nodeType);
             newColor = Color.Lerp(originalColor, newColor, lerValue);
             nodeView.ColorNode(newColor);
         }
     }
 }
Ejemplo n.º 17
0
    private void ColorStartAndGoalNodes()
    {
        NodeView startNodeView = m_graphView.nodeViews[m_startNode.xIndex, m_startNode.yIndex];
        NodeView goalNodeView  = m_graphView.nodeViews[m_goalNode.xIndex, m_goalNode.yIndex];

        if (startNodeView != null)
        {
            startNodeView.ColorNode(startColor);
        }
        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 18
0
    public void Init(Graph graph)
    {
        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW No Graph to initialize");
            return;
        }

        nodeViews = new NodeView[graph.Width, graph.Height];

        //In graph we create nodes[] based on the MapData
        foreach (Node n in graph.nodes)
        {
            GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();//from prefab get Nodeview ref

            if (nodeView != null)
            {
                nodeView.Init(n);
                //Allows to see each Node => NodeView
                nodeViews[n.xIndex, n.yIndex] = nodeView;//Add NodeView to Array using n
                if (n.nodeType == NodeType.Blocked)
                {
                    nodeView.ColorNode(wallColor);
                }
                else if (n.nodeType == NodeType.LightTerrain)
                {
                    nodeView.ColorNode(liteTerrainColor);
                }
                else
                {
                    nodeView.ColorNode(baseColor);
                }
            }
        }
    }
Ejemplo n.º 19
0
    ///<summary>Colors list of nodes to input color</summary>
    public void ColorNodes(List <Node> nodes, Color color)
    {
        foreach (Node node in nodes)
        {
            if (node != null)
            {
                NodeView nodeView = NodesVisualized[node.XIndex, node.YIndex];
                Color    newColor = color;

                if (nodeView != null)
                {
                    nodeView.ColorNode(newColor);
                }
            }
        }
    }
    public void Init(Graph graph, GraphView graphView, Node start, Node goal)
    {
        if (start == null || goal == null || graph == null || graphView == null)
        {
            Debug.LogWarning("Pathfinder info null (start goal graph pathview)");
            return;
        }

        if (start.nodeType == NodeType.blocked || goal.nodeType == NodeType.blocked)
        {
            Debug.LogWarning("start or node bloecked");
            return;
        }

        _graph     = graph;
        _graphView = graphView;
        startNode  = start;
        goalNode   = goal;

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

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

        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }

        frontierNodes = new Queue <Node>();
        frontierNodes.Enqueue(start);

        exploredNodes = new List <Node>();
        pathNodes     = new List <Node>();

        for (int x = 0; x < graph.width; x++)
        {
            for (int y = 0; y < graph.height; y++)
            {
                graph.nodes[x, y].Reset();
            }
        }
    }
Ejemplo n.º 21
0
    public void ColorStartGoalNodes(Node start, Node goal)
    {
        // color start NodeView and goal NodeView directly
        NodeView startNodeView = this.nodeViews[start.xIndex, start.yIndex];

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

        NodeView goalNodeView = this.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 22
0
    public void RebuildNodeViews(Graph graph, string tileId = "")
    {
        foreach (var n in graph.Nodes)
        {
            var      instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity, transform);
            NodeView nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                nodeView.SetFromNode(n);
                nodeView.xIndex     = n.xIndex;
                nodeView.yIndex     = n.yIndex;
                nodeView.tileId     = tileId;
                nodeView.tileColors = m_tileColors;

                Color originalColor = m_tileColors.GetNodeTypeColor(n.nodeType);
                nodeView.ColorNode(originalColor);
            }
        }
    }
Ejemplo n.º 23
0
    // color the initial NodeViews of the map (walls, open spaces)
    private void ColorMapNodes(Graph graph)
    {
        if (nodeViewPrefab == null)
        {
            Debug.LogWarning("GRAPHVIEW ColorMapNodes: Missing NodeViewPrefab!");
            return;
        }

        if (graph == null)
        {
            Debug.LogWarning("GRAPHVIEW ColorMapNodes: No graph to initialize!");
            return;
        }

        // setup array of NodeViews
        nodeViews = new NodeView[graph.Width, graph.Height];


        foreach (Node n in graph.nodes)
        {
            // create a NodeView for each corresponding Node

            GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity);
            NodeView   nodeView = instance.GetComponent <NodeView>();

            if (nodeView != null)
            {
                // initialize each NodeView
                nodeView.Init(n);

                // store each NodeView in the array
                nodeViews[n.xIndex, n.yIndex] = nodeView;

                // find the corresponding Color from the MapData
                Color originalColor = MapData.GetColorFromNodeType(n.nodeType);

                // color code the NodeView
                nodeView.ColorNode(originalColor);
            }
        }
    }
Ejemplo n.º 24
0
    /// <summary>
    /// Change the colors of nodes
    /// </summary>
    /// <param name="graphView"></param>
    /// <param name="start"></param>
    /// <param name="goal"></param>
    void ShowColors(GraphView graphView, Node start, Node goal, bool lerpColor = false, float lerpValue = 0.5f)
    {
        if (graphView == null || start == null || goal == null)
        {
            return;
        }

        // for diagnostic purposes
        if (m_frontierNodes != null)
        {
            graphView.ColorNodes(m_frontierNodes.ToList(), frontierColor, lerpColor, lerpValue);
        }

        // for diagnostic purposes
        if (m_exploredNodes != null)
        {
            graphView.ColorNodes(m_exploredNodes, exploredColor, lerpColor, lerpValue);
        }

        if (m_pathNodes != null && m_pathNodes.Count > 0)
        {
            graphView.ColorNodes(m_pathNodes, pathColor, lerpColor, lerpValue * 2f);
        }


        // Set up the start node
        NodeView startNodeView = graphView.nodeViews[start.xIndex, start.yIndex];

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

        // Set up the goal node
        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 25
0
    void ShowColors(GraphView graphView, Node start, Node goal)
    {
        if (graphView == null || start == null || goal == null)
        {
            return;
        }

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

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

        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 26
0
    public void ColorNodes(List <Node> nodes, Color color, bool lerpColor = false, float lerpValue = 0.5f)
    {
        foreach (Node n in nodes)
        {
            if (n != null)
            {
                NodeView nodeView = m_nodeViews[n.xIndex, n.yIndex];
                Color    newColor = color;

                if (lerpColor)
                {
                    Color originalColor = m_tileColors.GetNodeTypeColor(n.nodeType);
                    newColor = Color.Lerp(originalColor, newColor, lerpValue);
                }

                if (nodeView != null)
                {
                    nodeView.ColorNode(newColor);
                }
            }
        }
    }
Ejemplo n.º 27
0
    private void ShowColors(GraphView graphView, Node start, Node goal)
    {
        if (graphView == null || start == null || goal == null)
        {
            return;
        }


        if (m_frontierNodes != null)
        {
            graphView.ColorNodes(m_frontierNodes.ToList(), frontierColor);
        }

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


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

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

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

        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
    private void ShowColors(GraphView graphView, Node start, Node goal)
    {
        if (start == null || goal == null || graphView == null)
        {
            Debug.LogWarning("PATHFINDER Init error: missing component(s)!");
            return;
        }

        if (m_frontierNodes != null)
        {
            graphView.ColorNodes(m_frontierNodes.ToList(), frontierColor);
        }

        if (m_exploreNodes != null)
        {
            graphView.ColorNodes(m_exploreNodes, exploredColor, 0.5f);
        }

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

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

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

        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 29
0
    private void ShowColors(GraphView graphView, Node start, Node goal,
                            bool lerpColor = false, float lerpValue = 0.5f)
    {
        if (start == null || goal == null || graph == null || graphView == null)
        {
            return;
        }

        if (frontierNodes != null)
        {
            graphView.ColorNodes(frontierNodes.ToList(), frontierColor, lerpColor, lerpValue);
        }

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

        if (pathNodes != null && pathNodes.Count > 0)
        {
            graphView.ColorNodes(pathNodes, pathColor, lerpColor, lerpValue * 2f);
        }

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

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

        NodeView goalNodeView = graphView.nodeViews[goal.xIndex, goal.yIndex];

        if (goalNodeView != null)
        {
            goalNodeView.ColorNode(goalColor);
        }
    }
Ejemplo n.º 30
0
    public void Init(Graph graph, GraphView graphView, Node startNode, Node endNode)
    {
        if (startNode.nodeType == NodeType.Blocked || endNode.nodeType == NodeType.Blocked)
        {
            Debug.LogError("Start or End node is blocked.");
            return;
        }

        m_graph     = graph;
        m_graphView = graphView;
        m_startNode = startNode;
        m_endNode   = endNode;


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

        m_frontierNodes = new Queue <Node>();
        m_frontierNodes.Enqueue(startNode);
        m_exploredNodes = new List <Node>();
        m_pathNodes     = new List <Node>();


        for (int yIndex = 0; yIndex < graph.Height; yIndex++)
        {
            for (int xIndex = 0; xIndex < graph.Width; xIndex++)
            {
                graph.nodes[xIndex, yIndex].Reset();
            }
        }

        startNodeView.ColorNode(startColor);
        endNodeView.ColorNode(endColor);

        ShowColors();
    }