| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /**
- * Copyright (c) 2021 Vuplex Inc. All rights reserved.
- *
- * Licensed under the Vuplex Commercial Software Library License, you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * https://vuplex.com/commercial-library-license
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- using UnityEngine;
- namespace Vuplex.WebView {
- /// <summary>
- /// Utility class used internally for logging.
- /// </summary>
- public static class WebViewLogger {
- public static void Log(string message, bool enableFormatting = true) {
- if (enableFormatting) {
- Debug.Log(_format(message));
- } else {
- Debug.Log(PREFIX + message);
- }
- }
- public static void LogError(string message, bool enableFormatting = true) {
- if (enableFormatting) {
- Debug.LogError(_format(message));
- } else {
- Debug.LogError(PREFIX + message);
- }
- }
- public static void LogErrorFormat(string message, params object[] args) {
- Debug.LogErrorFormat(_format(message), args);
- }
- public static void LogErrorWithoutFormatting(string message) {
- Debug.LogError(PREFIX + message);
- }
- public static void LogFormat(string message, params object[] args) {
- Debug.LogFormat(_format(message), args);
- }
- public static void LogWarning(string message, bool enableFormatting = true) {
- if (enableFormatting) {
- Debug.LogWarning(_format(message));
- } else {
- Debug.LogWarning(PREFIX + message);
- }
- }
- public static void LogWarningFormat(string message, params object[] args) {
- Debug.LogWarningFormat(_format(message), args);
- }
- public static void LogWarningWithoutFormatting(string message) {
- Debug.LogWarning(PREFIX + message);
- }
- // Markup in log messages is only useful in the editor,
- // so omit the markup when not in the editor to prevent clutter.
- #if UNITY_EDITOR
- const string PREFIX = "<color=#12bae9ff>[3D WebView]</color> ";
- const string EM_OPENING_REPLACEMENT = "<color=#12bae9ff>";
- const string EM_CLOSING_REPLACEMENT = "</color>";
- #else
- const string PREFIX = "[3D WebView] ";
- const string EM_OPENING_REPLACEMENT = "";
- const string EM_CLOSING_REPLACEMENT = "";
- #endif
- static string _format(string originalMessage) {
- // Implement the <em> tag for highlighting.
- var formattedMessage = originalMessage;
- if (formattedMessage.Contains("<em>")) {
- formattedMessage = formattedMessage.Replace("<em>", EM_OPENING_REPLACEMENT)
- .Replace("</em>", EM_CLOSING_REPLACEMENT);
- }
- return PREFIX + formattedMessage;
- }
- }
- }
|