public static MapTo ( float startMin, float startMax, float value ) : float | ||
startMin | float | |
startMax | float | |
value | float | |
return | float |
public void LateUpdate() { if (!this.show || (!Application.isPlaying && !this.showInEditor)) { return; } if (Time.unscaledDeltaTime <= 0.0001f) { 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.unscaledDeltaTime; 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.unscaledDeltaTime; if (num2 >= 0) { this.allocRate = num2; } } if (Application.isPlaying) { this.fpsDrops[Time.frameCount % this.fpsDrops.Length] = ((Time.unscaledDeltaTime <= 1E-05f) ? 0f : (1f / Time.unscaledDeltaTime)); int num3 = Time.frameCount % this.graph.Length; this.graph[num3].fps = ((Time.unscaledDeltaTime >= 1E-05f) ? 0f : (1f / Time.unscaledDeltaTime)); this.graph[num3].collectEvent = flag; this.graph[num3].memory = (float)this.allocMem; } if (Application.isPlaying && this.cam != null && this.showGraph) { this.graphWidth = (float)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(((float)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); } } } }
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(); var delayedFPS = delayedDeltaTime > 0.00001f ? 1F / delayedDeltaTime : 0; text.Append("FPS".PadRight(25)).Append(delayedFPS.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 Scene"); } 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)); 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)); 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); 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); GUI.Label(new Rect(55, Screen.height - AstarMath.MapTo(minFPS, maxFPS, 0 + graphOffset, graphHeight + graphOffset, line) - 10, 100, 20), line.ToString("0 FPS")); } }
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(); float num = (this.delayedDeltaTime <= 1E-05f) ? 0f : (1f / this.delayedDeltaTime); this.text.Append("FPS".PadRight(25)).Append(num.ToString("0.0 fps")); float num2 = float.PositiveInfinity; for (int i = 0; i < this.fpsDrops.Length; i++) { if (this.fpsDrops[i] < num2) { num2 = this.fpsDrops[i]; } } this.text.AppendLine(); this.text.Append(("Lowest fps (last " + this.fpsDrops.Length + ")").PadRight(25)).Append(num2.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 num3 = float.PositiveInfinity; float num4 = 0f; float num5 = float.PositiveInfinity; float num6 = 0f; for (int k = 0; k < this.graph.Length; k++) { num3 = Mathf.Min(this.graph[k].memory, num3); num4 = Mathf.Max(this.graph[k].memory, num4); num5 = Mathf.Min(this.graph[k].fps, num5); num6 = Mathf.Max(this.graph[k].fps, num6); } GUI.color = Color.blue; float num7 = (float)Mathf.RoundToInt(num4 / 100000f); GUI.Label(new Rect(5f, (float)Screen.height - AstarMath.MapTo(num3, num4, this.graphOffset, this.graphHeight + this.graphOffset, num7 * 1000f * 100f) - 10f, 100f, 20f), (num7 / 10f).ToString("0.0 MB")); num7 = Mathf.Round(num3 / 100000f); GUI.Label(new Rect(5f, (float)Screen.height - AstarMath.MapTo(num3, num4, this.graphOffset, this.graphHeight + this.graphOffset, num7 * 1000f * 100f) - 10f, 100f, 20f), (num7 / 10f).ToString("0.0 MB")); GUI.color = Color.green; num7 = Mathf.Round(num6); GUI.Label(new Rect(55f, (float)Screen.height - AstarMath.MapTo(num5, num6, this.graphOffset, this.graphHeight + this.graphOffset, num7) - 10f, 100f, 20f), num7.ToString("0 FPS")); num7 = Mathf.Round(num5); GUI.Label(new Rect(55f, (float)Screen.height - AstarMath.MapTo(num5, num6, this.graphOffset, this.graphHeight + this.graphOffset, num7) - 10f, 100f, 20f), num7.ToString("0 FPS")); } }
public void LateUpdate() { if (!show || (!Application.isPlaying && !showInEditor)) { return; } if (Time.unscaledDeltaTime <= 0.0001f) { return; } int collCount = System.GC.CollectionCount(0); if (lastCollectNum != collCount) { lastCollectNum = collCount; delta = Time.realtimeSinceStartup - lastCollect; lastCollect = Time.realtimeSinceStartup; lastDeltaTime = Time.unscaledDeltaTime; 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.unscaledDeltaTime; if (diff >= 0) { allocRate = diff; } } if (Application.isPlaying) { fpsDrops[Time.frameCount % fpsDrops.Length] = Time.unscaledDeltaTime > 0.00001f ? 1F / Time.unscaledDeltaTime : 0; int graphIndex = Time.frameCount % graph.Length; graph[graphIndex].fps = Time.unscaledDeltaTime < 0.00001f ? 1F / Time.unscaledDeltaTime : 0; 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; } 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); } } }