示例#1
0
 public void OnGUI()
 {
     if (!this.show || (!Application.isPlaying && !this.showInEditor))
     {
         return;
     }
     if (this.style == null)
     {
         this.style = new GUIStyle();
         this.style.normal.textColor = Color.white;
         this.style.padding          = new RectOffset(5, 5, 5, 5);
     }
     if (Time.realtimeSinceStartup - this.lastUpdate > 0.5f || this.cachedText == null || !Application.isPlaying)
     {
         this.lastUpdate  = Time.realtimeSinceStartup;
         this.boxRect     = new Rect(5f, (float)this.yOffset, 310f, 40f);
         this.text.Length = 0;
         this.text.AppendLine("A* Pathfinding Project Debugger");
         this.text.Append("A* Version: ").Append(AstarPath.Version.ToString());
         if (this.showMemProfile)
         {
             this.boxRect.height = this.boxRect.height + 200f;
             this.text.AppendLine();
             this.text.AppendLine();
             this.text.Append("Currently allocated".PadRight(25));
             this.text.Append(((float)this.allocMem / 1000000f).ToString("0.0 MB"));
             this.text.AppendLine();
             this.text.Append("Peak allocated".PadRight(25));
             this.text.Append(((float)this.peakAlloc / 1000000f).ToString("0.0 MB")).AppendLine();
             this.text.Append("Last collect peak".PadRight(25));
             this.text.Append(((float)this.collectAlloc / 1000000f).ToString("0.0 MB")).AppendLine();
             this.text.Append("Allocation rate".PadRight(25));
             this.text.Append(((float)this.allocRate / 1000000f).ToString("0.0 MB")).AppendLine();
             this.text.Append("Collection frequency".PadRight(25));
             this.text.Append(this.delta.ToString("0.00"));
             this.text.Append("s\n");
             this.text.Append("Last collect fps".PadRight(25));
             this.text.Append((1f / this.lastDeltaTime).ToString("0.0 fps"));
             this.text.Append(" (");
             this.text.Append(this.lastDeltaTime.ToString("0.000 s"));
             this.text.Append(")");
         }
         if (this.showFPS)
         {
             this.text.AppendLine();
             this.text.AppendLine();
             this.text.Append("FPS".PadRight(25)).Append((1f / this.delayedDeltaTime).ToString("0.0 fps"));
             float num = float.PositiveInfinity;
             for (int i = 0; i < this.fpsDrops.Length; i++)
             {
                 if (this.fpsDrops[i] < num)
                 {
                     num = this.fpsDrops[i];
                 }
             }
             this.text.AppendLine();
             this.text.Append(("Lowest fps (last " + this.fpsDrops.Length + ")").PadRight(25)).Append(num.ToString("0.0"));
         }
         if (this.showPathProfile)
         {
             AstarPath active = AstarPath.active;
             this.text.AppendLine();
             if (active == null)
             {
                 this.text.Append("\nNo AstarPath Object In The Scene");
             }
             else
             {
                 if (ListPool <Vector3> .GetSize() > this.maxVecPool)
                 {
                     this.maxVecPool = ListPool <Vector3> .GetSize();
                 }
                 if (ListPool <GraphNode> .GetSize() > this.maxNodePool)
                 {
                     this.maxNodePool = ListPool <GraphNode> .GetSize();
                 }
                 this.text.Append("\nPool Sizes (size/total created)");
                 for (int j = 0; j < this.debugTypes.Length; j++)
                 {
                     this.debugTypes[j].Print(this.text);
                 }
             }
         }
         this.cachedText = this.text.ToString();
     }
     if (this.font != null)
     {
         this.style.font     = this.font;
         this.style.fontSize = this.fontSize;
     }
     this.boxRect.height = this.style.CalcHeight(new GUIContent(this.cachedText), this.boxRect.width);
     GUI.Box(this.boxRect, string.Empty);
     GUI.Label(this.boxRect, this.cachedText, this.style);
     if (this.showGraph)
     {
         float num2 = float.PositiveInfinity;
         float num3 = 0f;
         float num4 = float.PositiveInfinity;
         float num5 = 0f;
         for (int k = 0; k < this.graph.Length; k++)
         {
             num2 = Mathf.Min(this.graph[k].memory, num2);
             num3 = Mathf.Max(this.graph[k].memory, num3);
             num4 = Mathf.Min(this.graph[k].fps, num4);
             num5 = Mathf.Max(this.graph[k].fps, num5);
         }
         GUI.color = Color.blue;
         float num6 = (float)Mathf.RoundToInt(num3 / 100000f);
         GUI.Label(new Rect(5f, (float)Screen.height - AstarMath.MapTo(num2, num3, 0f + this.graphOffset, this.graphHeight + this.graphOffset, num6 * 1000f * 100f) - 10f, 100f, 20f), (num6 / 10f).ToString("0.0 MB"));
         num6 = Mathf.Round(num2 / 100000f);
         GUI.Label(new Rect(5f, (float)Screen.height - AstarMath.MapTo(num2, num3, 0f + this.graphOffset, this.graphHeight + this.graphOffset, num6 * 1000f * 100f) - 10f, 100f, 20f), (num6 / 10f).ToString("0.0 MB"));
         GUI.color = Color.green;
         num6      = Mathf.Round(num5);
         GUI.Label(new Rect(55f, (float)Screen.height - AstarMath.MapTo(num4, num5, 0f + this.graphOffset, this.graphHeight + this.graphOffset, num6) - 10f, 100f, 20f), num6.ToString("0 FPS"));
         num6 = Mathf.Round(num4);
         GUI.Label(new Rect(55f, (float)Screen.height - AstarMath.MapTo(num4, num5, 0f + this.graphOffset, this.graphHeight + this.graphOffset, num6) - 10f, 100f, 20f), num6.ToString("0 FPS"));
     }
 }
