void Awake()
    {
        if (!enabled)
            return;

        m_camera = Camera.main;
        //Debug.Log("w:" + Screen.width + " h:" + Screen.height);

        GameObject frameCounter = new GameObject("Frame Counter");
        m_frameCounter_transform = frameCounter.transform;
        m_frameCounter_transform.parent = m_camera.transform;
        m_frameCounter_transform.localRotation = Quaternion.identity;
        

        m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>();
        m_TextMeshPro.font = Resources.Load("Fonts/ARIAL SDF", typeof(TextMeshProFont)) as TextMeshProFont;
        m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts/ARIAL SDF Overlay", typeof(Material)) as Material;

        m_TextMeshPro.fontSize = 48;
        //m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128);
        //m_TextMeshPro.edgeWidth = .15f;      
        m_TextMeshPro.isOverlay = true;

        //m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0);
        //m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255);
        //m_TextMeshPro.FontMaterial.renderQueue = 4000;

        //m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f));

        Set_FrameCounter_Position(AnchorPosition);
        last_AnchorPosition = AnchorPosition;
        
    
    }
    void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
    {
        //Debug.Log("Changing frame counter anchor position.");
        m_textContainer.margins = new Vector4(1f, 1f, 1f, 1f);

        switch (anchor_position)
        {
            case FpsCounterAnchorPositions.TopLeft:
                m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
                m_textContainer.anchorPosition = TextContainerAnchors.TopLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;
            case FpsCounterAnchorPositions.BottomLeft:
                m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
                m_textContainer.anchorPosition = TextContainerAnchors.BottomLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;
            case FpsCounterAnchorPositions.TopRight:
                m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
                m_textContainer.anchorPosition = TextContainerAnchors.TopRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;
            case FpsCounterAnchorPositions.BottomRight:
                m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
                m_textContainer.anchorPosition = TextContainerAnchors.BottomRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
        }
    }
Пример #3
0
        void Awake()
        {
            if (!enabled)
            {
                return;
            }

            m_camera = Camera.main;
            Application.targetFrameRate = -1;

            GameObject frameCounter = new GameObject("Frame Counter");

            m_TextMeshPro      = frameCounter.AddComponent <TextMeshPro>();
            m_TextMeshPro.font = Resources.Load <TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
            m_TextMeshPro.fontSharedMaterial = Resources.Load <Material>("Fonts & Materials/LiberationSans SDF - Overlay");

            m_frameCounter_transform = frameCounter.transform;
            m_frameCounter_transform.SetParent(m_camera.transform);
            m_frameCounter_transform.localRotation = Quaternion.identity;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize           = 24;
            //m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128);
            //m_TextMeshPro.edgeWidth = .15f;
            m_TextMeshPro.isOverlay = true;

            //m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0);
            //m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255);
            //m_TextMeshPro.FontMaterial.renderQueue = 4000;

            //m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f));

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
Пример #4
0
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchorPosition)
        {
            //Debug.Log("Changing frame counter anchor position.");
            _mTextMeshPro.margin = new Vector4(1f, 1f, 1f, 1f);

            switch (anchorPosition)
            {
            case FpsCounterAnchorPositions.TopLeft:
                _mTextMeshPro.alignment           = TextAlignmentOptions.TopLeft;
                _mTextMeshPro.rectTransform.pivot = new Vector2(0, 1);
                _mFrameCounterTransform.position  = _mCamera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomLeft:
                _mTextMeshPro.alignment           = TextAlignmentOptions.BottomLeft;
                _mTextMeshPro.rectTransform.pivot = new Vector2(0, 0);
                _mFrameCounterTransform.position  = _mCamera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;

            case FpsCounterAnchorPositions.TopRight:
                _mTextMeshPro.alignment           = TextAlignmentOptions.TopRight;
                _mTextMeshPro.rectTransform.pivot = new Vector2(1, 1);
                _mFrameCounterTransform.position  = _mCamera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomRight:
                _mTextMeshPro.alignment           = TextAlignmentOptions.BottomRight;
                _mTextMeshPro.rectTransform.pivot = new Vector2(1, 0);
                _mFrameCounterTransform.position  = _mCamera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
            }
        }
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {
            //Debug.Log("Changing frame counter anchor position.");
            m_textContainer.margins = new Vector4(1f, 1f, 1f, 1f);

            switch (anchor_position)
            {
            case FpsCounterAnchorPositions.TopLeft:
                m_TextMeshPro.alignment           = TextAlignmentOptions.TopLeft;
                m_textContainer.anchorPosition    = TextContainerAnchors.TopLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomLeft:
                m_TextMeshPro.alignment           = TextAlignmentOptions.BottomLeft;
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;

            case FpsCounterAnchorPositions.TopRight:
                m_TextMeshPro.alignment           = TextAlignmentOptions.TopRight;
                m_textContainer.anchorPosition    = TextContainerAnchors.TopRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomRight:
                m_TextMeshPro.alignment           = TextAlignmentOptions.BottomRight;
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
            }
        }
