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); } }
internal void UpdateTexts() { if (this.operationMode != AFPSCounterOperationMode.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(AFPSCounter.NEW_LINE); } drawableLabel.newText.Append(this.fpsCounter.text); 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(AFPSCounter.NEW_LINE); } drawableLabel2.newText.Append(this.memoryCounter.text); 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(AFPSCounter.NEW_LINE); } drawableLabel3.newText.Append(this.deviceInfoCounter.text); drawableLabel3.dirty |= this.deviceInfoCounter.dirty; this.deviceInfoCounter.dirty = false; flag = true; } if (flag) { for (int i = 0; i < this.anchorsCount; i++) { this.labels[i].CheckAndUpdate(); } } else { for (int j = 0; j < this.anchorsCount; j++) { this.labels[j].Clear(); } } }
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 ConfigureLabels() { anchorsCount = Enum.GetNames(typeof(LabelAnchor)).Length; labels = new DrawableLabel[anchorsCount]; for (int i = 0; i < anchorsCount; i++) { labels[i] = new DrawableLabel(canvas.gameObject, (LabelAnchor)i, new LabelEffect(shadow, shadowColor, shadowDistance), new LabelEffect(outline, outlineColor, outlineDistance), labelsFont, fontSize, lineSpacing, paddingOffset); } }
private void ConfigureLabels() { anchorsCount = Enum.GetNames(typeof(LabelAnchor)).Length; labels = new DrawableLabel[anchorsCount]; for (int i = 0; i < anchorsCount; i++) { labels[i] = new DrawableLabel(canvas, (LabelAnchor)i, paddingOffset, labelsFont, fontSize, lineSpacing); } }
protected override void OnLoad(Microsoft.Xna.Framework.Content.ContentManager content, Microsoft.Xna.Framework.Graphics.GraphicsDevice gd) { Overlay = new DrawableRectangle(new GREATLib.Rect(0, 0, screenService.GameWindowSize.X, screenService.GameWindowSize.Y), Color.White); Overlay.Alpha = 0f; AddChild(Overlay); AddChild(Message = new DrawableLabel(), 2); Message.Scale = new Vector2(2f); Message.RelativeOrigin = new Vector2(0.5f); Message.SetPositionInScreenPercent(50, 50); base.OnLoad(content, gd); }
private void SetScore() { Kills = new DrawableLabel() { Text = "0" }; Deaths = new DrawableLabel() { Text = "0" }; TeamKills = new DrawableLabel() { Text = "0", Tint = Color.Green }; TeamDeaths = new DrawableLabel() { Text = "0", Tint = Color.Red }; AddChild(Kills, 3); AddChild(Deaths, 3); AddChild(TeamKills, 3); AddChild(TeamDeaths, 3); Kills.SetPositionRelativeToObject(ScoreBackground, new Vector2(20, 10)); Deaths.SetPositionRelativeToObject(Kills, new Vector2(70, 0)); TeamKills.SetPositionRelativeToObject(Deaths, new Vector2(120, 0)); TeamDeaths.SetPositionRelativeToObject(TeamKills, new Vector2(70, 0)); DrawableImage killIcon = new DrawableImage("UIObjects/killIcon"); DrawableImage deathIcon = new DrawableImage("UIObjects/deathIcon"); DrawableImage teamKillIcon = new DrawableImage("UIObjects/killIcon"); AddChild(killIcon, 2); AddChild(deathIcon, 2); AddChild(teamKillIcon, 2); killIcon.SetPositionRelativeToObject(Kills, new Vector2(23, -2)); deathIcon.SetPositionRelativeToObject(Deaths, new Vector2(23, -2)); teamKillIcon.SetPositionRelativeToObject(TeamKills, new Vector2(23, -2)); }
protected override void OnLoad(Microsoft.Xna.Framework.Content.ContentManager content, Microsoft.Xna.Framework.Graphics.GraphicsDevice gd) { RedRectangle = new DrawableRectangle(new GREATLib.Rect(0, 0, screenService.GameWindowSize.X, screenService.GameWindowSize.Y), Color.Red); RedRectangle.Alpha = 0f; AddChild(RedRectangle); DrawableLabel deathMessage = new DrawableLabel(); deathMessage.Text = "You died!"; deathMessage.Scale = new Vector2(2f); deathMessage.RelativeOrigin = new Vector2(0.5f); deathMessage.SetPositionInScreenPercent(50, 40); AddChild(deathMessage, 2); DeathTimer = new DrawableLabel(); DeathTimer.Text = DeathDuration.Seconds.ToString(); DeathTimer.Scale = new Vector2(2f); DeathTimer.RelativeOrigin = new Vector2(0.5f); DeathTimer.SetPositionInScreenPercent(50, 50); AddChild(DeathTimer, 2); }
internal void UpdateTexts() { if (operationMode != OperationMode.Normal) { return; } bool anyContentPresent = false; if (fpsCounter.Enabled) { DrawableLabel label = labels[(int)fpsCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(new string(NEW_LINE, countersSpacing + 1)); } label.newText.Append(fpsCounter.text); label.dirty |= fpsCounter.dirty; fpsCounter.dirty = false; anyContentPresent = true; } if (memoryCounter.Enabled) { DrawableLabel label = labels[(int)memoryCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(new string(NEW_LINE, countersSpacing + 1)); } label.newText.Append(memoryCounter.text); label.dirty |= memoryCounter.dirty; memoryCounter.dirty = false; anyContentPresent = true; } if (deviceInfoCounter.Enabled) { DrawableLabel label = labels[(int)deviceInfoCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(new string(NEW_LINE, countersSpacing + 1)); } label.newText.Append(deviceInfoCounter.text); label.dirty |= deviceInfoCounter.dirty; deviceInfoCounter.dirty = false; anyContentPresent = true; } if (anyContentPresent) { for (int i = 0; i < anchorsCount; i++) { labels[i].CheckAndUpdate(); } } else { for (int i = 0; i < anchorsCount; i++) { labels[i].Clear(); } } }
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(); } }
/// <summary> /// For internal usage! /// </summary> internal void UpdateTexts() { //Debug.Log("UpdateTexts " + Time.realtimeSinceStartup); if (!enabled) { return; } bool anyContentPresent = false; //Debug.Log("UpdateTexts1 " + FPSCounter.Enabled); //Debug.Log("UpdateTexts2 " + FPSCounter.text); if (fpsCounter.Enabled) { DrawableLabel label = labels[(int)fpsCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(NEW_LINE); } label.newText.Append(fpsCounter.text); label.dirty |= fpsCounter.dirty; fpsCounter.dirty = false; anyContentPresent = true; } if (memoryCounter.Enabled) { DrawableLabel label = labels[(int)memoryCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(NEW_LINE); } label.newText.Append(memoryCounter.text); label.dirty |= memoryCounter.dirty; memoryCounter.dirty = false; anyContentPresent = true; } if (deviceInfoCounter.Enabled) { DrawableLabel label = labels[(int)deviceInfoCounter.Anchor]; if (label.newText.Length > 0) { label.newText.Append(NEW_LINE); } label.newText.Append(deviceInfoCounter.text); label.dirty |= deviceInfoCounter.dirty; deviceInfoCounter.dirty = false; anyContentPresent = true; } if (anyContentPresent) { for (int i = 0; i < anchorsCount; i++) { labels[i].CheckAndUpdate(); } } else { for (int i = 0; i < anchorsCount; i++) { labels[i].Clear(); } } }
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(); }