Esempio n. 1
0
        // ----------------------------------------------------------------------------
        // unity callbacks
        // ----------------------------------------------------------------------------

        #region unity callbacks
        private void Awake()
        {
            /* checks for duplication */

            if (Instance != null && Instance.keepAlive)
            {
                Destroy(this);
                return;
            }

            /* editor-only checks */

#if UNITY_EDITOR
            if (!IsPlacedCorrectly())
            {
                //Debug.LogWarning(LOG_PREFIX + "incorrect placement detected! Please, use \"" + GAME_OBJECT_MENU_GROUP + MENU_PATH + "\" menu to fix it!", this);
            }
#endif

            /* initialization */

            Instance = this;

            fpsCounter.Init(this);
            memoryCounter.Init(this);
            deviceInfoCounter.Init(this);

            ConfigureCanvas();
            ConfigureLabels();

            inited = true;
        }
Esempio n. 2
0
 private void DisposeInternal()
 {
     Destroy(this);
     if (Instance == this)
     {
         Instance = null;
     }
 }
Esempio n. 3
0
        protected void CacheCriticalColor()
        {
            string colorString = AFPSCounter.Color32ToHex(colorCritical);

            colorCriticalCached    = string.Format(FPS_TEXT_START, colorString);
            colorCriticalCachedMs  = string.Format(MS_TEXT_START, colorString);
            colorCriticalCachedMin = string.Format(MIN_TEXT_START, colorString);
            colorCriticalCachedMax = string.Format(MAX_TEXT_START, colorString);
            colorCriticalCachedAvg = string.Format(AVG_TEXT_START, colorString);
        }
Esempio n. 4
0
        internal void Destroy()
        {
            main = null;

            if (text != null)
            {
                text.Remove(0, text.Length);
                text = null;
            }
        }
Esempio n. 5
0
 private static void DestroyInEditorImmediate(AFPSCounter component)
 {
     if (component.transform.childCount == 0 && component.GetComponentsInChildren <Component>(true).Length <= 2)
     {
         UnityEditor.Undo.DestroyObjectImmediate(component.gameObject);
     }
     else
     {
         UnityEditor.Undo.DestroyObjectImmediate(component);
     }
 }
Esempio n. 6
0
        protected override void CacheCurrentColor()
        {
            string colorString = AFPSCounter.Color32ToHex(color);

            colorCached    = string.Format(FPS_TEXT_START, colorString);
            colorCachedMs  = string.Format(MS_TEXT_START, colorString);
            colorCachedMin = string.Format(MIN_TEXT_START, colorString);
            colorCachedMax = string.Format(MAX_TEXT_START, colorString);
            colorCachedAvg = string.Format(AVG_TEXT_START, colorString);

            string colorRenderString = AFPSCounter.Color32ToHex(colorRender);

            colorCachedRender = string.Format(RENDER_TEXT_START, colorRenderString);
        }
Esempio n. 7
0
        private static AFPSCounter GetOrCreateInstance(bool keepAlive)
        {
            if (Instance != null)
            {
                return(Instance);
            }

            var counter = FindObjectOfType <AFPSCounter>();

            if (counter != null)
            {
                Instance = counter;
            }
            else
            {
                AFPSCounter newInstance = CreateInScene(false);
                newInstance.keepAlive = keepAlive;
            }
            return(Instance);
        }
Esempio n. 8
0
        private void OnDestroy()
        {
            if (inited)
            {
                fpsCounter.Destroy();
                memoryCounter.Destroy();
                deviceInfoCounter.Destroy();

                if (labels != null)
                {
                    for (int i = 0; i < anchorsCount; i++)
                    {
                        labels[i].Destroy();
                    }

                    System.Array.Clear(labels, 0, anchorsCount);
                    labels = null;
                }
                inited = false;
            }

            if (canvas != null)
            {
                Destroy(canvas.gameObject);
            }

            if (transform.childCount <= 1)
            {
                Destroy(gameObject);
            }

            if (Instance == this)
            {
                Instance = null;
            }
        }
