/// <summary> /// Called every frame to enable rendering of GUI items /// to the screeen /// </summary> public static void Render() { if (!mIsEnabled) { return; } GUIStyle lStyle = new GUIStyle(); lStyle.alignment = TextAnchor.UpperLeft; lStyle.normal.textColor = Color.white; lStyle.fontSize = mFontSize; //GUI.color = Color.white; GUI.contentColor = mForeColor; GUI.backgroundColor = Color.green; // Write out the lines of text for (int i = 0; i < mLineIndex; i++) { LogText lLine = mLines[i]; mLineRect.x = lLine.X; mLineRect.y = lLine.Y; mLineRect.width = 900; mLineRect.height = mLineHeight; GUI.Label(mLineRect, lLine.Text, lStyle); } }
/// <summary> /// Returns an element back to the pool. /// </summary> /// <param name="rEdge"></param> public static void Release(LogText rInstance) { if (rInstance == null) { return; } // Make it available to others. sPool.Release(rInstance); }
/// <summary> /// Pulls an object from the pool. /// </summary> /// <returns></returns> public static LogText Allocate(string rText, int rX, int rY) { // Grab the next available object LogText lInstance = sPool.Allocate(); // Set values lInstance.Text = rText; lInstance.X = rX; lInstance.Y = rY; return(lInstance); }
/// <summary> /// Pulls an object from the pool. /// </summary> /// <returns></returns> public static LogText Allocate() { // Grab the next available object LogText lInstance = sPool.Allocate(); // Set values lInstance.Text = ""; lInstance.X = 0; lInstance.Y = 0; return(lInstance); }
/// <summary> /// Static constructor /// </summary> static Log() { if (mLines == null) { mLines = new LogText[mLineCount]; } for (int i = 0; i < mLines.Length; i++) { LogText lLine = new LogText(); lLine.X = 10; lLine.Y = i * mLineHeight; lLine.Text = ""; mLines[i] = lLine; } }
/// <summary> /// Called by the co-routine after rendering happens /// so that we can clean up our objects /// </summary> public static void Clear() { for (int i = 0; i < mLineIndex; i++) { LogText.Release(mLines[i]); } mLineIndex = 0; // Flush the external log if needed #if USE_FILE_IO if (mWriter != null) { mWriter.Flush(); } #endif }
/// <summary> /// Writes text to the screen /// </summary> /// <param name="rText">Text to write</param> /// <param name="rX">X start of left character</param> /// <param name="rY">Y start of the left character</param> public static void ScreenWrite(string rText, int rX, int rY) { if (!mIsEnabled) { return; } if (mPrefixTime) { rText = String.Format("[{0:f4}] {1}", System.DateTime.Now.ToLongTimeString(), rText); } LogText lLine = LogText.Allocate(rText, rX, rY); mLines[mLineIndex % Log.LOG_TEXT_COUNT] = lLine; mLineIndex++; if (mLineIndex >= Log.LOG_TEXT_COUNT) { mLineIndex = Log.LOG_TEXT_COUNT - 1; } }
/// <summary> /// Writes text to the screen /// </summary> /// <param name="rText">Text to write</param> /// <param name="rX">X start of left character</param> /// <param name="rY">Y start of the left character</param> public static void ScreenWrite(string rText, int rX, int rY) { if (!mIsEnabled) { return; } if (mPrefixTime) { rText = String.Format("[{0:f4}] {1}", Time.realtimeSinceStartup, rText); } int lLineIndex = rY / mLineHeight; if (lLineIndex < mLines.Length) { if (mLines[lLineIndex] == null) { LogText lLine = new LogText(); lLine.X = rX; lLine.Y = lLineIndex * mLineHeight; lLine.Text = rText; mLines[lLineIndex] = lLine; } else { mLines[lLineIndex].Text = rText; } } mLineIndex++; if (mLineIndex >= mLineCount) { mLineIndex = mLineCount - 1; } }