chenlunfu

新宝娱乐城体验金: unity 实现Game窗口的Stats

新宝娱乐城博彩打不开 www.sl6cl.com.cn 热度 7220001 2016-9-7 17:56 |个人分类:unity Editor

[code]csharpcode:

using UnityEngine;
using System.Text;
using UnityEditor;

public class ShowFps : MonoBehaviour
{

    public bool m_isShow = true;

    private int m_FrameCounter;
    private float m_ClientTimeAccumulator;
    private float m_RenderTimeAccumulator;
    private float m_MaxTimeAccumulator;
    private float m_ClientFrameTime;
    private float m_RenderFrameTime;
    private float m_MaxFrameTime;
    private GUIStyle s_SectionHeaderStyle;
    private GUIStyle s_LabelStyle;
    [Range(0, 1)]
    public float position = 0.5f;
    void Start()
    {
    }



    void OnGUI()
    {
        if (m_isShow)
        {
            GameViewStatsGUI();
        }

    }

    private GUIStyle sectionHeaderStyle
    {
        get
        {
            if (s_SectionHeaderStyle == null)
            {
                s_SectionHeaderStyle = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene).GetStyle("BoldLabel");
            }
            return s_SectionHeaderStyle;
        }
    }
    private GUIStyle labelStyle
    {
        get
        {
            if (s_LabelStyle == null)
            {
                s_LabelStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene).label);
                s_LabelStyle.richText = true;
            }
            return s_LabelStyle;
        }
    }
    private string FormatNumber(int num)
    {
        if (num < 1000)
        {
            return num.ToString();
        }
        if (num < 1000000)
        {
            return ((double)num * 0.001).ToString("f1") + "k";
        }
        return ((double)num * 1E-06).ToString("f1") + "M";
    }
    public void UpdateFrameTime()
    {
        float frameTime = UnityStats.frameTime;
        float renderTime = UnityStats.renderTime;
        m_ClientTimeAccumulator += frameTime;
        m_RenderTimeAccumulator += renderTime;
        m_MaxTimeAccumulator += Mathf.Max(frameTime, renderTime);
        m_FrameCounter++;
        bool flag = m_ClientFrameTime == 0f && m_RenderFrameTime == 0f;
        bool flag2 = m_FrameCounter > 30 || m_ClientTimeAccumulator > 0.3f || m_RenderTimeAccumulator > 0.3f;
        if (flag || flag2)
        {
            m_ClientFrameTime = m_ClientTimeAccumulator / (float)m_FrameCounter;
            m_RenderFrameTime = m_RenderTimeAccumulator / (float)m_FrameCounter;
            m_MaxFrameTime = m_MaxTimeAccumulator / (float)m_FrameCounter;
        }
        if (flag2)
        {
            m_ClientTimeAccumulator = 0f;
            m_RenderTimeAccumulator = 0f;
            m_MaxTimeAccumulator = 0f;
            m_FrameCounter = 0;
        }
    }
    private static string FormatDb(float vol)
    {
        if (vol == 0f)
        {
            return "-∞ dB";
        }
        return string.Format("{0:F1} dB", 20f * Mathf.Log10(vol));
    }
    public void GameViewStatsGUI()
    {
        GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
        GUI.color = new Color(1f, 1f, 1f, 0.75f);
        float num = 300f;
        float num2 = 204f;
        int num3 = Network.connections.Length;
        if (num3 != 0)
        {
            num2 += 220f;
        }
        GUILayout.BeginArea(new Rect(Screen.width * position - num - 10f, 27f, num, num2), "Statistics", GUI.skin.window);
        GUILayout.Label("Audio:", sectionHeaderStyle, new GUILayoutOption[0]);
        StringBuilder stringBuilder = new StringBuilder(400);
        float audioLevel = UnityStats.audioLevel;
        stringBuilder.Append("  Level: " + FormatDb(audioLevel) + ((!EditorUtility.audioMasterMute) ? "\n" : " (MUTED)\n"));
        stringBuilder.Append(string.Format("  Clipping: {0:F1}%", 100f * UnityStats.audioClippingAmount));
        GUILayout.Label(stringBuilder.ToString(), new GUILayoutOption[0]);
        GUI.Label(new Rect(170f, 40f, 120f, 20f), string.Format("DSP load: {0:F1}%", 100f * UnityStats.audioDSPLoad));
        GUI.Label(new Rect(170f, 53f, 120f, 20f), string.Format("Stream load: {0:F1}%", 100f * UnityStats.audioStreamLoad));
        GUILayout.Label("Graphics:", sectionHeaderStyle, new GUILayoutOption[0]);
        UpdateFrameTime();
        string text = string.Format("{0:F1} FPS ({1:F1}ms)", 1f / Mathf.Max(m_MaxFrameTime, 1E-05f), m_MaxFrameTime * 1000f);
        GUI.Label(new Rect(170f, 75f, 120f, 20f), text);
        int screenBytes = UnityStats.screenBytes;
        int num4 = UnityStats.dynamicBatchedDrawCalls - UnityStats.dynamicBatches;
        int num5 = UnityStats.staticBatchedDrawCalls - UnityStats.staticBatches;
        StringBuilder stringBuilder2 = new StringBuilder(400);
        if (m_ClientFrameTime > m_RenderFrameTime)
        {
            stringBuilder2.Append(string.Format("  CPU: main <b>{0:F1}</b>ms  render thread {1:F1}ms\n", m_ClientFrameTime * 1000f, m_RenderFrameTime * 1000f));
        }
        else
        {
            stringBuilder2.Append(string.Format("  CPU: main {0:F1}ms  render thread <b>{1:F1}</b>ms\n", m_ClientFrameTime * 1000f, m_RenderFrameTime * 1000f));
        }
        stringBuilder2.Append(string.Format("  Batches: <b>{0}</b> \tSaved by batching: {1}\n", UnityStats.batches, num4 + num5));
        stringBuilder2.Append(string.Format("  Tris: {0} \tVerts: {1} \n", FormatNumber(UnityStats.triangles), FormatNumber(UnityStats.vertices)));
        stringBuilder2.Append(string.Format("  Screen: {0} - {1}\n", UnityStats.screenRes, EditorUtility.FormatBytes(screenBytes)));
        stringBuilder2.Append(string.Format("  SetPass calls: {0} \tShadow casters: {1} \n", UnityStats.setPassCalls, UnityStats.shadowCasters));
        stringBuilder2.Append(string.Format("  Visible skinned meshes: {0}  s: {1}", UnityStats.visibleSkinnedMeshes, UnityStats.visibleAnimations));
        GUILayout.Label(stringBuilder2.ToString(), labelStyle, new GUILayoutOption[0]);
        if (num3 != 0)
        {
            GUILayout.Label("Network:", sectionHeaderStyle, new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            for (int i = 0; i < num3; i++)
            {
                GUILayout.Label(UnityStats.GetNetworkStats(i), new GUILayoutOption[0]);
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            GUILayout.Label("Network: (no players connected)", sectionHeaderStyle, new GUILayoutOption[0]);
        }
        GUILayout.EndArea();
    }
}



发表评论 评论 (18 个评论)

回复 小丑丶 2016-9-23 09:36
66666666666666
回复 wx_opKOOOOS 2016-10-9 10:03
需要学的真是不少
回复 贝贝 2016-11-5 11:32
这个只能在编辑器下用吗?可否发布?
回复 失落的羽翼 2016-11-22 11:28
一模一样啊,牛X
回复 qq493201681 2016-11-29 08:31
太666了
回复 y876265603 2016-12-8 11:08
666666666666666666666666666666
回复 任林波 2017-1-23 09:30
6666666666666666
回复 邹恒 2017-2-20 14:14
妈的 ,碉堡了??!
回复 YuShow 2017-6-28 14:56
6666666666666666666666666
回复 倔强的摩羯 2017-7-27 14:40
大神啊
回复 a蛮牛范儿 2017-8-23 08:38
大神厉害
回复 JTed 2017-9-9 17:39
6666666666666666666666666666666666666
回复 UnityTerminator 2017-10-12 09:56
很不错
回复 UnityTerminator 2017-10-12 09:56
很不错
回复 sh348862335 2018-2-8 11:56
大哥 要不要这样 直接反编译了下UnityEditor.dll后 你就改了下 直接贴过来了???
回复 karsion 2018-6-22 23:51
晕,这有什么意义吗?反编译editor的代码,又不能发布出来用
回复 Broken 2018-7-20 10:53
我觉得么什么意义啊老哥,又不能发不出来使用
回复 chenlunfu 2018-12-5 20:37
可以发布出来 改一下

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册帐号

  • 银行不用“冲时点”了?存款偏离度调整至4% 2019-04-26
  • 快看!山西这场1600℃高温打铁花表演震撼人心 2019-04-26
  • 在学习中进步。[奋斗] 2019-04-25
  • 证监会核发两家企业IPO批文 筹资总额不超10亿元 2019-04-24
  • 衡阳日报社副社长周卫国祝贺人民日报创刊70周年 2019-04-23
  • 习近平出席上海合作组织青岛峰会欢迎宴会并致祝酒辞 2019-04-22
  • 杰森·斯坦森:《巨齿鲨》水下拍摄难度大 2019-04-22
  • 一张门票免签两国!白俄罗斯世界杯期间对球迷免签 2019-04-21
  • 近九成券商股逆市上涨 防御+反弹攻守兼备 2019-04-21
  • 女友提分手小伙以死相逼 警察破门救助被划伤 2019-04-20
  • 流动人口的户籍迁移意愿及其影响因素分析 2019-04-19
  • Angelababy上海街头拍大片 都市简约风优雅显气质 2019-04-19
  • 【群友杂谈】——农村、农民、农地 2019-04-18
  • 年轻妈妈留下遗书 携刚出生10天的婴儿在河中溺亡 2019-04-17
  • 中国三大球备战里约奥运 2019-04-16
  • 755| 364| 819| 597| 931| 767| 743| 855| 269| 950|