Beispiel #1
0
        private void CreatePoint(Vector3 pos)
        {
            GameObject point = Instantiate(NavGraphPoint, pos, Quaternion.identity);

            Points.Add(point);
            NodeInfoComponent nodeInfoComponent = point.AddComponent <NodeInfoComponent>();

            nodeInfoComponent.Index = PointIndex;
            point.gameObject.name  += PointIndex++;
            point.SetActive(true);
        }
Beispiel #2
0
        private int GetNodeIndex(Vector3 position, Vector3 dir)
        {
            int        nodeIndex = -1;
            RaycastHit hit;

            if (Physics.Raycast(position, dir, out hit, MaxEdgeLenght) && IsNode(hit))
            {
                NodeInfoComponent nodeInfoComponentComponent =
                    hit.transform.gameObject.GetComponent <NodeInfoComponent>();
                nodeIndex = nodeInfoComponentComponent.Index;
            }

            return(nodeIndex);
        }
Beispiel #3
0
 public void CreateGraph()
 {
     CreateVisualGraph();
     Graph = new Graph <NavGraphNode, GraphEdge>();
     for (int i = 0; i < Points.Count; i++)
     {
         NodeInfoComponent nodeInfo = Points[i].GetComponent <NodeInfoComponent>();
         Graph.AddNode(new NavGraphNode(nodeInfo.Index, Points[i].transform.position, nodeInfo.ExtraInfo));
         for (int j = 0; j < nodeInfo.ConnectedNodes.Count; j++)
         {
             float distanceBetweenNodes = Vector2.Distance(Points[nodeInfo.Index].transform.position,
                                                           Points[nodeInfo.ConnectedNodes[j]].transform.position);
             Graph.AddEdge(new GraphEdge(nodeInfo.Index, nodeInfo.ConnectedNodes[j], distanceBetweenNodes),
                           nodeInfo.Index);
         }
     }
 }
Beispiel #4
0
        private void AddConectedNodes(int node, int conectedNode)
        {
            NodeInfoComponent nodeInfoComponent = Points[node].GetComponent <NodeInfoComponent>();

            nodeInfoComponent.AddConnectedNode(conectedNode);
        }