Esempio n. 9
0
        public void OnEnable()
        {
            me = target as AFPSCounter;

            operationMode = serializedObject.FindProperty("operationMode");

            hotKey          = serializedObject.FindProperty("hotKey");
            hotKeyCtrl      = serializedObject.FindProperty("hotKeyCtrl");
            hotKeyShift     = serializedObject.FindProperty("hotKeyShift");
            hotKeyAlt       = serializedObject.FindProperty("hotKeyAlt");
            circleGesture   = serializedObject.FindProperty("circleGesture");
            keepAlive       = serializedObject.FindProperty("keepAlive");
            forceFrameRate  = serializedObject.FindProperty("forceFrameRate");
            forcedFrameRate = serializedObject.FindProperty("forcedFrameRate");

            lookAndFeelFoldout = serializedObject.FindProperty("lookAndFeelFoldout");
            autoScale          = serializedObject.FindProperty("autoScale");
            scaleFactor        = serializedObject.FindProperty("scaleFactor");
            labelsFont         = serializedObject.FindProperty("labelsFont");
            fontSize           = serializedObject.FindProperty("fontSize");
            lineSpacing        = serializedObject.FindProperty("lineSpacing");
            countersSpacing    = serializedObject.FindProperty("countersSpacing");
            paddingOffset      = serializedObject.FindProperty("paddingOffset");
            pixelPerfect       = serializedObject.FindProperty("pixelPerfect");

            background        = serializedObject.FindProperty("background");
            backgroundColor   = serializedObject.FindProperty("backgroundColor");
            backgroundPadding = serializedObject.FindProperty("backgroundPadding");

            shadow         = serializedObject.FindProperty("shadow");
            shadowColor    = serializedObject.FindProperty("shadowColor");
            shadowDistance = serializedObject.FindProperty("shadowDistance");

            outline         = serializedObject.FindProperty("outline");
            outlineColor    = serializedObject.FindProperty("outlineColor");
            outlineDistance = serializedObject.FindProperty("outlineDistance");

            advancedFoldout = serializedObject.FindProperty("advancedFoldout");
            sortingOrder    = serializedObject.FindProperty("sortingOrder");

            fps             = serializedObject.FindProperty("fpsCounter");
            fpsEnabled      = fps.FindPropertyRelative("enabled");
            fpsInterval     = fps.FindPropertyRelative("updateInterval");
            fpsAnchor       = fps.FindPropertyRelative("anchor");
            fpsMilliseconds = fps.FindPropertyRelative("milliseconds");

            fpsAverage                = fps.FindPropertyRelative("average");
            fpsAverageMilliseconds    = fps.FindPropertyRelative("averageMilliseconds");
            fpsAverageNewLine         = fps.FindPropertyRelative("averageNewLine");
            fpsAverageSamples         = fps.FindPropertyRelative("averageSamples");
            fpsResetAverageOnNewScene = fps.FindPropertyRelative("resetAverageOnNewScene");

            fpsMinMax                = fps.FindPropertyRelative("minMax");
            fpsMinMaxMilliseconds    = fps.FindPropertyRelative("minMaxMilliseconds");
            fpsMinMaxNewLine         = fps.FindPropertyRelative("minMaxNewLine");
            fpsMinMaxTwoLines        = fps.FindPropertyRelative("minMaxTwoLines");
            fpsResetMinMaxOnNewScene = fps.FindPropertyRelative("resetMinMaxOnNewScene");
            fpsMinMaxIntervalsToSkip = fps.FindPropertyRelative("minMaxIntervalsToSkip");

            fpsRender        = fps.FindPropertyRelative("render");
            fpsRenderNewLine = fps.FindPropertyRelative("renderNewLine");
            fpsRenderAutoAdd = fps.FindPropertyRelative("renderAutoAdd");

            fpsWarningLevelValue  = fps.FindPropertyRelative("warningLevelValue");
            fpsCriticalLevelValue = fps.FindPropertyRelative("criticalLevelValue");
            fpsColor         = fps.FindPropertyRelative("color");
            fpsColorWarning  = fps.FindPropertyRelative("colorWarning");
            fpsColorCritical = fps.FindPropertyRelative("colorCritical");
            fpsColorRender   = fps.FindPropertyRelative("colorRender");
            fpsStyle         = fps.FindPropertyRelative("style");

            memory          = serializedObject.FindProperty("memoryCounter");
            memoryEnabled   = memory.FindPropertyRelative("enabled");
            memoryInterval  = memory.FindPropertyRelative("updateInterval");
            memoryAnchor    = memory.FindPropertyRelative("anchor");
            memoryPrecise   = memory.FindPropertyRelative("precise");
            memoryColor     = memory.FindPropertyRelative("color");
            memoryStyle     = memory.FindPropertyRelative("style");
            memoryTotal     = memory.FindPropertyRelative("total");
            memoryAllocated = memory.FindPropertyRelative("allocated");
            memoryMonoUsage = memory.FindPropertyRelative("monoUsage");
#if UNITY_2018_1_OR_NEWER
            memoryGfx = memory.FindPropertyRelative("gfx");
#endif

            device                  = serializedObject.FindProperty("deviceInfoCounter");
            deviceEnabled           = device.FindPropertyRelative("enabled");
            deviceAnchor            = device.FindPropertyRelative("anchor");
            deviceColor             = device.FindPropertyRelative("color");
            deviceStyle             = device.FindPropertyRelative("style");
            devicePlatform          = device.FindPropertyRelative("platform");
            deviceCpuModel          = device.FindPropertyRelative("cpuModel");
            deviceCpuModelNewLine   = device.FindPropertyRelative("cpuModelNewLine");
            deviceGpuModel          = device.FindPropertyRelative("gpuModel");
            deviceGpuModelNewLine   = device.FindPropertyRelative("gpuModelNewLine");
            deviceGpuApi            = device.FindPropertyRelative("gpuApi");
            deviceGpuApiNewLine     = device.FindPropertyRelative("gpuApiNewLine");
            deviceGpuSpec           = device.FindPropertyRelative("gpuSpec");
            deviceGpuSpecNewLine    = device.FindPropertyRelative("gpuSpecNewLine");
            deviceRamSize           = device.FindPropertyRelative("ramSize");
            deviceRamSizeNewLine    = device.FindPropertyRelative("ramSizeNewLine");
            deviceScreenData        = device.FindPropertyRelative("screenData");
            deviceScreenDataNewLine = device.FindPropertyRelative("screenDataNewLine");
            deviceModel             = device.FindPropertyRelative("deviceModel");
            deviceModelNewLine      = device.FindPropertyRelative("deviceModelNewLine");
        }
