浏览代码

Merge pull request #14426 from aws-lumberyard-dev/cgalvan/FixNonSvgComponentIcons

Fix non-svg component icons not being loaded
Chris Galvan 2 年之前
父节点
当前提交
57a7df88f7
共有 1 个文件被更改,包括 41 次插入6 次删除
  1. 41 6
      Code/Editor/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp

+ 41 - 6
Code/Editor/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp

@@ -60,8 +60,10 @@
 #include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
 #include <MathConversion.h>
 
+#include <Atom/ImageProcessing/ImageProcessingDefines.h>
 #include <Atom/RPI.Public/ViewportContext.h>
 #include <Atom/RPI.Public/ViewportContextBus.h>
+#include <Atom/RPI.Reflect/Image/StreamingImageAsset.h>
 #include <AtomToolsFramework/Viewport/ModularViewportCameraControllerRequestBus.h>
 
 #include "Objects/ComponentEntityObject.h"
@@ -1926,12 +1928,45 @@ AZStd::string SandboxIntegrationManager::GetComponentIconPath(const AZ::Uuid& co
                 }
                 else
                 {
-                    AZ_Warning(
-                        "SandboxIntegration",
-                        false,
-                        "Unable to find icon path \"%s\" for component type: %s",
-                        iconPath.c_str(),
-                        classData->m_editData->m_name);
+                    // If we couldn't find the full source path, try appending the product extension if the icon
+                    // source asset is one of the supported image assets. Most component icons are in .svg format,
+                    // which isn't actually consumed by the Asset Processor so the GetFullSourcePathFromRelativeProductPath
+                    // API can find the source asset without needing the product extension as well. So this edge case is
+                    // to cover any component icons that are still using other formats (e.g. png), that haven't been converted
+                    // to .svg yet, or for customers that prefer to use image formats besides .svg.
+                    AZStd::string extension;
+                    AzFramework::StringFunc::Path::GetExtension(iconPath.c_str(), extension);
+                    bool supportedStreamingImage = false;
+                    for (int i = 0; i < ImageProcessingAtom::s_TotalSupportedImageExtensions; ++i)
+                    {
+                        if (AZStd::wildcard_match(ImageProcessingAtom::s_SupportedImageExtensions[i], extension.c_str()))
+                        {
+                            supportedStreamingImage = true;
+                            break;
+                        }
+                    }
+                    if (supportedStreamingImage)
+                    {
+                        iconPath = AZStd::string::format("%s.%s", iconPath.c_str(), AZ::RPI::StreamingImageAsset::Extension);
+
+                        AssetSysReqBus::BroadcastResult(
+                            pathFound, &AssetSysReqBus::Events::GetFullSourcePathFromRelativeProductPath,
+                            iconPath, iconFullPath);
+                    }
+
+                    if (pathFound)
+                    {
+                        iconPath = AZStd::move(iconFullPath);
+                    }
+                    else
+                    {
+                        AZ_Warning(
+                            "SandboxIntegration",
+                            false,
+                            "Unable to find icon path \"%s\" for component type: %s",
+                            iconPath.c_str(),
+                            classData->m_editData->m_name);
+                    }
                 }
             }
         }