示例#2
0
    public void Update()
    {
        if (!this.show || (!Application.isPlaying && !this.showInEditor))
        {
            return;
        }
        int num = GC.CollectionCount(0);

        if (this.lastCollectNum != (float)num)
        {
            this.lastCollectNum = (float)num;
            this.delta          = Time.realtimeSinceStartup - this.lastCollect;
            this.lastCollect    = Time.realtimeSinceStartup;
            this.lastDeltaTime  = Time.deltaTime;
            this.collectAlloc   = this.allocMem;
        }
        this.allocMem = (int)GC.GetTotalMemory(false);
        bool flag = this.allocMem < this.peakAlloc;

        this.peakAlloc = (flag ? this.peakAlloc : this.allocMem);
        if (Time.realtimeSinceStartup - this.lastAllocSet > 0.3f || !Application.isPlaying)
        {
            int num2 = this.allocMem - this.lastAllocMemory;
            this.lastAllocMemory  = this.allocMem;
            this.lastAllocSet     = Time.realtimeSinceStartup;
            this.delayedDeltaTime = Time.deltaTime;
            if (num2 >= 0)
            {
                this.allocRate = num2;
            }
        }
        if (Application.isPlaying)
        {
            this.fpsDrops[Time.frameCount % this.fpsDrops.Length] = ((Time.deltaTime == 0f) ? float.PositiveInfinity : (1f / Time.deltaTime));
            int num3 = Time.frameCount % this.graph.Length;
            this.graph[num3].fps          = ((Time.deltaTime >= 1.401298E-45f) ? (1f / Time.deltaTime) : 0f);
            this.graph[num3].collectEvent = flag;
            this.graph[num3].memory       = (float)this.allocMem;
        }
        if (Application.isPlaying && this.cam != null && this.showGraph)
        {
            this.graphWidth = this.cam.pixelWidth * 0.8f;
            float num4 = float.PositiveInfinity;
            float num5 = 0f;
            float num6 = float.PositiveInfinity;
            float num7 = 0f;
            for (int i = 0; i < this.graph.Length; i++)
            {
                num4 = Mathf.Min(this.graph[i].memory, num4);
                num5 = Mathf.Max(this.graph[i].memory, num5);
                num6 = Mathf.Min(this.graph[i].fps, num6);
                num7 = Mathf.Max(this.graph[i].fps, num7);
            }
            int       num8 = Time.frameCount % this.graph.Length;
            Matrix4x4 m    = Matrix4x4.TRS(new Vector3((this.cam.pixelWidth - this.graphWidth) / 2f, this.graphOffset, 1f), Quaternion.identity, new Vector3(this.graphWidth, this.graphHeight, 1f));
            for (int j = 0; j < this.graph.Length - 1; j++)
            {
                if (j != num8)
                {
                    this.DrawGraphLine(j, m, (float)j / (float)this.graph.Length, (float)(j + 1) / (float)this.graph.Length, AstarMath.MapTo(num4, num5, this.graph[j].memory), AstarMath.MapTo(num4, num5, this.graph[j + 1].memory), Color.blue);
                    this.DrawGraphLine(j, m, (float)j / (float)this.graph.Length, (float)(j + 1) / (float)this.graph.Length, AstarMath.MapTo(num6, num7, this.graph[j].fps), AstarMath.MapTo(num6, num7, this.graph[j + 1].fps), Color.green);
                }
            }
        }
    }