Пример #6
0
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {

            switch (anchor_position)
            {
                case FpsCounterAnchorPositions.TopLeft:
                    //m_TextMeshPro.anchor = AnchorPositions.TopLeft;
                    m_textContainer.anchorPosition = TextContainerAnchors.TopLeft;
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                    break;
                case FpsCounterAnchorPositions.BottomLeft:
                    //m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
                    m_textContainer.anchorPosition = TextContainerAnchors.BottomLeft;
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                    break;
                case FpsCounterAnchorPositions.TopRight:
                    //m_TextMeshPro.anchor = AnchorPositions.TopRight;
                    m_textContainer.anchorPosition = TextContainerAnchors.TopRight;
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                    break;
                case FpsCounterAnchorPositions.BottomRight:
                    //m_TextMeshPro.anchor = AnchorPositions.BottomRight;
                    m_textContainer.anchorPosition = TextContainerAnchors.BottomRight;
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                    break;
            }
        }
Пример #7
0
    void Awake()
    {
        if (!enabled)
        {
            return;
        }

        m_camera = Camera.main;
        //Debug.Log("w:" + Screen.width + " h:" + Screen.height);

        GameObject frameCounter = new GameObject("Frame Counter");

        m_frameCounter_transform               = frameCounter.transform;
        m_frameCounter_transform.parent        = m_camera.transform;
        m_frameCounter_transform.localRotation = Quaternion.identity;


        m_TextMeshPro      = frameCounter.AddComponent <TextMeshPro>();
        m_TextMeshPro.font = Resources.Load("Fonts/ARIAL SDF", typeof(TextMeshProFont)) as TextMeshProFont;
        m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts/ARIAL SDF Overlay", typeof(Material)) as Material;

        m_TextMeshPro.fontSize = 48;
        //m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128);
        //m_TextMeshPro.edgeWidth = .15f;
        m_TextMeshPro.isOverlay = true;

        //m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0);
        //m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255);
        //m_TextMeshPro.FontMaterial.renderQueue = 4000;

        //m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f));

        Set_FrameCounter_Position(AnchorPosition);
        last_AnchorPosition = AnchorPosition;
    }
