feat(editor): Stage 4 completed - Implement asset GUID reverse resolve in Inspector with rich UI presentation
This commit is contained in:
parent
a8022e5808
commit
edf6402a6a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -152,6 +152,7 @@ void MetaCoreCopyStringToBuffer(const std::string& value, char* buffer, std::siz
|
||||
}
|
||||
|
||||
[[nodiscard]] bool MetaCoreEditAssetGuidField(
|
||||
MetaCoreEditorContext& editorContext,
|
||||
const char* label,
|
||||
MetaCoreAssetGuid& assetGuid,
|
||||
const char* emptyHint = "<None>"
|
||||
@ -161,6 +162,54 @@ void MetaCoreCopyStringToBuffer(const std::string& value, char* buffer, std::siz
|
||||
MetaCoreCopyStringToBuffer(currentValue, buffer.data(), buffer.size());
|
||||
|
||||
const bool changed = ImGui::InputText(label, buffer.data(), buffer.size());
|
||||
|
||||
if (assetGuid.IsValid()) {
|
||||
const auto assetEditingService = editorContext.GetModuleRegistry().ResolveService<MetaCoreIAssetEditingService>();
|
||||
const auto assetDatabaseService = editorContext.GetModuleRegistry().ResolveService<MetaCoreIAssetDatabaseService>();
|
||||
|
||||
std::string friendlyName{};
|
||||
std::string sourceFileName{};
|
||||
std::string kindLabel{};
|
||||
|
||||
if (assetEditingService != nullptr) {
|
||||
const auto resolved = assetEditingService->ResolveGeneratedAsset(assetGuid);
|
||||
if (resolved.has_value()) {
|
||||
sourceFileName = resolved->SourceAsset.RelativePath.filename().string();
|
||||
kindLabel = resolved->GeneratedKind;
|
||||
|
||||
// 尝试读取模型资源,以查找更详细的原始子项名称
|
||||
const auto model = assetEditingService->LoadModelAsset(resolved->SourceAsset.Guid);
|
||||
if (model.has_value()) {
|
||||
if (resolved->GeneratedKind == "mesh" && resolved->GeneratedIndex < model->GeneratedMeshAssets.size()) {
|
||||
friendlyName = model->GeneratedMeshAssets[resolved->GeneratedIndex].Name;
|
||||
} else if (resolved->GeneratedKind == "material" && resolved->GeneratedIndex < model->GeneratedMaterialAssets.size()) {
|
||||
friendlyName = model->GeneratedMaterialAssets[resolved->GeneratedIndex].Name;
|
||||
} else if (resolved->GeneratedKind == "texture" && resolved->GeneratedIndex < model->GeneratedTextureAssets.size()) {
|
||||
friendlyName = model->GeneratedTextureAssets[resolved->GeneratedIndex].Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (friendlyName.empty() && assetDatabaseService != nullptr) {
|
||||
const auto record = assetDatabaseService->FindAssetByGuid(assetGuid);
|
||||
if (record.has_value()) {
|
||||
friendlyName = record->RelativePath.filename().string();
|
||||
kindLabel = record->Type;
|
||||
}
|
||||
}
|
||||
|
||||
if (!friendlyName.empty()) {
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.3F, 0.75F, 0.9F, 1.0F));
|
||||
if (!sourceFileName.empty()) {
|
||||
ImGui::Text(" ↳ 源模型: %s (%s: %s)", sourceFileName.c_str(), kindLabel.c_str(), friendlyName.c_str());
|
||||
} else {
|
||||
ImGui::Text(" ↳ 关联资源: (%s: %s)", kindLabel.c_str(), friendlyName.c_str());
|
||||
}
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
return false;
|
||||
}
|
||||
@ -1566,7 +1615,7 @@ void MetaCoreDrawMeshRendererComponentInspector(MetaCoreEditorContext& editorCon
|
||||
meshAssetGuid
|
||||
);
|
||||
}
|
||||
if (MetaCoreEditAssetGuidField("Mesh Asset Guid", meshAssetGuid)) {
|
||||
if (MetaCoreEditAssetGuidField(editorContext, "Mesh Asset Guid", meshAssetGuid)) {
|
||||
MetaCoreTrackComponentInspectorEdit(editorContext, "修改检查器属性", false);
|
||||
MetaCoreApplyValueToSelectedObjects(
|
||||
editorContext,
|
||||
@ -1627,7 +1676,7 @@ void MetaCoreDrawMeshRendererComponentInspector(MetaCoreEditorContext& editorCon
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
const std::string label = "Material Guid " + std::to_string(materialIndex);
|
||||
if (MetaCoreEditAssetGuidField(label.c_str(), materialGuid)) {
|
||||
if (MetaCoreEditAssetGuidField(editorContext, label.c_str(), materialGuid)) {
|
||||
MetaCoreTrackComponentInspectorEdit(editorContext, "修改检查器属性", false);
|
||||
MetaCoreForEachSelectedGameObject(editorContext, [&](MetaCoreGameObject& selectedObject) {
|
||||
if (!selectedObject.HasComponent<MetaCoreMeshRendererComponent>()) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user