示例#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));
        }
示例#2
0
        private void ObjItem_Expanded(object sender, System.Windows.RoutedEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (CheckNotInBreakMode())
            {
                return;
            }

            MyTreeViewItem item = sender as MyTreeViewItem;

            if (item == null)
            {
                return;
            }

            item.Expanded -= ObjItem_Expanded;

            int[] index = item.GetIndexOfItem();
            if (index == null)
            {
                return;
            }

            string transformQuery = GetTransformQuery(index);

            if (!isInitObj)
            {
                dte.Debugger.ExecuteStatement(Statement: "UnityEngine.Transform tf;");
                isInitObj = true;
            }

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

            dte.Debugger.ExecuteStatement(Statement: $"tf = objs{transformQuery};");

            string childCountStr = GetDebuggerExecutionOutput(Statement: $"tf.childCount", TreatAsExpression: true, selection);

            int childCount = int.Parse(childCountStr.SplitAndTrim("\r\n", StringSplitOptions.RemoveEmptyEntries)[0]);

            if (item.hasDummy)
            {
                item.Items.Clear();

                // Get Name
                int lineNum;
                selection.SaveLinePosition(out lineNum);
                for (int i = 0; i < childCount; ++i)
                {
                    dte.Debugger.ExecuteStatement(Statement: $"tf.GetChild({i}).childCount", TreatAsExpression: true);
                }
                string   childCountsInfoStr = selection.GetTextBetweenCurPosToLine(lineNum);
                string[] childCounts        = childCountsInfoStr.SplitAndTrim("\r\n", StringSplitOptions.RemoveEmptyEntries);

                // Get childCount
                selection.SaveLinePosition(out lineNum);
                for (int i = 0; i < childCount; ++i)
                {
                    dte.Debugger.ExecuteStatement(Statement: $"tf.GetChild({i}).name", TreatAsExpression: true);
                }
                string   childNamesInfoStr = selection.GetTextBetweenCurPosToLine(lineNum);
                string[] childNames        = childNamesInfoStr.SplitAndTrim("\r\n", StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < childCount; ++i)
                {
                    MyTreeViewItem objItem = new MyTreeViewItem();
                    objItem.Header         = childNames[i].Trim('"');
                    objItem.doubleClicked += () => Inspect(objItem);
                    if (int.Parse(childCounts[i]) > 0)
                    {
                        objItem.CreateDummy();
                        objItem.Expanded += ObjItem_Expanded;
                    }
                    item.Items.Add(objItem);
                }
            }
            else
            {
                // if the item doesn't have dummy item, we don't need to initialize it again.
            }
        }
示例#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();
        }