Example #1
0
        /// <summary>
        /// 在下拉列表中选择当前的模式时被调用
        /// </summary>
        public override void OnGUI()
        {
            base.OnGUI();

            if (GUILayout.Button(new GUIContent("Add Log"), EditorStyles.toolbarButton))
            {
                UnityDebugViewerLogger.Log("Add Log", MODE_NAME);
            }
        }
        //private const string LOG_FILE_STACK_REGEX = @"(?m)^(?<className>[\w]+(\.[\<\>\w\s\,\`]+)*)[\s]*:[\s]*(?<methodName>[\<\>\w\s\,\`\.]+\([\w\s\,\[\]\<\>\&\*\`]*\))\r*$";

        /// <summary>
        /// Add log to the UnityDebugViewerEditor correspond to 'ADBLogcat'
        /// </summary>
        /// <param name="logcat"></param>
        private void AddLogFileLog(string logStr)
        {
            string editorMode = UnityDebugViewerDefaultMode.LogFile;
            var    match      = Regex.Match(logStr, LOG_FILE_TYPE_AND_TIME_REGEX);

            if (match.Success)
            {
                string  logType = match.Result("${logType}").ToLower();
                string  time    = match.Result("${time}");
                LogType type;
                switch (logType)
                {
                case "log":
                    type = LogType.Log;
                    break;

                case "warning":
                    type = LogType.Warning;
                    break;

                case "error":
                    type = LogType.Error;
                    break;

                default:
                    type = LogType.Error;
                    break;
                }

                string preProcessedStr        = Regex.Replace(logStr, LOG_FILE_TYPE_AND_TIME_REGEX, "").Trim();
                string info                   = Regex.Replace(preProcessedStr, LogData.UNITY_STACK_REGEX, "").Trim();
                string extraInfo              = string.Empty;
                string stackMessage           = string.Empty;
                List <LogStackData> stackList = new List <LogStackData>();

                if (string.IsNullOrEmpty(info) == false)
                {
                    stackMessage = preProcessedStr.Replace(info, "").Trim();
                    match        = Regex.Match(stackMessage, LogData.UNITY_STACK_REGEX);
                    while (match.Success)
                    {
                        stackList.Add(new LogStackData(match));
                        match = match.NextMatch();
                    }

                    if (stackList.Count > 0 && stackList[0].lineNumber == -1)
                    {
                        var stackData = stackList[0];
                        stackList.RemoveAt(0);
                        extraInfo = stackData.ToString();
                    }
                }

                var log = new LogData(info, extraInfo, stackMessage, stackList, time, type);
                UnityDebugViewerLogger.AddLog(log, editorMode);
            }
        }
        /// <summary>
        /// Add log to the UnityDebugViewerEditor correspond to 'ADBForward'
        /// </summary>
        /// <param name="transferLogData"></param>
        private void AddTransferLog(TransferLogData transferLogData)
        {
            string editorMode = UnityDebugViewerDefaultMode.ADBForward;

            LogType type  = (LogType)transferLogData.logType;
            string  info  = transferLogData.info;
            string  stack = transferLogData.stack;

            UnityDebugViewerLogger.AddLog(info, stack, type, editorMode);
        }
        private void DisconnectToServerHandler()
        {
            string adbPath = UnityDebugViewerWindowUtility.GetAdbPath();

            if (UnityDebugViewerADBUtility.CheckDevice(adbPath) == false)
            {
                UnityDebugViewerLogger.LogError("No devices connect, adb forward process should be restart!", UnityDebugViewerDefaultMode.ADBForward);

                StopADBForward();
            }
        }
Example #5
0
        void GenerateLog(float deltaTime)
        {
            timer += deltaTime;
            if (timer >= 1)
            {
                UnityDebugViewerLogger.LogWarning("pass 1s;");
                Debug.LogWarningFormat("pass {0}s;", 1);

                timer = 0f;
            }
        }
        private void ConnectToClientSocket()
        {
            if (clientSocket != null)
            {
                clientSocket.Close();
            }

            try
            {
                clientSocket = serverSocket.Accept();
            }
            catch (Exception e)
            {
                UnityDebugViewerLogger.LogError(e.ToString(), UnityDebugViewerDefaultMode.ADBForward);
            }
        }
        private void FinishCollectingLog()
        {
            if (isCollectingInfo == false)
            {
                return;
            }

            isCollectingInfo  = false;
            isCollectingStack = false;

            Encoding CURRENT_CODE_PAGE = Encoding.Default;
            Encoding TARGET_CODE_PAGE  = Encoding.UTF8;

            /// 使用gb2312对utf8进行编码,获取utf8字节
            byte[] raw = CURRENT_CODE_PAGE.GetBytes(collectedInfo);
            collectedInfo = TARGET_CODE_PAGE.GetString(raw);

            /// 输出收集的信息
            var log = new LogData(collectedInfo, collectedStack, collectedTime, collectingType);

            UnityDebugViewerLogger.AddLog(log, UnityDebugViewerDefaultMode.ADBLogcat);
        }
        private void ConnectToServerSocket()
        {
            if (serverSocket != null)
            {
                serverSocket.Close();
                serverSocket = null;
            }

            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                serverSocket.Connect(ipEndPoint);
            }
            catch (Exception e)
            {
                if (disconnectToServerEvent != null)
                {
                    disconnectToServerEvent();
                }

                UnityDebugViewerLogger.LogError(e.ToString(), UnityDebugViewerDefaultMode.ADBForward);
            }
        }
        /// <summary>
        /// 将log输出至UnityDebugViewerDefaultMode.Editor对应的UnityDebugViewerEditor
        /// </summary>
        /// <param name="transferLogData"></param>
        public static void AddEditorLog(string info, string stack, LogType type)
        {
            string editorType = UnityDebugViewerDefaultMode.Editor;

            UnityDebugViewerLogger.AddLog(info, stack, type, editorType);
        }