Пример #8
0
        void Update()
        {
            if (AnchorPosition != last_AnchorPosition)
                Set_FrameCounter_Position(AnchorPosition);

            last_AnchorPosition = AnchorPosition;

            m_Frames += 1;
            float timeNow = Time.realtimeSinceStartup;

            if (timeNow > m_LastInterval + UpdateInterval)
            {
                // display two fractional digits (f2 format)
                float fps = m_Frames / (timeNow - m_LastInterval);
                float ms = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                    htmlColorTag = "<color=yellow>";
                else if (fps < 10)
                    htmlColorTag = "<color=red>";
                else
                    htmlColorTag = "<color=green>";

                m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);

                m_Frames = 0;
                m_LastInterval = timeNow;
            }
        }
        void Awake()
        {
            if (!enabled)
            {
                return;
            }

            Application.targetFrameRate = 120;

            GameObject frameCounter = new GameObject("Frame Counter");

            m_frameCounter_transform = frameCounter.AddComponent <RectTransform>();

            m_frameCounter_transform.SetParent(this.transform, false);

            m_TextMeshPro      = frameCounter.AddComponent <TextMeshProUGUI>();
            m_TextMeshPro.font = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
            m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Overlay", typeof(Material)) as Material;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize           = 36;

            m_TextMeshPro.isOverlay = true;

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {
            switch (anchor_position)
            {
            case FpsCounterAnchorPositions.TopLeft:
//commented out code was ommited here
                m_textContainer.anchorPosition    = TextContainerAnchors.TopLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomLeft:
//commented out code was ommited here
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;

            case FpsCounterAnchorPositions.TopRight:
//commented out code was ommited here
                m_textContainer.anchorPosition    = TextContainerAnchors.TopRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomRight:
//commented out code was ommited here
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
            }
        }
        void Awake()
        {
            if (!enabled)
            {
                return;
            }

            //ApplicationExit.targetFrameRate = 1000;

            GameObject frameCounter = new GameObject("Frame Counter");

            m_frameCounter_transform = frameCounter.AddComponent <RectTransform>();

            m_frameCounter_transform.SetParent(this.transform, false);

            m_TextMeshPro      = frameCounter.AddComponent <TextMeshProUGUI>();
            m_TextMeshPro.font = Resources.Load <TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
            m_TextMeshPro.fontSharedMaterial = Resources.Load <Material>("Fonts & Materials/LiberationSans SDF - Overlay");

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize           = 36;

            m_TextMeshPro.isOverlay = true;

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
Пример #12
0
        private void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {
            switch (anchor_position)
            {
            case FpsCounterAnchorPositions.TopLeft:
                //m_TextMeshPro.anchor = AnchorPositions.TopLeft;
                m_textContainer.anchorPosition    = TextContainerAnchors.TopLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomLeft:
                //m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomLeft;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;

            case FpsCounterAnchorPositions.TopRight:
                //m_TextMeshPro.anchor = AnchorPositions.TopRight;
                m_textContainer.anchorPosition    = TextContainerAnchors.TopRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomRight:
                //m_TextMeshPro.anchor = AnchorPositions.BottomRight;
                m_textContainer.anchorPosition    = TextContainerAnchors.BottomRight;
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
            }
        }
Пример #13
0
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {
//commented out code was ommited here
            m_TextMeshPro.margin = new Vector4(1f, 1f, 1f, 1f);

            switch (anchor_position)
            {
            case FpsCounterAnchorPositions.TopLeft:
                m_TextMeshPro.alignment           = TextAlignmentOptions.TopLeft;
                m_TextMeshPro.rectTransform.pivot = new Vector2(0, 1);
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomLeft:
                m_TextMeshPro.alignment           = TextAlignmentOptions.BottomLeft;
                m_TextMeshPro.rectTransform.pivot = new Vector2(0, 0);
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
                break;

            case FpsCounterAnchorPositions.TopRight:
                m_TextMeshPro.alignment           = TextAlignmentOptions.TopRight;
                m_TextMeshPro.rectTransform.pivot = new Vector2(1, 1);
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
                break;

            case FpsCounterAnchorPositions.BottomRight:
                m_TextMeshPro.alignment           = TextAlignmentOptions.BottomRight;
                m_TextMeshPro.rectTransform.pivot = new Vector2(1, 0);
                m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
                break;
            }
        }
Пример #14
0
    void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
    {
        //Debug.Log("Changing frame counter anchor position.");

        switch (anchor_position)
        {
        case FpsCounterAnchorPositions.TopLeft:
            m_TextMeshPro.anchor = AnchorPositions.TopLeft;
            m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
            break;

        case FpsCounterAnchorPositions.BottomLeft:
            m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
            m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
            break;

        case FpsCounterAnchorPositions.TopRight:
            m_TextMeshPro.anchor = AnchorPositions.TopRight;
            m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
            break;

        case FpsCounterAnchorPositions.BottomRight:
            m_TextMeshPro.anchor = AnchorPositions.BottomRight;
            m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
            break;
        }
    }
Пример #15
0
        void Update()
        {
            UpdateAverageFramerate();

            if (AnchorPosition != last_AnchorPosition)
            {
                Set_FrameCounter_Position(AnchorPosition);
            }

            last_AnchorPosition = AnchorPosition;

            m_Frames += 1;
            float timeNow = Time.realtimeSinceStartup;

            if (timeNow > m_LastInterval + UpdateInterval)
            {
                // display two fractional digits (f2 format)
                fps = m_Frames / (timeNow - m_LastInterval);
                ms  = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                {
                    htmlColorTag = "<color=yellow>";
                }
                else if (fps < 10)
                {
                    htmlColorTag = "<color=red>";
                }
                else
                {
                    htmlColorTag = "<color=green>";
                }

                if (isVisible == true)
                {
                    m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);
                }

                else
                {
                    m_TextMeshPro.SetText("");
                }

                m_Frames       = 0;
                m_LastInterval = timeNow;
            }
        }
        void Update()
        {
            if (AnchorPosition != last_AnchorPosition)
            {
                Set_FrameCounter_Position(AnchorPosition);
            }

            last_AnchorPosition = AnchorPosition;

            m_Frames += 1;
            float timeNow = Time.realtimeSinceStartup;

            if (timeNow > m_LastInterval + UpdateInterval)
            {
                // display two fractional digits (f2 format)
                float fps = m_Frames / (timeNow - m_LastInterval);
                float ms  = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                {
                    htmlColorTag = "<color=yellow>";
                }
                else if (fps < 10)
                {
                    htmlColorTag = "<color=red>";
                }
                else
                {
                    htmlColorTag = "<color=green>";
                }

                //string format = System.String.Format(htmlColorTag + "{0:F2} </color>FPS \n{1:F2} <#8080ff>MS",fps, ms);
                //m_TextMeshPro.text = format;

                m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);

                m_Frames       = 0;
                m_LastInterval = timeNow;
            }
        }
