ConsoleBridgeMessage.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * Copyright (c) 2021 Vuplex Inc. All rights reserved.
  3. *
  4. * Licensed under the Vuplex Commercial Software Library License, you may
  5. * not use this file except in compliance with the License. You may obtain
  6. * a copy of the License at
  7. *
  8. * https://vuplex.com/commercial-library-license
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma warning disable CS0649
  17. using System;
  18. using UnityEngine;
  19. namespace Vuplex.WebView {
  20. /// <summary>
  21. /// Used internally for implementing `IWebView.ConsoleMessageLogged`.
  22. /// </summary>
  23. [Serializable]
  24. class ConsoleBridgeMessage : BridgeMessage {
  25. public string message;
  26. public string level;
  27. public string source;
  28. public int line;
  29. public ConsoleMessageEventArgs ToEventArgs() {
  30. return new ConsoleMessageEventArgs(_parseMessageLevel(level), message, source, line);
  31. }
  32. ConsoleMessageLevel _parseMessageLevel(string levelString) {
  33. switch (levelString) {
  34. case "LOG":
  35. return ConsoleMessageLevel.Log;
  36. case "DEBUG":
  37. return ConsoleMessageLevel.Debug;
  38. case "WARNING":
  39. return ConsoleMessageLevel.Warning;
  40. case "ERROR":
  41. return ConsoleMessageLevel.Error;
  42. default:
  43. WebViewLogger.LogError("Unrecognized ConsoleMessageLevel string: " + levelString);
  44. return ConsoleMessageLevel.Log;
  45. }
  46. }
  47. }
  48. }