Example #10
0
        /// <summary>
        /// 在脚本开始编译时被调用
        /// </summary>
        public override void StartCompiling()
        {
            base.StartCompiling();

            UnityDebugViewerLogger.Log("StartCompiling", MODE_NAME);
        }
Example #11
0
        /// <summary>
        /// 在点击Clear按钮时被调用
        /// </summary>
        public override void Clear()
        {
            base.Clear();

            UnityDebugViewerLogger.Log("Clear", MODE_NAME);
        }
Example #12
0
        public bool StartForwardProcess(string pcPort, string phonePort, string adbPath)
        {
            /// stop first
            StopForwardProcess(adbPath);

            if (CheckDevice(adbPath))
            {
                if (String.IsNullOrEmpty(pcPort))
                {
                    pcPort = UnityDebugViewerADBUtility.DEFAULT_FORWARD_PC_PORT;
                }

                if (String.IsNullOrEmpty(phonePort))
                {
                    phonePort = UnityDebugViewerADBUtility.DEFAULT_FORWARD_PHONE_PORT;
                }

                string           command     = String.Format(UnityDebugViewerADBUtility.START_ADB_FORWARD, pcPort, phonePort);
                ProcessStartInfo forwardInfo = CreateProcessStartInfo(command, adbPath);
                if (forwardInfo != null)
                {
                    using (Process forwardProcess = Process.Start(forwardInfo))
                    {
                        using (StreamReader stdOutput = forwardProcess.StandardOutput)
                        {
                            if (!stdOutput.EndOfStream)
                            {
                                string output = stdOutput.ReadLine();
                                if (!String.IsNullOrEmpty(output))
                                {
                                    int port = 0;
                                    if (int.TryParse(output, out port))
                                    {
                                        UnityDebugViewerLogger.AddLog(string.Format("Start adb forward successfully at port: {0}", port), String.Empty, LogType.Log, UnityDebugViewerDefaultMode.ADBForward);
                                    }
                                    else
                                    {
                                        UnityDebugViewerLogger.AddLog(String.Format("[{0}] {1}", "Start adb forward process faild", output), String.Empty, LogType.Error, UnityDebugViewerDefaultMode.ADBForward);
                                        return(false);
                                    }
                                }
                            }
                        }

                        using (StreamReader errorOutPut = forwardProcess.StandardError)
                        {
                            if (!errorOutPut.EndOfStream)
                            {
                                string output = errorOutPut.ReadLine();
                                if (!string.IsNullOrEmpty(output))
                                {
                                    UnityDebugViewerLogger.AddLog(String.Format("[{0}] {1}", "Start adb forward process faild", output), String.Empty, LogType.Error, UnityDebugViewerDefaultMode.ADBForward);
                                }

                                return(false);
                            }
                        }
                    }

                    return(true);
                }
            }

            return(false);
        }
        public static void ClearNativeConsoleWindow()
        {
            Assembly unityEditorAssembly = Assembly.GetAssembly(typeof(EditorWindow));
            Type     logEntriesType      = unityEditorAssembly.GetType("UnityEditor.LogEntries");

            if (logEntriesType == null)
            {
                logEntriesType = unityEditorAssembly.GetType("UnityEditorInternal.LogEntries");
                if (logEntriesType == null)
                {
                    return;
                }
            }

            object logEntriesInstance = Activator.CreateInstance(logEntriesType);
            var    clearMethod        = logEntriesType.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            if (clearMethod != null)
            {
                clearMethod.Invoke(logEntriesInstance, null);
            }

            var getCountMethod = logEntriesType.GetMethod("GetCount", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            if (getCountMethod == null)
            {
                return;
            }

            int count = (int)getCountMethod.Invoke(logEntriesInstance, null);

            if (count > 0)
            {
                Type logEntryType = unityEditorAssembly.GetType("UnityEditor.LogEntry");
                if (logEntryType == null)
                {
                    logEntryType = unityEditorAssembly.GetType("UnityEditorInternal.LogEntry");
                    if (logEntryType == null)
                    {
                        return;
                    }
                }
                object logEntryInstacne = Activator.CreateInstance(logEntryType);

                var startGettingEntriesMethod = logEntriesType.GetMethod("StartGettingEntries", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                var endGettingEntriesMethod   = logEntriesType.GetMethod("EndGettingEntries", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                var getEntryInternalMethod    = logEntriesType.GetMethod("GetEntryInternal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                if (startGettingEntriesMethod == null || endGettingEntriesMethod == null || getEntryInternalMethod == null)
                {
                    return;
                }

                var infoFieldInfo = logEntryType.GetField("message", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (infoFieldInfo == null)
                {
                    infoFieldInfo = logEntryType.GetField("condition", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if (infoFieldInfo == null)
                    {
                        return;
                    }
                }

                string info;
                startGettingEntriesMethod.Invoke(logEntriesInstance, null);
                for (int i = 0; i < count; i++)
                {
                    getEntryInternalMethod.Invoke(logEntriesInstance, new object[] { i, logEntryInstacne });
                    if (logEntryInstacne == null)
                    {
                        continue;
                    }

                    info = infoFieldInfo.GetValue(logEntryInstacne).ToString();
                    UnityDebugViewerLogger.AddLog(info, string.Empty, LogType.Error, UnityDebugViewerDefaultMode.Editor);
                }
                endGettingEntriesMethod.Invoke(logEntriesInstance, null);
            }
        }