コード例 #1
0
 public void Draw(Color color, float height)
 {
     Debuger_K.AddLine(minVector3, new Vector3(maxX, height, minY), color);
     Debuger_K.AddLine(minVector3, new Vector3(minX, height, maxY), color);
     Debuger_K.AddLine(maxVector3, new Vector3(maxX, height, minY), color);
     Debuger_K.AddLine(maxVector3, new Vector3(minX, height, maxY), color);
 }
コード例 #2
0
        public static void SceneDebug()
        {
            Debuger_K.ClearGeneric();

            float   gs  = PathFinder.gridSize;
            Vector3 add = new Vector3(gs * 0.5f, 0, gs * 0.5f);

            StringBuilder sb = new StringBuilder();

            foreach (var item in content)
            {
                sb.AppendLine(item.Value.lastUpdate.ToString());
            }

            Debuger_K.AddLabelFormat(new Vector3(startX * gs, 0, startZ * gs), "Map space {0}\nCount {1}\n{2}", mapSpace, content.Count, sb);

            for (int x = startX; x < endX + 1; x++)
            {
                Debuger_K.AddLine(new Vector3(x, 0, startZ) * gs, new Vector3(x, 0, endZ) * gs, Color.blue);
            }

            for (int z = startZ; z < endZ + 1; z++)
            {
                Debuger_K.AddLine(new Vector3(startX, 0, z) * gs, new Vector3(endX, 0, z) * gs, Color.blue);
            }

            System.Random random = new System.Random();

            for (int x = startX; x < endX; x++)
            {
                for (int z = startZ; z < endZ; z++)
                {
                    ChunkContent content;
                    TryGetChunkContent(x, z, out content);

                    Vector3 p = (new Vector3(x, 0, z) * gs) + add;

                    Debuger_K.AddLabelFormat(p, "x: {0}\nz: {1}", x, z);

                    Color color = new Color(1, 0, 0, 0.1f);
                    if (content != null && content.Count != 0)
                    {
                        color = new Color(0, 1, 0, 0.1f);
                    }

                    Debuger_K.AddTriangle(new Vector3(x, 0, z) * gs, (new Vector3(x + 1, 0, z) * gs), (new Vector3(x, 0, z + 1) * gs), color, false);
                    Debuger_K.AddTriangle(new Vector3(x + 1, 0, z + 1) * gs, (new Vector3(x + 1, 0, z) * gs), (new Vector3(x, 0, z + 1) * gs), color, false);

                    if (content != null && content.Count != 0)
                    {
                        Color cColor = new Color(random.Next(100) / 100f, random.Next(100) / 100f, random.Next(100) / 100f, 1f);
                        foreach (var item in content)
                        {
                            Debuger_K.AddBounds(item.chunkContentBounds, cColor);
                            Debuger_K.AddLine(p, item.chunkContentBounds.center, cColor);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void CellTester(Vector3 origin, AgentProperties properties)
        {
            Graph graph;

            if (TryGetGraph(ToChunkPosition(origin), properties, out graph) == false || graph.canBeUsed == false)
            {
                return;
            }

            Cell    cell;
            bool    outsideCell;
            Vector3 closestPosToCell;

            graph.GetClosestCell(origin, out cell, out outsideCell, out closestPosToCell);

            foreach (var pair in cell.dataContentPairs)
            {
                Debuger_K.AddLine(pair.Key, Color.magenta);

                if (pair.Value == null)
                {
                    continue;
                }

                Cell connection = pair.Value.connection;
                Debuger_K.AddLabel(pair.Key.centerV3, connection.Contains(pair.Key));
            }
        }
コード例 #4
0
        void DrawBranchRecursive(QuadTreeBranch branch, float offset = 0f, float offsetDelta = 0f)
        {
            if (branch == null)
            {
                return;
            }

            Bounds2D branchBounds = branch.bounds;

            Debuger_K.AddBounds(branchBounds, Color.green);

            Vector3 curPos = branchBounds.centerVector3;

            for (int i = 0; i < branch.list.Count; i++)
            {
                Bounds2D countentBounds = branch.list[i].bounds;
                Debuger_K.AddBounds(countentBounds, Color.blue);
                Debuger_K.AddLine(curPos, countentBounds.centerVector3, Color.magenta);
            }

            for (int i = 0; i < 4; i++)
            {
                if (branch.branches[i] != null)
                {
                    DrawBranchRecursive(branch.branches[i]);
                }
            }
        }
コード例 #5
0
        void Update()
        {
            if (properties == null)
            {
                return;
            }

            RaycastHit raycastHit;

            if (!Physics.Raycast(transform.position, Vector3.down, out raycastHit, 10))
            {
                return;
            }

            Vector3 p = raycastHit.point;

            Debug.DrawLine(transform.position, p, Color.red);

            //Debuger_K.ClearGeneric();

            RaycastHitNavMesh raycastHitNavMesh;

            for (int i = 0; i < tests; i++)
            {
                float x = Mathf.Cos((i / (float)tests) * 2 * Mathf.PI);
                float z = Mathf.Sin((i / (float)tests) * 2 * Mathf.PI);

                //var q = Quaternion.LookRotation(transform.forward + new Vector3(x, 0, z), Vector3.up);

                PathFinder.Raycast(p, new Vector3(x, 0, z), properties, out raycastHitNavMesh);
                if (raycastHitNavMesh.isOnGraph)
                {
                    Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue);
                    Debuger_K.AddLabel(raycastHitNavMesh.point, "H");
                }
            }

            //PathFinder.Raycast(p, transform.forward * -1, properties, out raycastHitNavMesh);
            //if (raycastHitNavMesh.isOnGraph) {
            //    Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue);
            //    Debuger_K.AddLabel(raycastHitNavMesh.point, "B");
            //}
            //PathFinder.Raycast(p, transform.transform.right * -1, properties, out raycastHitNavMesh);
            //if (raycastHitNavMesh.isOnGraph) {
            //    Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue);
            //    Debuger_K.AddLabel(raycastHitNavMesh.point, "L");
            //}
            //PathFinder.Raycast(p, transform.right, properties, out raycastHitNavMesh);
            //if (raycastHitNavMesh.isOnGraph) {
            //    Debuger_K.AddLine(p, raycastHitNavMesh.point, Color.blue);
            //    Debuger_K.AddLabel(raycastHitNavMesh.point, "R");
            //}
        }
コード例 #6
0
 public void DebugByDebuger()
 {
     for (int i = 0; i < pathNodes.Count; i++)
     {
         Debuger_K.AddDot(pathNodes[i], Color.red);
         Debuger_K.AddLabelFormat(pathNodes[i], "{0} {1}", i, pathNodes[i]);
     }
     for (int i = 0; i < pathNodes.Count - 1; i++)
     {
         Debuger_K.AddLine(pathNodes[i], pathNodes[i + 1], Color.red);
     }
 }
コード例 #7
0
        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;
            }
        }
コード例 #8
0
        public void DebugMe(bool drawMax = true, bool drawMin = true, bool drawMaxMinSize = true)
        {
            Vector3 realChunkPos = template.realOffsetedPosition;
            Vector3 offset       = template.halfVoxelOffset;

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    int gen   = 0;
                    int index = (z * sizeX) + x;

                    var current = arrayData[index];

                    if (current.next == -2)
                    {
                        continue;
                    }

                    while (true)
                    {
                        Vector3 p1 = realChunkPos + offset + new Vector3((x * template.voxelSize), current.max, (z * template.voxelSize));
                        Vector3 p2 = realChunkPos + offset + new Vector3((x * template.voxelSize), current.min, (z * template.voxelSize));

                        Color dColor;
                        switch (current.pass)
                        {
                        case -1:
                            dColor = Color.black;
                            break;

                        case 0:
                            dColor = Color.red;
                            break;

                        case 1:
                            dColor = Color.magenta;
                            break;

                        case 2:
                            dColor = new Color(0f, 0.5f, 0f, 1f);
                            break;

                        case 3:
                            dColor = Color.green;
                            break;

                        default:
                            dColor = Color.white;
                            break;
                        }
                        //Debuger_K.AddLabelFormat(p2 + (new Vector3(0.005f, 0.005f, 0.005f) * gen), "{0}", gen);
                        //Debuger_K.AddLabelFormat(p2 + (new Vector3(0.005f, 0.005f, 0.005f) * gen), "{0}\n{1}\n{2}", gen, curVal.max, curVal.min);

                        if (drawMax)
                        {
                            Debuger_K.AddDot(p1, dColor, 0.02f);
                        }

                        if (drawMin)
                        {
                            Debuger_K.AddDot(p2, Color.gray, 0.02f);
                        }

                        if (drawMaxMinSize)
                        {
                            Debuger_K.AddLine(p1, p2);
                        }

                        gen++;
                        if (current.next == -1)
                        {
                            break;
                        }
                        else
                        {
                            current = arrayData[current.next];
                        }
                    }
                }
            }
        }