Exemplo n.º 1
0
        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);
        }
Exemplo n.º 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.
            }
        }