示例#3
0
    public void Update()
    {
        if (!show || (!Application.isPlaying && !showInEditor))
        {
            return;
        }

        int collCount = System.GC.CollectionCount(0);

        if (lastCollectNum != collCount)
        {
            lastCollectNum = collCount;
            delta          = Time.realtimeSinceStartup - lastCollect;
            lastCollect    = Time.realtimeSinceStartup;
            lastDeltaTime  = Time.deltaTime;
            collectAlloc   = allocMem;
        }

        allocMem = (int)System.GC.GetTotalMemory(false);

        bool collectEvent = allocMem < peakAlloc;

        peakAlloc = !collectEvent ? allocMem : peakAlloc;

        if (Time.realtimeSinceStartup - lastAllocSet > 0.3F || !Application.isPlaying)
        {
            int diff = allocMem - lastAllocMemory;
            lastAllocMemory  = allocMem;
            lastAllocSet     = Time.realtimeSinceStartup;
            delayedDeltaTime = Time.deltaTime;

            if (diff >= 0)
            {
                allocRate = diff;
            }
        }

        if (Application.isPlaying)
        {
            fpsDrops[Time.frameCount % fpsDrops.Length] = Time.deltaTime != 0 ? 1F / Time.deltaTime : float.PositiveInfinity;
            int graphIndex = Time.frameCount % graph.Length;
            graph[graphIndex].fps          = Time.deltaTime < Mathf.Epsilon ? 0 : 1F / Time.deltaTime;
            graph[graphIndex].collectEvent = collectEvent;
            graph[graphIndex].memory       = allocMem;
        }

        if (Application.isPlaying && cam != null && showGraph)
        {
            graphWidth = cam.pixelWidth * 0.8f;


            float minMem = float.PositiveInfinity, maxMem = 0, minFPS = float.PositiveInfinity, maxFPS = 0;
            for (int i = 0; i < graph.Length; i++)
            {
                minMem = Mathf.Min(graph[i].memory, minMem);
                maxMem = Mathf.Max(graph[i].memory, maxMem);
                minFPS = Mathf.Min(graph[i].fps, minFPS);
                maxFPS = Mathf.Max(graph[i].fps, maxFPS);
            }

            int currentGraphIndex = Time.frameCount % graph.Length;

            Matrix4x4 m = Matrix4x4.TRS(new Vector3((cam.pixelWidth - graphWidth) / 2f, graphOffset, 1), Quaternion.identity, new Vector3(graphWidth, graphHeight, 1));

            for (int i = 0; i < graph.Length - 1; i++)
            {
                if (i == currentGraphIndex)
                {
                    continue;
                }

                //Debug.DrawLine (m.MultiplyPoint (new Vector3 (i/(float)graph.Length, Mathfx.MapTo (minMem, maxMem, graph[i].memory), -1)),
                //	m.MultiplyPoint (new Vector3 ((i+1)/(float)graph.Length, Mathfx.MapTo (minMem, maxMem, graph[i+1].memory), -1)), Color.blue);

                //Debug.DrawLine (m.MultiplyPoint (Vector3.zero), m.MultiplyPoint (-Vector3.one), Color.red);
                //Debug.Log (Mathfx.MapTo (minMem, maxMem, graph[i].memory)  + " " + graph[i].memory);
                DrawGraphLine(i, m, i / (float)graph.Length, (i + 1) / (float)graph.Length, AstarMath.MapTo(minMem, maxMem, graph[i].memory), AstarMath.MapTo(minMem, maxMem, graph[i + 1].memory), Color.blue);

                DrawGraphLine(i, m, i / (float)graph.Length, (i + 1) / (float)graph.Length, AstarMath.MapTo(minFPS, maxFPS, graph[i].fps), AstarMath.MapTo(minFPS, maxFPS, graph[i + 1].fps), Color.green);

                //Debug.DrawLine (m.MultiplyPoint (new Vector3 (i/(float)graph.Length, Mathfx.MapTo (minFPS, maxFPS, graph[i].fps), -1)),
                //	m.MultiplyPoint (new Vector3 ((i+1)/(float)graph.Length, Mathfx.MapTo (minFPS, maxFPS, graph[i+1].fps), -1)), Color.green);
            }



            /*Cross (new Vector3(0,0,1));
             * Cross (new Vector3(1,1,1));
             * Cross (new Vector3(0,1,1));
             * Cross (new Vector3(1,0,1));
             * Cross (new Vector3(-1,0,1));
             * Debug.DrawLine (m.MultiplyPoint(Vector3.zero), m.MultiplyPoint(new Vector3(0,0,-5)),Color.blue);*/
        }
    }