Пример #17
0
        void Update()
        {
            if (AnchorPosition != last_AnchorPosition)
            {
                Set_FrameCounter_Position(AnchorPosition);
            }

            last_AnchorPosition = AnchorPosition;

            m_Frames += 1;
            float timeNow = Time.realtimeSinceStartup;

            if (timeNow > m_LastInterval + UpdateInterval)
            {
                // display two fractional digits (f2 format)
                float fps = m_Frames / (timeNow - m_LastInterval);
                float ms  = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                {
                    htmlColorTag = "<color=yellow>";
                }
                else if (fps < 10)
                {
                    htmlColorTag = "<color=red>";
                }
                else
                {
                    htmlColorTag = "<color=green>";
                }

//commented out code was ommited here
//commented out code was ommited here
                m_TextMeshPro.SetText(htmlColorTag + fpsLabel, fps, ms);

                m_Frames       = 0;
                m_LastInterval = timeNow;
            }
        }
Пример #18
0
        void Update()
        {
            if (this.AnchorPosition != this.last_AnchorPosition)
            {
                this.Set_FrameCounter_Position(this.AnchorPosition);
            }

            this.last_AnchorPosition = this.AnchorPosition;

            this.m_Frames += 1;
            var timeNow = Time.realtimeSinceStartup;

            if (timeNow > this.m_LastInterval + this.UpdateInterval)
            {
                // display two fractional digits (f2 format)
                var fps = this.m_Frames / (timeNow - this.m_LastInterval);
                var ms  = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                {
                    this.htmlColorTag = "<color=yellow>";
                }
                else if (fps < 10)
                {
                    this.htmlColorTag = "<color=red>";
                }
                else
                {
                    this.htmlColorTag = "<color=green>";
                }

                //string format = System.String.Format(htmlColorTag + "{0:F2} </color>FPS \n{1:F2} <#8080ff>MS",fps, ms);
                //m_TextMeshPro.text = format;
                this.m_TextMeshPro.SetText(this.htmlColorTag + fpsLabel, fps, ms);

                this.m_Frames       = 0;
                this.m_LastInterval = timeNow;
            }
        }
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
        {
            switch (anchor_position)
            {
            case FpsCounterAnchorPositions.TopLeft:
                m_TextMeshPro.alignment                   = TextAlignmentOptions.TopLeft;
                m_frameCounter_transform.pivot            = new Vector2(0, 1);
                m_frameCounter_transform.anchorMin        = new Vector2(0.01f, 0.99f);
                m_frameCounter_transform.anchorMax        = new Vector2(0.01f, 0.99f);
                m_frameCounter_transform.anchoredPosition = new Vector2(0, 1);
                break;

            case FpsCounterAnchorPositions.BottomLeft:
                m_TextMeshPro.alignment                   = TextAlignmentOptions.BottomLeft;
                m_frameCounter_transform.pivot            = new Vector2(0, 0);
                m_frameCounter_transform.anchorMin        = new Vector2(0.01f, 0.01f);
                m_frameCounter_transform.anchorMax        = new Vector2(0.01f, 0.01f);
                m_frameCounter_transform.anchoredPosition = new Vector2(0, 0);
                break;

            case FpsCounterAnchorPositions.TopRight:
                m_TextMeshPro.alignment                   = TextAlignmentOptions.TopRight;
                m_frameCounter_transform.pivot            = new Vector2(1, 1);
                m_frameCounter_transform.anchorMin        = new Vector2(0.99f, 0.99f);
                m_frameCounter_transform.anchorMax        = new Vector2(0.99f, 0.99f);
                m_frameCounter_transform.anchoredPosition = new Vector2(1, 1);
                break;

            case FpsCounterAnchorPositions.BottomRight:
                m_TextMeshPro.alignment                   = TextAlignmentOptions.BottomRight;
                m_frameCounter_transform.pivot            = new Vector2(1, 0);
                m_frameCounter_transform.anchorMin        = new Vector2(0.99f, 0.01f);
                m_frameCounter_transform.anchorMax        = new Vector2(0.99f, 0.01f);
                m_frameCounter_transform.anchoredPosition = new Vector2(1, 0);
                break;
            }
        }
