//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); } } }
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); } } }
public void Init(Graph graph) { if (graph == null) { Debug.LogWarning("GraphView: No graph to initialize!"); return; } //if (initialized || nodeViewInstances.Count == 0) return; foreach (GameObject go in nodeViewInstances) { Destroy(go); } nodeViews = new NodeView[graph.Width, graph.Height]; foreach (Node n in graph.nodes) { GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity); nodeViewInstances.Add(instance); NodeView nodeView = instance.GetComponent <NodeView>(); if (nodeView != null) { nodeView.Init(n); nodeViews[n.xIndex, n.yIndex] = nodeView; } } initialized = true; }
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); } } } }
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); } } } }
public void Initialize([NotNull] Graph graph) { if (graph == null) { return; } Views = new NodeView[graph.Width, graph.Height]; foreach (var node in graph.Nodes) { var instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity, transform); instance.name = nodeViewPrefab.name; var nodeView = instance.GetComponent <NodeView>(); if (nodeView == null) { continue; } nodeView.Initialize(node); Views[node.Index.x, node.Index.y] = nodeView; var color = mapData.GetColorFromNodeType(node); nodeView.ColorNode(color); } }
//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); } } } }
// 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); } } }
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); } } } }
///<summary>Initializes visual graph</summary> public void Init(Graph graph) { if (graph == null) { Debug.LogWarning("No graph to initialize!"); return; } NodesVisualized = new NodeView[graph.Width, graph.Height]; GameObject parent = new GameObject(); parent.name = "NodeGroup"; parent.transform.position = Vector3.zero; foreach (Node node in graph.Nodes) { GameObject instance = Instantiate(_nodePrefab, Vector3.zero, _nodePrefab.transform.rotation); instance.transform.SetParent(parent.transform); NodeView nodeVisualized = instance.GetComponent <NodeView>(); if (nodeVisualized != null) { nodeVisualized.Init(node); NodesVisualized[node.XIndex, node.YIndex] = nodeVisualized; Color color = MapData.GetColorByNodeType(node.NodeType); ColorNode(node, color); } } SetupCamera(graph.Width, graph.Height, _borderSize); }
public void Construct(Graph graph) { if (graph == null) { Debug.LogWarning($"No graph"); return; } nodeViews = new NodeView[graph.Width, graph.Height]; foreach (var node in graph.nodes) { var instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity); var nodeView = instance.GetComponent <NodeView>(); if (nodeView != null) { nodeView.Construct(node); nodeViews[node.xIndex, node.yIndex] = nodeView; if (node.nodeType == NodeType.Blocked) { nodeView.ColorNode(wallColor); } else if (node.nodeType == NodeType.Open) { nodeView.ColorNode(baseColor); } } } }
public CheckerboardView(Transform parent) { m_BgSprite = new GameObject("Checkerboard").AddComponent <SpriteRenderer>(); m_BgSprite.transform.SetParent(parent, Vector3.zero, Quaternion.identity, Vector3.one); m_BgSprite.sprite = SpriteUtil.BgSprite; m_BgSprite.sortingOrder = -1; m_BgSprite.gameObject.AddComponent <BoxCollider2D>(); m_TouchBoardWidget = m_BgSprite.gameObject.AddComponent <TouchBoardWidget>(); Transform nodeParent = new GameObject("nodeMatrix").transform; nodeParent.SetParent(parent, Vector3.zero, Quaternion.identity, Vector3.one); m_NodeMatrix = new NodeView[ValueUtil.GridRow, ValueUtil.GridColumn]; m_MaxGridSign = ValueUtil.GridRow * ValueUtil.GridColumn; float x = ValueUtil.GridInitX; float y = ValueUtil.GridInitY; for (int i = 0; i < ValueUtil.GridRow; i++) { y = ValueUtil.GridInitY - ValueUtil.GridOffset * i; for (int j = 0; j < ValueUtil.GridColumn; j++) { x = ValueUtil.GridInitX + ValueUtil.GridOffset * j; Transform nodeTrans = new GameObject("Node_" + i + "_" + j).transform; nodeTrans.SetParent(nodeParent, new Vector3(x, y), Quaternion.identity, Vector3.one); NodeView nodeView = nodeTrans.gameObject.AddComponent <NodeView>(); nodeView.AnimationMoveFinished += OnGridMoveFinished; nodeView.AnimationZoomFinished += OnGridZoomFinish; m_NodeMatrix[i, j] = nodeView; } // end for } // end for } // end CheckerboardView
public void Init(Graph graph, NodeView[] nodeViews) { m_graph = graph; m_nodeViews = new NodeView[m_graph.width, m_graph.height]; foreach (var view in nodeViews) { Color originalColor = m_tileColors.GetNodeTypeColor(view.nodeType); view.tileColors = m_tileColors; view.ColorNode(originalColor); } }
/// <summary> /// Create the graph grid (visual) /// </summary> private void CreateGraph() { // setup array of NodeViews nodeViews = new NodeView[graphWidth, graphHeight]; foreach (Node n in nodes) { // create a NodeView for each corresponding Node GameObject instance = Instantiate(nodeViewPrefab, Vector3.zero, Quaternion.identity); NodeView nodeView = instance.GetComponent <NodeView>(); nodeView.Init(n); // store each NodeView in the array nodeViews[n.xIndex, n.yIndex] = nodeView; } }
private void Start() { var grid = _manager.Grid; _nodeViews = new NodeView[grid.Width, grid.Height]; for (int i = 0; i < grid.Width; i++) { for (int j = 0; j < grid.Height; j++) { _nodeViews[i, j] = Instantiate(_nodePrefab, new Vector3(i, j, 0), Quaternion.identity, transform).GetComponent <NodeView>(); _nodeViews[i, j].GetComponent <NodeView>().Init(grid.Nodes[i, j]); _nodeViews[i, j].GetComponent <NodeView>().Clicked += OnNodeViewClicked; } } _manager.PathfindingFinished += OnPathfindingFinished; _manager.StartNodeSet += OnSetStartNode; _manager.EndNodeSet += OnSetEndNode; }
// 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); } } }
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); } } } }