示例#4
0
    public void OnGUI()
    {
        if (!show || (!Application.isPlaying && !showInEditor))
        {
            return;
        }

        if (style == null)
        {
            style = new GUIStyle();
            style.normal.textColor = Color.white;
            style.padding          = new RectOffset(5, 5, 5, 5);
        }

        if (Time.realtimeSinceStartup - lastUpdate > 0.5f || cachedText == null || !Application.isPlaying)
        {
            lastUpdate = Time.realtimeSinceStartup;

            boxRect = new Rect(5, yOffset, 310, 40);

            text.Length = 0;
            text.AppendLine("A* Pathfinding Project Debugger");
            text.Append("A* Version: ").Append(AstarPath.Version.ToString());

            if (showMemProfile)
            {
                boxRect.height += 200;

                text.AppendLine();
                text.AppendLine();
                text.Append("Currently allocated".PadRight(25));
                text.Append((allocMem / 1000000F).ToString("0.0 MB"));
                text.AppendLine();

                text.Append("Peak allocated".PadRight(25));
                text.Append((peakAlloc / 1000000F).ToString("0.0 MB")).AppendLine();

                text.Append("Last collect peak".PadRight(25));
                text.Append((collectAlloc / 1000000F).ToString("0.0 MB")).AppendLine();


                text.Append("Allocation rate".PadRight(25));
                text.Append((allocRate / 1000000F).ToString("0.0 MB")).AppendLine();

                text.Append("Collection frequency".PadRight(25));
                text.Append(delta.ToString("0.00"));
                text.Append("s\n");

                text.Append("Last collect fps".PadRight(25));
                text.Append((1F / lastDeltaTime).ToString("0.0 fps"));
                text.Append(" (");
                text.Append(lastDeltaTime.ToString("0.000 s"));
                text.Append(")");
            }

            if (showFPS)
            {
                text.AppendLine();
                text.AppendLine();
                text.Append("FPS".PadRight(25)).Append((1F / delayedDeltaTime).ToString("0.0 fps"));


                float minFps = Mathf.Infinity;

                for (int i = 0; i < fpsDrops.Length; i++)
                {
                    if (fpsDrops[i] < minFps)
                    {
                        minFps = fpsDrops[i];
                    }
                }

                text.AppendLine();
                text.Append(("Lowest fps (last " + fpsDrops.Length + ")").PadRight(25)).Append(minFps.ToString("0.0"));
            }

            if (showPathProfile)
            {
                AstarPath astar = AstarPath.active;

                text.AppendLine();

                if (astar == null)
                {
                    text.Append("\nNo AstarPath Object In The BattleScene");
                }
                else
                {
#if ProfileAstar
                    double searchSpeed = (double)AstarPath.TotalSearchedNodes * 10000 / (double)AstarPath.TotalSearchTime;

                    text.Append("\nSearch Speed	(nodes/ms)	").Append(searchSpeed.ToString("0")).Append(" (" + AstarPath.TotalSearchedNodes + " / ").Append(((double)AstarPath.TotalSearchTime / 10000F).ToString("0") + ")");
#endif

                    if (Pathfinding.Util.ListPool <Vector3> .GetSize() > maxVecPool)
                    {
                        maxVecPool = Pathfinding.Util.ListPool <Vector3> .GetSize();
                    }
                    if (Pathfinding.Util.ListPool <Pathfinding.GraphNode> .GetSize() > maxNodePool)
                    {
                        maxNodePool = Pathfinding.Util.ListPool <Pathfinding.GraphNode> .GetSize();
                    }

                    text.Append("\nPool Sizes (size/total created)");

                    for (int i = 0; i < debugTypes.Length; i++)
                    {
                        debugTypes[i].Print(text);
                    }
                }
            }

            cachedText = text.ToString();
        }


        if (font != null)
        {
            style.font     = font;
            style.fontSize = fontSize;
        }

        boxRect.height = style.CalcHeight(new GUIContent(cachedText), boxRect.width);

        GUI.Box(boxRect, "");
        GUI.Label(boxRect, cachedText, style);

        if (showGraph)
        {
            float minMem = float.PositiveInfinity, maxMem = 0, minFPS = float.PositiveInfinity, maxFPS = 0;
            for (int i = 0; i < graph.Length; i++)
            {
                minMem = Mathf.Min(graph[i].memory, minMem);
                maxMem = Mathf.Max(graph[i].memory, maxMem);
                minFPS = Mathf.Min(graph[i].fps, minFPS);
                maxFPS = Mathf.Max(graph[i].fps, maxFPS);
            }

            float line;
            GUI.color = Color.blue;
            //Round to nearest x.x MB
            line = Mathf.RoundToInt(maxMem / (100.0f * 1000));          // *1000*100
            GUI.Label(new Rect(5, Screen.height - AstarMath.MapTo(minMem, maxMem, 0 + graphOffset, graphHeight + graphOffset, line * 1000 * 100) - 10, 100, 20), (line / 10.0f).ToString("0.0 MB"));



            line = Mathf.Round(minMem / (100.0f * 1000));          // *1000*100
            GUI.Label(new Rect(5, Screen.height - AstarMath.MapTo(minMem, maxMem, 0 + graphOffset, graphHeight + graphOffset, line * 1000 * 100) - 10, 100, 20), (line / 10.0f).ToString("0.0 MB"));


            GUI.color = Color.green;
            //Round to nearest x.x MB
            line = Mathf.Round(maxFPS);              // *1000*100
            GUI.Label(new Rect(55, Screen.height - AstarMath.MapTo(minFPS, maxFPS, 0 + graphOffset, graphHeight + graphOffset, line) - 10, 100, 20), (line).ToString("0 FPS"));



            line = Mathf.Round(minFPS);              // *1000*100
            GUI.Label(new Rect(55, Screen.height - AstarMath.MapTo(minFPS, maxFPS, 0 + graphOffset, graphHeight + graphOffset, line) - 10, 100, 20), (line).ToString("0 FPS"));
        }
    }
