示例#1
0
 public DeserializationResult(Graph graph, XZPosInt chunkPosition, int minY, int maxY)
 {
     this.graph         = graph;
     this.chunkPosition = chunkPosition;
     this.chunkMinY     = minY;
     this.chunkMaxY     = maxY;
 }
        public void Triangulate(XZPosInt pos, AgentProperties properties, ref GraphCombiner combiner, NavMeshTemplateRecast template)
        {
            this.pos        = pos;
            this.properties = properties;
            this.combiner   = combiner;

            //Debug.Log(chunk == null);
            //Debug.Log(properties == null);


            MakeConnections(template);

#if UNITY_EDITOR
            if (Debuger_K.doDebug && Debuger_K.debugOnlyNavMesh == false)
            {
                DebugDataSets(pos, properties);
            }
#endif

            GenerateCells();
        }
        public void Triangulate(XZPosInt pos, AgentProperties properties, ref GraphCombiner combiner, NavMeshTemplateCreation template)
        {
#if UNITY_EDITOR
            //for debug
            this.pos        = pos;
            this.properties = properties;
#endif

            this.combiner = combiner;

            //Debug.Log(chunk == null);
            //Debug.Log(properties == null);
            if (profiler != null)
            {
                profiler.AddLog("Start make connections");
            }
            MakeConnections(template);
            if (profiler != null)
            {
                profiler.AddLog("End make connections");
            }

#if UNITY_EDITOR
            if (Debuger_K.doDebug && Debuger_K.debugOnlyNavMesh == false)
            {
                DebugDataSets(pos, properties);
            }
#endif
            if (profiler != null)
            {
                profiler.AddLog("Start Generate Cells");
            }
            GenerateCells();
            if (profiler != null)
            {
                profiler.AddLog("End Generate Cells");
            }
        }
示例#4
0
        protected void GetChunkValues(Vector3 pos, out Graph graph, out Cell cell, out Vector3 closestPoint, bool snapToNavMesh = false)
        {
            graph        = null;
            cell         = null;
            closestPoint = pos;

            HashSet <Graph> usedGraphs = new HashSet <Graph>();
            XZPosInt        startPos   = PathFinder.ToChunkPosition(pos.x, pos.z);

            ClearGraphList();

            //getting first graph
            Graph curGraph;

            while (true)
            {
                if (PathFinder.GetGraph(startPos, properties, out curGraph) && curGraph.canBeUsed)
                {
                    break;
                }
                else
                {
                    Thread.Sleep(30);
                }
            }
            AddGraphNode(new GraphPathSimple(curGraph, Vector3.Distance(pos, curGraph.positionCenter)));
            usedGraphs.Add(curGraph);

            for (int i = 0; i < 100; i++)
            {
                var node = TakeGraphNode();
                graph = node.graph;

                if (graph.empty == false)
                {
                    bool    outsideCell;
                    Vector3 ifOutsideCell;
                    graph.GetClosestCell(pos, out cell, out outsideCell, out ifOutsideCell);
                    if (snapToNavMesh | outsideCell)
                    {
                        closestPoint = ifOutsideCell;
                    }
                }

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

                        if (neighbourGraph != null && usedGraphs.Add(neighbourGraph))
                        {
                            AddGraphNode(new GraphPathSimple(neighbourGraph, Vector3.Distance(pos, neighbourGraph.positionCenter)));
                        }
                    }
                }
                else
                {
                    break;
                }
            }

            if (cell == null)
            {
                closestPoint = pos;
                Debug.LogError("there was 100 iterations and still no graph. are you trying to find path in middle of nowhere? if u r so smart than increase up number");
            }
        }