Esempio n. 10
0
 internal void Init(AFPSCounter reference)
 {
     main = reference;
 }
Esempio n. 11
0
 protected override void CacheCurrentColor()
 {
     colorCached = "<color=#" + AFPSCounter.Color32ToHex(color) + ">";
 }
Esempio n. 12
0
 protected override void CacheCurrentColor()
 {
     colorCached = string.Format(TEXT_START, AFPSCounter.Color32ToHex(color));
 }
Esempio n. 13
0
        // ----------------------------------------------------------------------------
        // protected methods
        // ----------------------------------------------------------------------------

        protected override void PerformActivationActions()
        {
            base.PerformActivationActions();

            if (!HasData())
            {
                return;
            }

            LastTotalValue     = 0;
            LastAllocatedValue = 0;
            LastMonoValue      = 0;

            if (main.OperationMode == OperationMode.Normal)
            {
                if (colorCached == null)
                {
                    colorCached = string.Format(TEXT_START, AFPSCounter.Color32ToHex(color));
                }

                text.Append(colorCached);

                if (total)
                {
                    if (precise)
                    {
                        text.Append(LINE_START_TOTAL).Append("0.00").Append(LINE_END);
                    }
                    else
                    {
                        text.Append(LINE_START_TOTAL).Append(0).Append(LINE_END);
                    }
                }

                if (allocated)
                {
                    if (text.Length > 0)
                    {
                        text.Append(AFPSCounter.NEW_LINE);
                    }
                    if (precise)
                    {
                        text.Append(LINE_START_ALLOCATED).Append("0.00").Append(LINE_END);
                    }
                    else
                    {
                        text.Append(LINE_START_ALLOCATED).Append(0).Append(LINE_END);
                    }
                }

                if (monoUsage)
                {
                    if (text.Length > 0)
                    {
                        text.Append(AFPSCounter.NEW_LINE);
                    }
                    if (precise)
                    {
                        text.Append(LINE_START_MONO).Append("0.00").Append(LINE_END);
                    }
                    else
                    {
                        text.Append(LINE_START_MONO).Append(0).Append(LINE_END);
                    }
                }

#if ENABLE_GFX_MEMORY
                if (gfx)
                {
                    if (text.Length > 0)
                    {
                        text.Append(AFPSCounter.NEW_LINE);
                    }
                    if (precise)
                    {
                        text.Append(LINE_START_GFX).Append("0.00").Append(LINE_END);
                    }
                    else
                    {
                        text.Append(LINE_START_GFX).Append(0).Append(LINE_END);
                    }
                }
#endif

                text.Append(TEXT_END);

                ApplyTextStyles();

                dirty = true;
            }
        }