示例#5
0
 public void Update()
 {
     if (this.show && (Application.isPlaying || this.showInEditor))
     {
         int num = GC.CollectionCount(0);
         if (this.lastCollectNum != num)
         {
             this.lastCollectNum = num;
             this.delta          = Time.realtimeSinceStartup - this.lastCollect;
             this.lastCollect    = Time.realtimeSinceStartup;
             this.lastDeltaTime  = Time.deltaTime;
             this.collectAlloc   = this.allocMem;
         }
         this.allocMem = (int)GC.GetTotalMemory(false);
         bool flag = this.allocMem < this.peakAlloc;
         this.peakAlloc = flag ? this.peakAlloc : this.allocMem;
         if (((Time.realtimeSinceStartup - this.lastAllocSet) > 0.3f) || !Application.isPlaying)
         {
             int num2 = this.allocMem - this.lastAllocMemory;
             this.lastAllocMemory  = this.allocMem;
             this.lastAllocSet     = Time.realtimeSinceStartup;
             this.delayedDeltaTime = Time.deltaTime;
             if (num2 >= 0)
             {
                 this.allocRate = num2;
             }
         }
         if (Application.isPlaying)
         {
             this.fpsDrops[Time.frameCount % this.fpsDrops.Length] = (Time.deltaTime == 0f) ? float.PositiveInfinity : (1f / Time.deltaTime);
             int index = Time.frameCount % this.graph.Length;
             this.graph[index].fps          = (Time.deltaTime >= float.Epsilon) ? (1f / Time.deltaTime) : 0f;
             this.graph[index].collectEvent = flag;
             this.graph[index].memory       = this.allocMem;
         }
         if ((Application.isPlaying && (this.cam != null)) && this.showGraph)
         {
             this.graphWidth = this.cam.pixelWidth * 0.8f;
             float positiveInfinity = float.PositiveInfinity;
             float b    = 0f;
             float num6 = float.PositiveInfinity;
             float num7 = 0f;
             for (int i = 0; i < this.graph.Length; i++)
             {
                 positiveInfinity = Mathf.Min(this.graph[i].memory, positiveInfinity);
                 b    = Mathf.Max(this.graph[i].memory, b);
                 num6 = Mathf.Min(this.graph[i].fps, num6);
                 num7 = Mathf.Max(this.graph[i].fps, num7);
             }
             int       num9 = Time.frameCount % this.graph.Length;
             Matrix4x4 m    = Matrix4x4.TRS(new Vector3((this.cam.pixelWidth - this.graphWidth) / 2f, this.graphOffset, 1f), Quaternion.identity, new Vector3(this.graphWidth, this.graphHeight, 1f));
             for (int j = 0; j < (this.graph.Length - 1); j++)
             {
                 if (j != num9)
                 {
                     this.DrawGraphLine(j, m, ((float)j) / ((float)this.graph.Length), ((float)(j + 1)) / ((float)this.graph.Length), AstarMath.MapTo(positiveInfinity, b, this.graph[j].memory), AstarMath.MapTo(positiveInfinity, b, this.graph[j + 1].memory), Color.blue);
                     this.DrawGraphLine(j, m, ((float)j) / ((float)this.graph.Length), ((float)(j + 1)) / ((float)this.graph.Length), AstarMath.MapTo(num6, num7, this.graph[j].fps), AstarMath.MapTo(num6, num7, this.graph[j + 1].fps), Color.green);
                 }
             }
         }
     }
 }