Пример #20
0
        void Update()
        {
            if (anchorPosition != _lastAnchorPosition)
            {
                Set_FrameCounter_Position(anchorPosition);
            }

            _lastAnchorPosition = anchorPosition;

            _mFrames += 1;
            float timeNow = Time.realtimeSinceStartup;

            if (timeNow > _mLastInterval + updateInterval)
            {
                // display two fractional digits (f2 format)
                float fps = _mFrames / (timeNow - _mLastInterval);
                float ms  = 1000.0f / Mathf.Max(fps, 0.00001f);

                if (fps < 30)
                {
                    _htmlColorTag = "<color=yellow>";
                }
                else if (fps < 10)
                {
                    _htmlColorTag = "<color=red>";
                }
                else
                {
                    _htmlColorTag = "<color=green>";
                }

                _mTextMeshPro.SetText(_htmlColorTag + FpsLabel, fps, ms);

                _mFrames       = 0;
                _mLastInterval = timeNow;
            }
        }
Пример #21
0
        void Awake()
        {
            if (!enabled)
                return;

            m_camera = Camera.main;
            Application.targetFrameRate = -1;

            GameObject frameCounter = new GameObject("Frame Counter");

            m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>();
            m_TextMeshPro.font = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
            m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Overlay", typeof(Material)) as Material;


            m_frameCounter_transform = frameCounter.transform;
            m_frameCounter_transform.SetParent(m_camera.transform);
            m_frameCounter_transform.localRotation = Quaternion.identity;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize = 24;
            //m_TextMeshPro.FontColor = new Color32(255, 255, 255, 128);
            //m_TextMeshPro.edgeWidth = .15f;
            m_TextMeshPro.isOverlay = true;

            //m_TextMeshPro.FaceColor = new Color32(255, 128, 0, 0);
            //m_TextMeshPro.EdgeColor = new Color32(0, 255, 0, 255);
            //m_TextMeshPro.FontMaterial.renderQueue = 4000;

            //m_TextMeshPro.CreateSoftShadowClone(new Vector2(1f, -1f));
            m_textContainer = frameCounter.GetComponent<TextContainer>();

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;


        }
