예제 #1
0
        protected void AddGraphNode(GraphPathSimple node)
        {
            LinkedListNode <GraphPathSimple> targetNode = null;

            for (LinkedListNode <GraphPathSimple> currentPath = linkedGraph.First;
                 currentPath != null && currentPath.Value.cost < node.cost;
                 currentPath = currentPath.Next)
            {
                targetNode = currentPath;
            }

            if (targetNode == null)
            {
                linkedGraph.AddFirst(node);
            }
            else
            {
                linkedGraph.AddAfter(targetNode, node);
            }
        }
        private void CheckChunkPath()
        {
            Vector3 closestPos;

            GetChunkValues(end_v3, out endGraph, out endCell, out closestPos, snapToNavMesh);

#if UNITY_EDITOR
            if (Debuger_K.debugPath)
            {
                Debuger_K.AddLine(end_v3, closestPos, Color.red);
                Debuger_K.AddLine(end_v3, endCell.centerV3, Color.cyan);
            }
#endif

            end_v3 = closestPos;

            if (PathFinder.ToChunkPosition(start_v3) == PathFinder.ToChunkPosition(end_v3))
            {
                return;
            }

            VectorInt.Vector2Int targetPosition = endGraph.positionChunk;
            ClearGraphList();

            AddGraphNode(new GraphPathSimple(startGraph, Vector2.Distance(start_v3, end_v3)));
            HashSet <Graph> usedGraphs = new HashSet <Graph>();

            for (int v = 0; v < 10; v++)
            {
                if (base.linkedGraph.Count == 0)
                {
                    UnityEngine.Debug.Log("no path. count");
                    break;
                }

                GraphPathSimple current      = TakeGraphNode();
                Graph           currentGraph = current.graph;

                //Debuger3.AddLine(start_v3, currentGraph.positionWorldCenter, Color.red);
                //Debuger3.AddLabel(currentGraph.positionWorldCenter, linkedGrap.Count);

                if (currentGraph.positionChunk == targetPosition)
                {
                    break;
                }

                for (int dir = 0; dir < 4; dir++)
                {
                    Graph neighbourGraph;
                    while (true)
                    {
                        if (PathFinder.GetGraphFrom(currentGraph.gridPosition, (Directions)dir, properties, out neighbourGraph) && neighbourGraph.canBeUsed)
                        {
                            break;
                        }
                        Thread.Sleep(10);
                    }

                    if (neighbourGraph != null && usedGraphs.Contains(neighbourGraph) == false)
                    {
                        AddGraphNode(new GraphPathSimple(neighbourGraph, Vector3.Distance(end_v3, neighbourGraph.positionCenter)));
                        usedGraphs.Add(neighbourGraph);
                    }
                }
            }

            if (endGraph == null)
            {
                Debug.LogWarning("graph path > 500");
                Debug.LogWarning("chunk path result are null");
                return;
            }
        }