public void OnEnable() { self = (target as AFPSCounter); fpsGroupToggle = serializedObject.FindProperty("fpsGroupToggle"); fpsCounter = serializedObject.FindProperty("fpsCounter"); fpsCounterEnabled = fpsCounter.FindPropertyRelative("enabled"); fpsCounterUpdateInterval = fpsCounter.FindPropertyRelative("updateInterval"); fpsCounterAnchor = fpsCounter.FindPropertyRelative("anchor"); fpsCounterShowAverage = fpsCounter.FindPropertyRelative("showAverage"); fpsCounterResetAverageOnNewScene = fpsCounter.FindPropertyRelative("resetAverageOnNewScene"); fpsCounterWarningLevelValue = fpsCounter.FindPropertyRelative("warningLevelValue"); fpsCounterCriticalLevelValue = fpsCounter.FindPropertyRelative("criticalLevelValue"); fpsCounterColorNormal = fpsCounter.FindPropertyRelative("colorNormal"); fpsCounterColorWarning = fpsCounter.FindPropertyRelative("colorWarning"); fpsCounterColorCritical = fpsCounter.FindPropertyRelative("colorCritical"); memoryGroupToggle = serializedObject.FindProperty("memoryGroupToggle"); memoryCounter = serializedObject.FindProperty("memoryCounter"); memoryCounterEnabled = memoryCounter.FindPropertyRelative("enabled"); memoryCounterUpdateInterval = memoryCounter.FindPropertyRelative("updateInterval"); memoryCounterAnchor = memoryCounter.FindPropertyRelative("anchor"); memoryCounterPreciseValues = memoryCounter.FindPropertyRelative("preciseValues"); memoryCounterColor = memoryCounter.FindPropertyRelative("color"); memoryCounterMonoUsage = memoryCounter.FindPropertyRelative("monoUsage"); memoryCounterHeapUsage = memoryCounter.FindPropertyRelative("heapUsage"); deviceGroupToggle = serializedObject.FindProperty("deviceGroupToggle"); deviceCounter = serializedObject.FindProperty("deviceInfoCounter"); deviceCounterEnabled = deviceCounter.FindPropertyRelative("enabled"); deviceCounterAnchor = deviceCounter.FindPropertyRelative("anchor"); deviceCounterColor = deviceCounter.FindPropertyRelative("color"); deviceCounterCpuModel = deviceCounter.FindPropertyRelative("cpuModel"); deviceCounterGpuModel = deviceCounter.FindPropertyRelative("gpuModel"); deviceCounterRamSize = deviceCounter.FindPropertyRelative("ramSize"); deviceCounterScreenData = deviceCounter.FindPropertyRelative("screenData"); lookAndFeelToggle = serializedObject.FindProperty("lookAndFeelToggle"); labelsFont = serializedObject.FindProperty("labelsFont"); fontSize = serializedObject.FindProperty("fontSize"); lineSpacing = serializedObject.FindProperty("lineSpacing"); anchorsOffset = serializedObject.FindProperty("anchorsOffset"); hotKey = serializedObject.FindProperty("hotKey"); keepAlive = serializedObject.FindProperty("keepAlive"); forceFrameRate = serializedObject.FindProperty("forceFrameRate"); forcedFrameRate = serializedObject.FindProperty("forcedFrameRate"); }
/// <summary> /// Use it to completely dispose AFPSCounter. /// </summary> public void Dispose() { instance = null; Destroy(gameObject); }
private void Awake() { //Debug.Log("AFPSCounter Awake, instance = " + instance); if (instance != null) { Debug.LogWarning("Only one Advanced FPS Counter instance allowed!"); Destroy(this); return; } if (!IsPlacedCorrectly()) { Debug.LogWarning("Advanced FPS Counter is placed in scene incorrectly and will be auto-destroyed! Please, use \"GameObject->Create Other->Code Stage->Advanced FPS Counter\" menu to correct this!"); Destroy(this); return; } #if UNITY_EDITOR Camera[] cameras = Camera.allCameras; int len = cameras.Length; float highestCameraDeph = float.MinValue; float highestSuitableCameraDeph = float.MinValue; for (int i = 0; i < len; i++) { Camera cam = cameras[i]; if (cam.depth > highestCameraDeph) { highestCameraDeph = cam.depth; } GUILayer guiLayer = cameras[i].GetComponent <GUILayer>(); if (guiLayer != null && guiLayer.enabled) { if (cam.depth > highestSuitableCameraDeph) { highestSuitableCameraDeph = cam.depth; } } } if (highestCameraDeph != highestSuitableCameraDeph) { Debug.LogWarning("Advanced FPS Counter needs top-most (highest depth) camera with enabled GUILayer to be visible!"); } #endif instance = this; DontDestroyOnLoad(gameObject); anchorsCount = Enum.GetNames(typeof(LabelAnchor)).Length; labels = new DrawableLabel[anchorsCount]; for (int i = 0; i < anchorsCount; i++) { labels[i] = new DrawableLabel((LabelAnchor)i, anchorsOffset, labelsFont, fontSize, lineSpacing); } RefreshHotKey(); }
private static void AddToScene() { AFPSCounter counter = (AFPSCounter)FindObjectOfType(typeof(AFPSCounter)); if (counter != null) { if (counter.IsPlacedCorrectly()) { if (UnityEditor.EditorUtility.DisplayDialog("Remove Advanced FPS Counter?", "Advanced FPS Counter already exists in scene and placed correctly. Dou you wish to remove it?", "Yes", "No")) { DestroyImmediate(counter.gameObject); } } else { if (counter.MayBePlacedHere()) { int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Fix existing Game Object to work with Adavnced FPS Counter?", "Advanced FPS Counter already exists in scene and placed onto empty Game Object \"" + counter.name + "\".\nDo you wish to let plugin configure 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: DestroyImmediate(counter); break; default: break; } } else { int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing Adavnced FPS Counter to own Game Object?", "Looks like Advanced FPS Counter plugin is already exists in scene and placed incorrectly on Game Object \"" + counter.name + "\".\nDo you wish to let plugin move itself onto separate configured Game Object \"" + CONTAINER_NAME + "\"? Press Delete to remove plugin from scene at all.", "Move", "Delete", "Cancel"); switch (dialogResult) { case 0: GameObject go = new GameObject(CONTAINER_NAME); AFPSCounter newCounter = go.AddComponent <AFPSCounter>(); UnityEditor.EditorUtility.CopySerialized(counter, newCounter); DestroyImmediate(counter); break; case 1: DestroyImmediate(counter); break; default: break; } } } } else { GameObject go = new GameObject(CONTAINER_NAME); go.AddComponent <AFPSCounter>(); } }