Пример #22
0
        void Awake()
        {
            if (!enabled)
            {
                return;
            }

            m_camera = Camera.main;
            Application.targetFrameRate = -1;

            GameObject frameCounter = new GameObject("Frame Counter");

            m_TextMeshPro      = frameCounter.AddComponent <TextMeshPro>();
            m_TextMeshPro.font = Resources.Load <TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
            m_TextMeshPro.fontSharedMaterial = Resources.Load <Material>("Fonts & Materials/LiberationSans SDF - Overlay");


            m_frameCounter_transform = frameCounter.transform;
            m_frameCounter_transform.SetParent(m_camera.transform);
            m_frameCounter_transform.localRotation = Quaternion.identity;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize           = 24;
//commented out code was ommited here
//commented out code was ommited here
            m_TextMeshPro.isOverlay = true;

//commented out code was ommited here
//commented out code was ommited here
//commented out code was ommited here

//commented out code was ommited here

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
Пример #23
0
        void Awake()
        {
            if (!enabled)
                return;

            Application.targetFrameRate = -1;

            GameObject frameCounter = new GameObject("Frame Counter");
            m_frameCounter_transform = frameCounter.AddComponent<RectTransform>();

            m_frameCounter_transform.SetParent(this.transform, false);

            m_TextMeshPro = frameCounter.AddComponent<TextMeshProUGUI>();
            m_TextMeshPro.font = Resources.Load("Fonts & Materials/ARIAL SDF", typeof(TMP_FontAsset)) as TMP_FontAsset;
            m_TextMeshPro.fontSharedMaterial = Resources.Load("Fonts & Materials/ARIAL SDF Overlay", typeof(Material)) as Material;

            m_TextMeshPro.enableWordWrapping = false;
            m_TextMeshPro.fontSize = 36;

            m_TextMeshPro.isOverlay = true;

            Set_FrameCounter_Position(AnchorPosition);
            last_AnchorPosition = AnchorPosition;
        }
   void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
   {
       //Debug.Log("Changing frame counter anchor position.");
 
       switch (anchor_position)
       {
           case FpsCounterAnchorPositions.TopLeft:
               m_TextMeshPro.anchor = AnchorPositions.TopLeft;
               m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
               break;
           case FpsCounterAnchorPositions.BottomLeft:
               m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
               m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
               break;
           case FpsCounterAnchorPositions.TopRight:
               m_TextMeshPro.anchor = AnchorPositions.TopRight;
               m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
               break;
           case FpsCounterAnchorPositions.BottomRight:
               m_TextMeshPro.anchor = AnchorPositions.BottomRight;
               m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
               break;
       }  
   }
Пример #25
0
 void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
 {
     switch (anchor_position)
     {
         case FpsCounterAnchorPositions.TopLeft:
             m_TextMeshPro.alignment = TextAlignmentOptions.TopLeft;
             m_frameCounter_transform.pivot = new Vector2(0, 1);
             m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.99f);
             m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.99f);
             m_frameCounter_transform.anchoredPosition = new Vector2(0, 1);
             break;
         case FpsCounterAnchorPositions.BottomLeft:
             m_TextMeshPro.alignment = TextAlignmentOptions.BottomLeft;
             m_frameCounter_transform.pivot = new Vector2(0, 0);
             m_frameCounter_transform.anchorMin = new Vector2(0.01f, 0.01f);
             m_frameCounter_transform.anchorMax = new Vector2(0.01f, 0.01f);
             m_frameCounter_transform.anchoredPosition = new Vector2(0, 0);
             break;
         case FpsCounterAnchorPositions.TopRight:
             m_TextMeshPro.alignment = TextAlignmentOptions.TopRight;
             m_frameCounter_transform.pivot = new Vector2(1, 1);
             m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.99f);
             m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.99f);
             m_frameCounter_transform.anchoredPosition = new Vector2(1, 1);
             break;
         case FpsCounterAnchorPositions.BottomRight:
             m_TextMeshPro.alignment = TextAlignmentOptions.BottomRight;
             m_frameCounter_transform.pivot = new Vector2(1, 0);
             m_frameCounter_transform.anchorMin = new Vector2(0.99f, 0.01f);
             m_frameCounter_transform.anchorMax = new Vector2(0.99f, 0.01f);
             m_frameCounter_transform.anchoredPosition = new Vector2(1, 0);
             break;
     }
 }