Esempio n. 14
0
        // ReSharper disable once UnusedMember.Local
        //[UnityEditor.MenuItem(GAME_OBJECT_MENU_PATH, false)]
        private static void AddToSceneInEditor()
        {
            AFPSCounter counter = FindObjectOfType <AFPSCounter>();

            if (counter != null)
            {
                if (counter.IsPlacedCorrectly())
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Remove " + COMPONENT_NAME + "?",
                                                                COMPONENT_NAME + " already exists in scene and placed correctly. Do you wish to remove it?", "Yes", "No"))
                    {
                        DestroyInEditorImmediate(counter);
                    }
                }
                else
                {
                    if (counter.MayBePlacedHere())
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with " +
                                                                                          COMPONENT_NAME + "?",
                                                                                          COMPONENT_NAME + " already exists in scene and placed on Game Object \"" +
                                                                                          counter.name + "\" with minor errors.\nDo you wish to let plugin fix and use this Game Object further? " +
                                                                                          "Press Delete to remove plugin from scene at all.", "Fix", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            counter.FixCurrentGameObject();
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                    else
                    {
                        int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing " + COMPONENT_NAME +
                                                                                          " to own Game Object?",
                                                                                          "Looks like " + COMPONENT_NAME + " already exists in scene and placed incorrectly on Game Object \"" +
                                                                                          counter.name + "\".\nDo you wish to let plugin move itself onto separate correct Game Object \"" +
                                                                                          COMPONENT_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel");

                        switch (dialogResult)
                        {
                        case 0:
                            AFPSCounter newCounter = CreateInScene(false);
                            UnityEditor.EditorUtility.CopySerialized(counter, newCounter);
                            DestroyInEditorImmediate(counter);
                            break;

                        case 1:
                            DestroyInEditorImmediate(counter);
                            break;
                        }
                    }
                }
            }
            else
            {
                var newCounter = CreateInScene();

                var fonts = UnityEditor.AssetDatabase.FindAssets("t:Font, VeraMono");
                if (fonts != null && fonts.Length != 0)
                {
                    string veraMonoPath = null;
                    foreach (var font in fonts)
                    {
                        var fontPath     = UnityEditor.AssetDatabase.GUIDToAssetPath(font);
                        var fontFileName = System.IO.Path.GetFileName(fontPath);
                        if (fontFileName == "VeraMono.ttf")
                        {
                            veraMonoPath = fontPath;
                            break;
                        }
                    }

                    if (!string.IsNullOrEmpty(veraMonoPath))
                    {
                        var font = (Font)UnityEditor.AssetDatabase.LoadAssetAtPath(veraMonoPath, typeof(Font));
                        var so   = new UnityEditor.SerializedObject(newCounter);
                        so.FindProperty("labelsFont").objectReferenceValue = font;
                        so.ApplyModifiedProperties();
                        UnityEditor.EditorUtility.SetDirty(newCounter);
                    }
                }
                UnityEditor.EditorUtility.DisplayDialog("Advanced FPS Counter added!", "Advanced FPS Counter successfully added to the object \"" + COMPONENT_NAME + "\"", "OK");
            }
        }