// ---------------------------------------------------------------------------- // 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(LogPrefix + "incorrect placement detected! Please, use \"" + GameObjectMenuGroup + MenuPath + "\" menu to fix it!", this); } #endif /* initialization */ Instance = this; fpsCounter.Init(this); memoryCounter.Init(this); deviceInfoCounter.Init(this); ConfigureCanvas(); ConfigureLabels(); inited = true; }
private static AFPSCounter CreateInScene(bool lookForExistingContainer) { GameObject container = lookForExistingContainer ? GameObject.Find(COMPONENT_NAME) : null; if (container == null) { container = new GameObject(COMPONENT_NAME); container.layer = LayerMask.NameToLayer("UI"); #if UNITY_EDITOR UnityEditor.Undo.RegisterCreatedObjectUndo(container, "Create " + COMPONENT_NAME); if (UnityEditor.Selection.activeTransform != null) { container.transform.parent = UnityEditor.Selection.activeTransform; } UnityEditor.Selection.activeObject = container; #endif } var existingContainer = container.GetComponent <AFPSCounter>(); if (existingContainer == null) { AFPSCounter newInstance = container.AddComponent <AFPSCounter>(); return(newInstance); } else { return(existingContainer); } }
private void Start() { // will add AFPSCounter to the scene if it not exists // you don't need to call it if you already have AFPSCounter in the scene AFPSCounter.AddToScene(); AFPSCounter.Instance.fpsCounter.OnFpsLevelChange += OnFPSLevelChanged; }
// ---------------------------------------------------------------------------- // 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 && false 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; }
private void Awake() { if (instance != null && instance.keepAlive) { Destroy(gameObject); 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; } fpsCounter.Init(this); memoryCounter.Init(this); deviceInfoCounter.Init(this); 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); } }
private void Awake() { if (AFPSCounter.instance != null && AFPSCounter.instance.keepAlive) { UnityEngine.Object.Destroy(base.gameObject); return; } if (!this.IsPlacedCorrectly()) { UnityEngine.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!"); UnityEngine.Object.Destroy(this); return; } this.fpsCounter.Init(this); this.memoryCounter.Init(this); this.deviceInfoCounter.Init(this); AFPSCounter.instance = this; UnityEngine.Object.DontDestroyOnLoad(base.gameObject); this.anchorsCount = Enum.GetNames(typeof(LabelAnchor)).Length; this.labels = new DrawableLabel[this.anchorsCount]; for (int i = 0; i < this.anchorsCount; i++) { this.labels[i] = new DrawableLabel((LabelAnchor)i, this.anchorsOffset, this.labelsFont, this.fontSize, this.lineSpacing); } }
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(); UnityEditor.EditorUtility.CopySerialized(counter, newCounter); break; } DestroyInEditorImmediate(counter); } } } else { CreateInScene(); UnityEditor.EditorUtility.DisplayDialog("Advanced FPS Counter added!", "Advanced FPS Counter successfully added to the object \"" + COMPONENT_NAME + "\"", "OK"); } }
/// <summary> /// Use it to completely dispose %AFPSCounter. /// </summary> public void Dispose() { if (instance == this) { instance = null; } Destroy(gameObject); }
private void DisposeInternal() { Destroy(this); if (Instance == this) { Instance = null; } }
public void Dispose() { if (AFPSCounter.instance == this) { AFPSCounter.instance = null; } UnityEngine.Object.Destroy(base.gameObject); }
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; } } 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); go.layer = 5; AFPSCounter newCounter = go.AddComponent <AFPSCounter>(); UnityEditor.EditorUtility.CopySerialized(counter, newCounter); DestroyImmediate(counter); break; case 1: DestroyImmediate(counter); break; } } } } else { GameObject go = new GameObject(CONTAINER_NAME); go.layer = 5; go.AddComponent <AFPSCounter>(); } }
public void OnEnable() { self = (target as AFPSCounter); operationMode = serializedObject.FindProperty("operationMode"); fpsGroupToggle = serializedObject.FindProperty("fpsGroupToggle"); fpsCounter = serializedObject.FindProperty("fpsCounter"); fpsCounterEnabled = fpsCounter.FindPropertyRelative("enabled"); fpsCounterUpdateInterval = fpsCounter.FindPropertyRelative("updateInterval"); fpsCounterAnchor = fpsCounter.FindPropertyRelative("anchor"); fpsCounterShowMinMax = fpsCounter.FindPropertyRelative("showMinMax"); fpsCounterResetMinMaxOnNewScene = fpsCounter.FindPropertyRelative("resetMinMaxOnNewScene"); fpsCounterShowAverage = fpsCounter.FindPropertyRelative("showAverage"); fpsCounterAverageFromSamples = fpsCounter.FindPropertyRelative("averageFromSamples"); fpsCounterResetAverageOnNewScene = fpsCounter.FindPropertyRelative("resetAverageOnNewScene"); fpsCounterWarningLevelValue = fpsCounter.FindPropertyRelative("warningLevelValue"); fpsCounterCriticalLevelValue = fpsCounter.FindPropertyRelative("criticalLevelValue"); fpsCounterColor = fpsCounter.FindPropertyRelative("color"); 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"); memoryCounterTotalReserved = memoryCounter.FindPropertyRelative("totalReserved"); memoryCounterAllocated = memoryCounter.FindPropertyRelative("allocated"); memoryCounterMonoUsage = memoryCounter.FindPropertyRelative("monoUsage"); 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"); }
private void Awake() { if (instance != null && instance.keepAlive) { Destroy(gameObject); 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; } DateTime Now = System.DateTime.Now; String strTime = Now.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25 strTime = strTime.Replace('/', '_'); strTime = strTime.Replace('-', '_'); strTime = strTime.Replace(' ', 'T'); strTime = strTime.Replace(':', '_'); String strFilePath = null; if (Application.platform == RuntimePlatform.IPhonePlayer) { string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.Length - 5); path = path.Substring(0, path.LastIndexOf('/')); strFilePath = Path.Combine(Path.Combine(path, "Documents"), String.Format("{0}{1}", strTime, ".txt")); } else { strFilePath = String.Format("{0}{1}{2}", Application.persistentDataPath, strTime, ".txt"); } if (File.Exists(strFilePath) == false) { File.Create(strFilePath).Close(); } streamWriter = File.AppendText(strFilePath); fpsCounter.Init(this); memoryCounter.Init(this); deviceInfoCounter.Init(this); 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); } }
private void Start() { // will add AFPSCounter to the scene if it not exists // you don't need to call it if you already have AFPSCounter in the scene var newCounterInstance = AFPSCounter.AddToScene(); // you also may get the instance at any time // using AFPSCounter.Instance property newCounterInstance.fpsCounter.OnFPSLevelChange += OnFPSLevelChanged; }
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); } }
private static AFPSCounter GetOrCreateInstance(bool keepAlive) { if (Instance != null) { return(Instance); } var counter = FindObjectOfType <AFPSCounter>(); if (counter != null) { Instance = counter; } else { var newInstance = CreateInScene(false); newInstance.keepAlive = keepAlive; } return(Instance); }
private void OnDestroy() { if (inited) { fpsCounter.Destroy(); memoryCounter.Destroy(); deviceInfoCounter.Destroy(); if (labels != null) { for (var 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; } }
private void OnDestroy() { if (inited) { fpsCounter.Dispose(); memoryCounter.Dispose(); deviceInfoCounter.Dispose(); if (labels != null) { for (int i = 0; i < anchorsCount; i++) { labels[i].Dispose(); } Array.Clear(labels, 0, anchorsCount); labels = null; } inited = false; } if (canvas != null) { Destroy(canvas.gameObject); } if (transform.childCount <= 1 && GetComponentsInChildren <Component>().Length <= 5) { Destroy(gameObject); } if (Instance == this) { Instance = null; } }
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"); } }
public void OnEnable() { me = (target as AFPSCounter); operationMode = serializedObject.FindProperty("operationMode"); hotKey = serializedObject.FindProperty("hotKey"); keepAlive = serializedObject.FindProperty("keepAlive"); forceFrameRate = serializedObject.FindProperty("forceFrameRate"); forcedFrameRate = serializedObject.FindProperty("forcedFrameRate"); lookAndFeelFoldout = serializedObject.FindProperty("lookAndFeelFoldout"); scaleFactor = serializedObject.FindProperty("scaleFactor"); labelsFont = serializedObject.FindProperty("labelsFont"); fontSize = serializedObject.FindProperty("fontSize"); lineSpacing = serializedObject.FindProperty("lineSpacing"); countersSpacing = serializedObject.FindProperty("countersSpacing"); paddingOffset = serializedObject.FindProperty("paddingOffset"); advancedFoldout = serializedObject.FindProperty("advancedFoldout"); sortingOrder = serializedObject.FindProperty("sortingOrder"); fpsGroupFoldout = serializedObject.FindProperty("fpsGroupFoldout"); fps = serializedObject.FindProperty("fpsCounter"); fpsEnabled = fps.FindPropertyRelative("enabled"); fpsInterval = fps.FindPropertyRelative("updateInterval"); fpsAnchor = fps.FindPropertyRelative("anchor"); fpsMilliseconds = fps.FindPropertyRelative("milliseconds"); fpsAverage = fps.FindPropertyRelative("average"); fpsMinMax = fps.FindPropertyRelative("minMax"); fpsMinMaxNewLine = fps.FindPropertyRelative("minMaxNewLine"); fpsResetMinMaxOnNewScene = fps.FindPropertyRelative("resetMinMaxOnNewScene"); fpsMinMaxIntervalsToSkip = fps.FindPropertyRelative("minMaxIntervalsToSkip"); fpsAverageSamples = fps.FindPropertyRelative("averageSamples"); fpsResetAverageOnNewScene = fps.FindPropertyRelative("resetAverageOnNewScene"); fpsWarningLevelValue = fps.FindPropertyRelative("warningLevelValue"); fpsCriticalLevelValue = fps.FindPropertyRelative("criticalLevelValue"); fpsColor = fps.FindPropertyRelative("color"); fpsColorWarning = fps.FindPropertyRelative("colorWarning"); fpsColorCritical = fps.FindPropertyRelative("colorCritical"); memoryGroupFoldout = serializedObject.FindProperty("memoryGroupFoldout"); memory = serializedObject.FindProperty("memoryCounter"); memoryEnabled = memory.FindPropertyRelative("enabled"); memoryInterval = memory.FindPropertyRelative("updateInterval"); memoryAnchor = memory.FindPropertyRelative("anchor"); memoryPrecise = memory.FindPropertyRelative("precise"); memoryColor = memory.FindPropertyRelative("color"); memoryTotal = memory.FindPropertyRelative("total"); memoryAllocated = memory.FindPropertyRelative("allocated"); memoryMonoUsage = memory.FindPropertyRelative("monoUsage"); deviceGroupFoldout = serializedObject.FindProperty("deviceGroupFoldout"); device = serializedObject.FindProperty("deviceInfoCounter"); deviceEnabled = device.FindPropertyRelative("enabled"); deviceAnchor = device.FindPropertyRelative("anchor"); deviceColor = device.FindPropertyRelative("color"); deviceCpuModel = device.FindPropertyRelative("cpuModel"); deviceGpuModel = device.FindPropertyRelative("gpuModel"); deviceRamSize = device.FindPropertyRelative("ramSize"); deviceScreenData = device.FindPropertyRelative("screenData"); }
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"); 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"); }
private void Awake() { AFPSCounter.AddToScene(); AFPSCounter.Instance.fpsCounter.onFPSLevelChange += OnFPSLevelChanged; }
private static void AddToSceneInEditor() { AFPSCounter counter = FindObjectOfType <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")) { DestroyInEditorImmediate(counter); } } 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 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: DestroyInEditorImmediate(counter); break; } } else { int dialogResult = UnityEditor.EditorUtility.DisplayDialogComplex("Move existing Adavnced FPS Counter to own Game Object?", "Looks like Advanced FPS Counter plugin 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); UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Create " + CONTAINER_NAME); UnityEditor.Selection.activeObject = go; AFPSCounter newCounter = go.AddComponent <AFPSCounter>(); UnityEditor.EditorUtility.CopySerialized(counter, newCounter); DestroyInEditorImmediate(counter); break; case 1: DestroyInEditorImmediate(counter); break; } } } } else { GameObject container = GameObject.Find(CONTAINER_NAME); if (container == null) { container = new GameObject(CONTAINER_NAME); UnityEditor.Undo.RegisterCreatedObjectUndo(container, "Create " + CONTAINER_NAME); UnityEditor.Selection.activeObject = container; } container.AddComponent <AFPSCounter>(); UnityEditor.EditorUtility.DisplayDialog("Adavnced FPS Counter added!", "Adavnced FPS Counter successfully added to the object \"" + CONTAINER_NAME + "\"", "OK"); } }
private void UpdateTexts() { string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); string s = folderPath + "\\CurrentEncounters.txt - Does not exist."; if (File.Exists(folderPath + "\\CurrentEncounters.txt")) { s = File.ReadAllText(folderPath + "\\CurrentEncounters.txt"); if (this.totalEncounters < 0) { try { this.totalEncounters = int.Parse(s); } catch (FormatException) { this.totalEncounters = -1; } } try { this.currentEncounters = int.Parse(s) - this.totalEncounters; } catch (FormatException) { this.currentEncounters = -1; } } if (this.operationMode != OperationMode.Normal) { return; } bool flag = false; if (this.fpsCounter.Enabled) { DrawableLabel drawableLabel = this.labels[(int)this.fpsCounter.Anchor]; if (drawableLabel.newText.Length > 0) { drawableLabel.newText.Append(new string('\n', this.countersSpacing + 1)); } drawableLabel.newText.Append(this.fpsCounter.text.ToString()); drawableLabel.dirty |= this.fpsCounter.dirty; this.fpsCounter.dirty = false; flag = true; } if (this.memoryCounter.Enabled) { DrawableLabel drawableLabel2 = this.labels[(int)this.memoryCounter.Anchor]; if (drawableLabel2.newText.Length > 0) { drawableLabel2.newText.Append(new string('\n', this.countersSpacing + 1)); } drawableLabel2.newText.Append(this.memoryCounter.text.ToString()); drawableLabel2.dirty |= this.memoryCounter.dirty; this.memoryCounter.dirty = false; flag = true; } if (this.deviceInfoCounter.Enabled) { DrawableLabel drawableLabel3 = this.labels[(int)this.deviceInfoCounter.Anchor]; if (drawableLabel3.newText.Length > 0) { drawableLabel3.newText.Append(new string('\n', this.countersSpacing + 1)); } drawableLabel3.newText.Append("TEST"); drawableLabel3.dirty |= this.deviceInfoCounter.dirty; this.deviceInfoCounter.dirty = false; flag = true; } DrawableLabel drawableLabel4 = this.labels[0]; if (drawableLabel4.newText.Length > 0) { drawableLabel4.newText.Append(new string('\n', this.countersSpacing + 1)); } string arg = AFPSCounter.Color32ToHex(Color.red); string arg2 = AFPSCounter.Color32ToHex(Color.yellow); string value = string.Format("<size=20><color=#{0}><b>", arg); string value2 = string.Format("<size=20><color=#{0}><b>", arg2); drawableLabel4.newText.Append(value2).Append("Total Encounters: ").Append("</b></color></size>").Append(value).Append(this.totalEncounters + this.currentEncounters).Append("</b></color></size>"); drawableLabel4.newText.Append(new string('\n', this.countersSpacing + 1)); drawableLabel4.newText.Append(value2).Append("Current Encounters: ").Append("</b></color></size>").Append(value).Append(this.currentEncounters).Append("</b></color></size>"); drawableLabel4.dirty = true; if (flag) { for (int i = 0; i < this.labels.Length; i++) { this.labels[i].CheckAndUpdate(); } return; } for (int j = 0; j < this.labels.Length; j++) { this.labels[j].Clear(); } }