Beispiel #1
0
        private string GetDebuggerExecutionOutput(string Statement, bool TreatAsExpression, EnvDTE.TextSelection selection)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            int saveLineNum;

            selection.EndOfDocument();
            selection.SaveLinePosition(out saveLineNum);
            dte.Debugger.ExecuteStatement(Statement: Statement, TreatAsExpression: TreatAsExpression);
            return(selection.GetTextBetweenCurPosToLine(saveLineNum));
        }
Beispiel #2
0
        internal void FillPreviewFromDocument(BlockCollection blocks, EnvDTE.TextSelection selection, ResultItem resultLine)
        {
            if (selection != null)
            {
                selection.EndOfDocument();
                int docLength  = selection.CurrentLine;
                int countEmpty = 0;

                Paragraph paragraph = new Paragraph();
                blocks.Add(paragraph);

                //Pre
                for (int i = resultLine.lineNumber.Value - 2; i < 1; i++)
                {
                    paragraph.Inlines.Add(new Run("\n"));
                    countEmpty++;
                }
                for (int i = Math.Max(1, resultLine.lineNumber.Value - 2); i < resultLine.lineNumber.Value; i++)
                {
                    selection.GotoLine(i, true);
                    paragraph.Inlines.Add(new Run(selection.Text + "\n"));
                }
                //Res
                selection.GotoLine(resultLine.lineNumber.Value, true);
                (string pre, string res, string post) = resultLine.GetSplitLine(selection.Text, false);
                paragraph.Inlines.Add(new Run(pre));
                paragraph.Inlines.Add(new Run(res)
                {
                    Foreground = Brushes.Red
                });
                paragraph.Inlines.Add(new Run(post + "\n"));
                //Post
                for (int i = 1; i <= Math.Min(2, docLength - resultLine.lineNumber.Value); i++)
                {
                    selection.GotoLine(resultLine.lineNumber.Value + i, true);
                    paragraph.Inlines.Add(new Run(selection.Text + "\n"));
                }
            }
            return;
        }
Beispiel #3
0
        /// <summary>
        /// Refresh Unity Hierarchy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Refresh(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (CheckNotInBreakMode())
            {
                return;
            }

            EnvDTE.TextSelection selection = commandWindow?.Selection as EnvDTE.TextSelection;

            if (selection == null)
            {
                ShowMessage(
                    "Error!",
                    "Cannot find command window automatically\nPlease manually activate it and try again.",
                    OLEMSGICON.OLEMSGICON_CRITICAL);
                return;
            }


            if (!isInitSceneAndRootObj)
            {
                dte.Debugger.ExecuteStatement(Statement: "UnityEngine.SceneManagement.Scene scene;");
                dte.Debugger.ExecuteStatement(Statement: "UnityEngine.GameObject[] objs;");
                isInitSceneAndRootObj = true;
            }

            // Get Active Scene
            string sceneInfoStr = GetDebuggerExecutionOutput(Statement: "scene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();", TreatAsExpression: true, selection);

            VsScene scene = new VsScene(sceneInfoStr);

            // Get Root GameObjects
            string objInfoStr = GetDebuggerExecutionOutput(Statement: "objs = scene.GetRootGameObjects();", TreatAsExpression: true, selection);

            string[] gameObjectNames = OuputParseUtil.GetGameObjectNamesFromInfo(objInfoStr);

            // Get ChildCount of each GameObjects
            int saveLineNum;

            selection.SaveLinePosition(out saveLineNum);
            for (int i = 0; i < scene.rootCount; ++i)
            {
                dte.Debugger.ExecuteStatement(Statement: $"objs[{i}].transform.childCount;", TreatAsExpression: true);
            }
            string childCountInfoStr = selection.GetTextBetweenCurPosToLine(saveLineNum);

            string[] childCountsStr = childCountInfoStr.SplitAndTrim("\r\n", StringSplitOptions.RemoveEmptyEntries);

            var objs = new System.Collections.Generic.List <VsGameObject>();

            for (int i = 0; i < gameObjectNames.Length; ++i)
            {
                VsGameObject go = new VsGameObject();
                go.name       = gameObjectNames[i];
                go.childCount = int.Parse(childCountsStr[i]);

                objs.Add(go);
            }

            InitHierarchyView(scene, objs);

            selection.EndOfDocument();
        }