示例#1
0
    void OnGUI()
    {
        //Debug.Log("OnGUI time:"+stopWatch.Elapsed);
        w = Screen.width;
        h = Screen.height;

        if(viewMode != FPSGraphViewMode.graphing){
            Time.timeScale = 0.0f;
            format();
            Color backupColor = GUI.color;
            GUI.color = Color.black;

            Rect sRect = new Rect(w*0.05f,h*0.05f,w*0.9f,h*0.9f);
            GUI.color = Color.black;

            GUI.color = Color.white;
            GUI.skin.label = h2;
            GUI.Label(new Rect(w*0.1f,h*0.07f,w,h*0.2f), "Performance Results");
            GUI.Label(new Rect(w*0.62f,h*0.07f,w,h*0.2f), "Assets Used");

            if(viewMode == FPSGraphViewMode.totalperformance){
                GUI.skin.label = h2;
                GUI.Label(new Rect(w*0.1f,h*0.2f,w,h*0.2f), "Score:");
                GUI.skin.label = h1;
                GUI.Label(new Rect(w*0.1f,h*0.27f,w,h*0.2f), (totalDt*1000.0f).ToString("n0")+"ms");

                GUI.skin.label = h2;
                GUI.Label(new Rect(w*0.1f,h*0.38f,w,h*0.2f), "Time Elapsed:");
                GUI.skin.label = h1;
                GUI.Label(new Rect(w*0.1f,h*0.43f,w,h*0.2f), totalTimeElapsed.ToString("F1")+"s");

                GUI.skin.label = h3;
                float avgFrameRate = totalDt / totalFrames;
                string[] arr = new string[]{"lowest: "+(1.0f/highestDt).ToString("n0")+"fps","highest: "+(1.0f/lowestDt).ToString("n0")+"fps", "avg: "+(1.0f/avgFrameRate).ToString("n0")+"fps"};
                for(int i = 0; i < arr.Length; i++){
                    GUI.Label(new Rect(w*0.1f,h*0.57f + w*0.04f*i,w,h*0.2f), arr[i]);
                }

                GUI.color = Color.black;
                GUI.skin.label = graphTitles;
                arr = new string[]{"Render","CPU","Other"};
                float[] arrW = new float[]{0.12f,0.12f,0.12f};
                float sh = 0.0023f*w;
                for(int i = 0; circleGraphLabels!=null && i<circleGraphLabels.Length; i++){
                    GUI.color = Color.black;
                    GUI.Label(new Rect(circleGraphLabels[i].x+sh,circleGraphLabels[i].y+sh,w*arrW[i],h*0.047f), arr[i]);
                    GUI.color = Color.white;
                    GUI.Label(new Rect(circleGraphLabels[i].x,circleGraphLabels[i].y,w*arrW[i],h*0.047f), arr[i]);
                }
            }else{
                GUILayout.BeginArea( new Rect(w*0.08f,h*0.175f,w*0.9f,h*0.7f) );
                GUI.skin.label = h2;
                GUILayout.Label("All: " + Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object)).Length.ToString("n0"));
                GUILayout.Label("Textures: " + Resources.FindObjectsOfTypeAll(typeof(Texture2D)).Length.ToString("n0"));
                GUILayout.Label("AudioClips: " + Resources.FindObjectsOfTypeAll(typeof(AudioClip)).Length.ToString("n0"));
                GUILayout.Label("Meshes: " + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length.ToString("n0"));
                GUILayout.Label("Materials: " + Resources.FindObjectsOfTypeAll(typeof(Material)).Length.ToString("n0"));
                GUILayout.Label("GameObjects: " + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length.ToString("n0"));
                GUILayout.Label("Components: " + Resources.FindObjectsOfTypeAll(typeof(Component)).Length.ToString("n0"));
                GUILayout.EndArea();
            }

            GUI.skin.button = guiButton;
            if(GUI.Button(new Rect(w*0.05f,h*0.05f,w*0.45f,h*0.15f),"")){
                viewMode = FPSGraphViewMode.totalperformance;
            }
            if(GUI.Button(new Rect(w*0.5f,h*0.05f,w*0.45f,h*0.15f),"")){
                viewMode = FPSGraphViewMode.assetbreakdown;
            }
            if(GUI.Button(new Rect(w*0.3f,h*0.8f,w*0.4f,h*0.15f),"")){
                reset();
                viewMode = FPSGraphViewMode.graphing;
                Time.timeScale = 1.0f;
            }
            sRect = new Rect(w*0.435f,h*0.83f,w*0.25f,h*0.11f);
            GUI.skin.label = h2;
            GUI.Label(sRect, "Dismiss");

            GUI.skin.label = backupLabel;
            GUI.skin.button = backupButton;
            GUI.color = backupColor;
        }else{
            if(Time.frameCount>4)
                GUI.DrawTexture( new Rect(graphPosition.x*(w-graphMultiply*frameHistoryLength), graphPosition.y*(h-graphMultiply*107) + 100*graphMultiply, graphSizeGUI.width, graphSizeGUI.height), graphTexture );
        }

        if(showPerformanceOnClick && didPressOnGraph() && highestDt>0.0f)
            showPerformance();
    }
示例#2
0
 public void showPerformance()
 {
     if(viewMode!=FPSGraphViewMode.totalperformance){
         totalTimeElapsed = Time.time;
         viewMode = FPSGraphViewMode.totalperformance;
         if(audioSource)
             audioSource.Stop();
     }
 }