private void Inspect(MyTreeViewItem item) { ThreadHelper.ThrowIfNotOnUIThread(); if (CheckNotInBreakMode()) { return; } inspectorWindow.control.ParentPanel.Children.Clear(); VsUnityInspectorCommand.Instance.curInspectedObjects.Clear(); int[] index = item.GetIndexOfItem(); string tfQuery = GetTransformQuery(index); if (!isInitInspectObj) { dte.Debugger.ExecuteStatement(Statement: "UnityEngine.GameObject inspectObj;"); isInitInspectObj = true; } EnvDTE.TextSelection selection = commandWindow?.Selection as EnvDTE.TextSelection; string gameObjectInfo = GetDebuggerExecutionOutput(Statement: $"inspectObj = objs{tfQuery}.gameObject;", TreatAsExpression: true, selection); VsGameObject obj = new VsGameObject(gameObjectInfo); obj.Inspect(inspectorWindow); VsUnityInspectorCommand.Instance.curInspectedObjects.Add(obj); }
/// <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(); }