Exemple #1
0
        protected void OnGUI()
        {
            if (m_simulation == null)
            {
                return;
            }

            if (!NativeHandler.Instance.HasValidLicense)
            {
                GUILayout.Window(GUIUtility.GetControlID(FocusType.Passive),
                                 new Rect(new Vector2(16,
                                                      0.5f * Screen.height),
                                          new Vector2(Screen.width - 32, 32)),
                                 id =>
                {
                    // Invalid license if initialized.
                    if (NativeHandler.Instance.Initialized && agx.Runtime.instance().getStatus().Length > 0)
                    {
                        GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: " + agx.Runtime.instance().getStatus(),
                                                            Color.red,
                                                            18,
                                                            true),
                                        Utils.GUI.Skin.label);
                    }
                    else
                    {
                        GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: Errors occurred during initialization of AGX Dynamics.",
                                                            Color.red,
                                                            18,
                                                            true),
                                        Utils.GUI.Skin.label);
                    }
                },
                                 "AGX Dynamics not properly initialized",
                                 Utils.GUI.Skin.window);

                return;
            }

            if (m_statisticsWindowData == null)
            {
                return;
            }

            var simColor      = Color.Lerp(Color.white, Color.blue, 0.2f);
            var spaceColor    = Color.Lerp(Color.white, Color.green, 0.2f);
            var dynamicsColor = Color.Lerp(Color.white, Color.yellow, 0.2f);
            var eventColor    = Color.Lerp(Color.white, Color.cyan, 0.2f);
            var dataColor     = Color.Lerp(Color.white, Color.magenta, 0.2f);
            var memoryColor   = Color.Lerp(Color.white, Color.red, 0.2f);

            var labelStyle         = m_statisticsWindowData.LabelStyle;
            var stats              = agx.Statistics.instance();
            var simTime            = stats.getTimingInfo("Simulation", "Step forward time");
            var spaceTime          = stats.getTimingInfo("Simulation", "Collision-detection time");
            var dynamicsSystemTime = stats.getTimingInfo("Simulation", "Dynamics-system time");
            var preCollideTime     = stats.getTimingInfo("Simulation", "Pre-collide event time");
            var preTime            = stats.getTimingInfo("Simulation", "Pre-step event time");
            var postTime           = stats.getTimingInfo("Simulation", "Post-step event time");
            var lastTime           = stats.getTimingInfo("Simulation", "Last-step event time");

            var numBodies      = m_system.getRigidBodies().Count;
            var numShapes      = m_space.getGeometries().Count;
            var numConstraints = m_system.getConstraints().Count +
                                 m_space.getGeometryContacts().Count;

            GUILayout.Window(m_statisticsWindowData.Id,
                             DisplayMemoryAllocations ? m_statisticsWindowData.RectMemoryEnabled : m_statisticsWindowData.Rect,
                             id =>
            {
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Total time:            ", simColor) + simTime.current.ToString("0.00").PadLeft(5, ' ') + " ms", 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre-collide step:      ", eventColor) + preCollideTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Collision detection:   ", spaceColor) + spaceTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre step:              ", eventColor) + preTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Dynamics solvers:      ", dynamicsColor) + dynamicsSystemTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post step:             ", eventColor) + postTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Last step:             ", eventColor) + lastTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Data:                  ", dataColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Update frequency:      ", dataColor) + (int)(1.0f / TimeStep + 0.5f) + " Hz"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of bodies:      ", dataColor) + numBodies), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of shapes:      ", dataColor) + numShapes), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of constraints: ", dataColor) + numConstraints), labelStyle);
                GUILayout.Label("");
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("StepForward (managed):", memoryColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Step forward:          ", memoryColor) + m_statisticsWindowData.ManagedStepForward.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                if (!DisplayMemoryAllocations)
                {
                    return;
                }
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Allocations (managed):", memoryColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre step callbacks:    ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreStepForward).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre synchronize:       ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreSynchronizeTransforms).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Step forward:          ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.StepForward).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post synchronize:      ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostSynchronizeTransforms).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post step callbacks:   ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostStepForward).PadLeft(6, ' ')), labelStyle);
            },
                             "AGX Dynamics statistics",
                             Utils.GUI.Skin.window);
        }