LogView.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  3. *
  4. * You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  5. * copy, modify, and distribute this software in source code or binary form for use
  6. * in connection with the web services and APIs provided by Facebook.
  7. *
  8. * As with any software that integrates with the Facebook platform, your use of
  9. * this software is subject to the Facebook Developer Principles and Policies
  10. * [http://developers.facebook.com/policy/]. This copyright notice shall be
  11. * included in all copies or substantial portions of the software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  15. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  16. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  17. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  18. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. namespace Facebook.Unity.Example
  21. {
  22. using System;
  23. using System.Collections.Generic;
  24. using System.Linq;
  25. using UnityEngine;
  26. internal class LogView : ConsoleBase
  27. {
  28. private static string datePatt = @"M/d/yyyy hh:mm:ss tt";
  29. private static IList<string> events = new List<string>();
  30. public static void AddLog(string log)
  31. {
  32. events.Insert(0, string.Format("{0}\n{1}\n", DateTime.Now.ToString(datePatt), log));
  33. }
  34. protected void OnGUI()
  35. {
  36. GUILayout.BeginVertical();
  37. if (this.Button("Back"))
  38. {
  39. this.GoBack();
  40. }
  41. #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8
  42. if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
  43. {
  44. Vector2 scrollPosition = this.ScrollPosition;
  45. scrollPosition.y += Input.GetTouch(0).deltaPosition.y;
  46. this.ScrollPosition = scrollPosition;
  47. }
  48. #endif
  49. this.ScrollPosition = GUILayout.BeginScrollView(
  50. this.ScrollPosition,
  51. GUILayout.MinWidth(ConsoleBase.MainWindowFullWidth));
  52. GUILayout.TextArea(
  53. string.Join("\n", events.ToArray()),
  54. this.TextStyle,
  55. GUILayout.ExpandHeight(true),
  56. GUILayout.MaxWidth(ConsoleBase.MainWindowWidth));
  57. GUILayout.EndScrollView();
  58. GUILayout.EndVertical();
  59. }
  60. }
  61. }