1- #include " pch.h"
1+ #include " pch.h"
22#include " inspector.h"
33
4- void Inspector::RenderHierarchyNode (HierarchyNode& node, const int depth)
5- {
6- if (!Core::helper->SafeIsAlive (node.gameObject )) return ;
7-
8- bool matchesSearch = true ;
9- if (searchBuffer[0 ] != ' \0 ' )
10- {
11- matchesSearch = node.name .find (searchBuffer) != std::string::npos;
12-
13- if (!matchesSearch)
14- {
15- for (auto & child : node.children )
16- {
17- std::function<bool (HierarchyNode&)> checkChildren = [&](HierarchyNode& n) -> bool {
18- if (n.name .find (searchBuffer) != std::string::npos) return true ;
19- for (auto & c : n.children )
20- {
21- if (checkChildren (c)) return true ;
22- }
23- return false ;
24- };
25- if (checkChildren (child))
26- {
27- matchesSearch = true ;
28- break ;
29- }
30- }
31- }
32- }
33-
34- if (!matchesSearch) return ;
35-
36- ImGui::PushID (node.gameObject );
37-
38- const bool hasChildren = !node.children .empty ();
39- const bool isSelected = (FindTabForObject (node.gameObject ) >= 0 );
40-
41- ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth;
42- if (!hasChildren) flags |= ImGuiTreeNodeFlags_Leaf;
43- if (isSelected) flags |= ImGuiTreeNodeFlags_Selected;
44-
45- bool isActive = true ;
46- if (!Core::helper->SafeGetActiveSelf (node.gameObject , isActive))
47- {
48- ImGui::PopID ();
49- return ;
50- }
51-
52- if (!isActive)
53- {
54- ImGui::PushStyleColor (ImGuiCol_Text, ImVec4 (0 .5f , 0 .5f , 0 .5f , 1 .0f ));
55- }
56-
57- const bool nodeOpen = ImGui::TreeNodeEx (node.name .c_str (), flags);
58-
59- if (!isActive)
60- {
61- ImGui::PopStyleColor ();
62- }
63-
64- if (ImGui::IsItemClicked () && !ImGui::IsItemToggledOpen ())
65- {
66- OpenObjectInNewTab (node.gameObject );
67- }
68-
69- if (ImGui::BeginPopupContextItem ())
70- {
71- if (ImGui::MenuItem (" Inspect" ))
72- {
73- OpenObjectInNewTab (node.gameObject );
74- }
75- ImGui::EndPopup ();
76- }
77-
78- if (nodeOpen)
79- {
80- for (auto & child : node.children )
81- {
82- RenderHierarchyNode (child, depth + 1 );
83- }
84- ImGui::TreePop ();
85- }
86-
87- ImGui::PopID ();
88- }
894void Inspector::RenderEditableField (UT::Component* component, const ComponentFieldInfo& field) const
905{
916 if (!component || field.offset < 0 ) return ;
@@ -692,7 +607,6 @@ void Inspector::RenderTransformSection(UT::Transform* transform, InspectedObject
692607 }
693608}
694609
695-
696610void Inspector::RenderMethodsSection (UT::Component* component, const std::vector<ComponentMethodInfo>& methods, InspectedObjectTab& tab, const size_t componentIndex)
697611{
698612 if (methods.empty ())
@@ -1364,7 +1278,7 @@ void Inspector::RenderTabContent(InspectedObjectTab& tab)
13641278 ImGui::Text (" Tag: %s" , tag->ToString ().c_str ());
13651279 }
13661280 }
1367-
1281+
13681282 if (bool isStatic = false ; Helper::SafeGetIsStatic (tab.gameObject , isStatic))
13691283 {
13701284 ImGui::SameLine ();
@@ -1392,12 +1306,12 @@ void Inspector::RenderTabContent(InspectedObjectTab& tab)
13921306 if (ImGui::BeginChild (" Content" , ImVec2 (0 , 0 ), false ))
13931307 {
13941308 UT::Transform* transform = nullptr ;
1395-
1309+
13961310 if (tab.gameObject && Core::helper->SafeIsAlive (tab.gameObject ))
13971311 {
13981312 Core::helper->SafeGetTransform (tab.gameObject , transform);
13991313 }
1400-
1314+
14011315
14021316 if (transform)
14031317 {
@@ -1413,153 +1327,4 @@ void Inspector::RenderTabContent(InspectedObjectTab& tab)
14131327 RenderComponentsSection (tab);
14141328 }
14151329 ImGui::EndChild ();
1416- }
1417-
1418- void Inspector::RenderMethodInvokePopup ()
1419- {
1420- if (!invokeState.showPopup ) return ;
1421-
1422- ImGui::SetNextWindowSize (ImVec2 (400 , 300 ), ImGuiCond_FirstUseEver);
1423-
1424- std::string title = " Invoke: " + invokeState.method .name + " ###MethodInvoke" ;
1425- if (ImGui::Begin (title.c_str (), &invokeState.showPopup ))
1426- {
1427- ImGui::Text (" Method: %s" , invokeState.method .name .c_str ());
1428- ImGui::Text (" Return Type: %s" , invokeState.method .returnTypeName .c_str ());
1429- if (invokeState.method .isStatic )
1430- {
1431- ImGui::SameLine ();
1432- ImGui::TextColored (ImVec4 (0 .5f , 0 .8f , 1 .0f , 1 .0f ), " [Static]" );
1433- }
1434-
1435- ImGui::Separator ();
1436-
1437- if (invokeState.method .parameters .empty ())
1438- {
1439- ImGui::TextDisabled (" No parameters" );
1440- }
1441- else
1442- {
1443- ImGui::Text (" Parameters:" );
1444- for (size_t i = 0 ; i < invokeState.method .parameters .size (); i++)
1445- {
1446- const auto & [name, typeName] = invokeState.method .parameters [i];
1447- const auto paramType = invokeState.method .parameterEditableTypes [i];
1448-
1449- ImGui::PushID (static_cast <int >(i));
1450-
1451- std::string label = name + " (" + typeName + " )" ;
1452- ImGui::Text (" %s" , label.c_str ());
1453- ImGui::SameLine ();
1454-
1455- char buf[256 ] = {};
1456- if (i < invokeState.parameterValues .size () && !invokeState.parameterValues [i].empty ())
1457- {
1458- strncpy_s (buf, invokeState.parameterValues [i].c_str (), sizeof (buf) - 1 );
1459- }
1460-
1461- ImGui::SetNextItemWidth (-1 );
1462- switch (paramType)
1463- {
1464- case EditableType::Int:
1465- case EditableType::Float:
1466- case EditableType::Double:
1467- if (ImGui::InputText (" ##param" , buf, sizeof (buf), ImGuiInputTextFlags_CharsDecimal))
1468- {
1469- invokeState.parameterValues [i] = buf;
1470- }
1471- break ;
1472- case EditableType::Bool:
1473- {
1474- bool val = (invokeState.parameterValues [i] == " true" || invokeState.parameterValues [i] == " 1" );
1475- if (ImGui::Checkbox (" ##param" , &val))
1476- {
1477- invokeState.parameterValues [i] = val ? " true" : " false" ;
1478- }
1479- break ;
1480- }
1481- default :
1482- if (ImGui::InputText (" ##param" , buf, sizeof (buf)))
1483- {
1484- invokeState.parameterValues [i] = buf;
1485- }
1486- break ;
1487- }
1488-
1489- ImGui::PopID ();
1490- }
1491- }
1492-
1493- ImGui::Separator ();
1494-
1495- if (ImGui::Button (" Invoke" , ImVec2 (100 , 0 )))
1496- {
1497- void * result = InvokeMethod (invokeState.targetComponent , invokeState.method , invokeState.parameterValues );
1498-
1499- invokeState.hasResult = true ;
1500- if (result)
1501- {
1502- if (invokeState.method .returnTypeName == " void" || invokeState.method .returnTypeName == " System.Void" )
1503- {
1504- invokeState.resultText = " (void)" ;
1505- }
1506- else
1507- {
1508- const EditableType retType = DetermineEditableType (invokeState.method .returnTypeName );
1509- void * unboxed = UR::Invoke<void *, void *>(
1510- Core::config->gameMode == UnityResolve::Mode::Mono ? " mono_object_unbox" : " il2cpp_object_unbox" , result);
1511-
1512- if (unboxed)
1513- {
1514- switch (retType)
1515- {
1516- case EditableType::Int:
1517- invokeState.resultText = std::to_string (*static_cast <int *>(unboxed));
1518- break ;
1519- case EditableType::Float:
1520- invokeState.resultText = std::to_string (*static_cast <float *>(unboxed));
1521- break ;
1522- case EditableType::Double:
1523- invokeState.resultText = std::to_string (*static_cast <double *>(unboxed));
1524- break ;
1525- case EditableType::Bool:
1526- invokeState.resultText = *static_cast <bool *>(unboxed) ? " true" : " false" ;
1527- break ;
1528- default :
1529- invokeState.resultText = std::format (" (object: 0x{:X})" , reinterpret_cast <uintptr_t >(result));
1530- break ;
1531- }
1532- }
1533- else
1534- {
1535- invokeState.resultText = std::format (" (object: 0x{:X})" , reinterpret_cast <uintptr_t >(result));
1536- }
1537- }
1538- }
1539- else
1540- {
1541- if (invokeState.method .returnTypeName == " void" || invokeState.method .returnTypeName == " System.Void" )
1542- {
1543- invokeState.resultText = " (completed)" ;
1544- }
1545- else
1546- {
1547- invokeState.resultText = " (null or error)" ;
1548- }
1549- }
1550- }
1551-
1552- ImGui::SameLine ();
1553- if (ImGui::Button (" Close" , ImVec2 (100 , 0 )))
1554- {
1555- invokeState.showPopup = false ;
1556- }
1557-
1558- if (invokeState.hasResult )
1559- {
1560- ImGui::Separator ();
1561- ImGui::Text (" Result: %s" , invokeState.resultText .c_str ());
1562- }
1563- }
1564- ImGui::End ();
15651330}
0 commit comments