Browse Source

Added editor context for decal bus, fixed opacity issue, added global BC method for getting the RPI Scene from a name.

Signed-off-by: Ken Pruiksma <[email protected]>
Ken Pruiksma 2 năm trước cách đây
mục cha
commit
cc88bae665

+ 28 - 2
Gem/Code/Include/DecalBus.h

@@ -29,11 +29,37 @@ namespace MultiplayerSample
 
     void SpawnDecalConfig::Reflect(AZ::ReflectContext* context)
     {
-        if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
+        if (AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
         {
-            serialize->Class<MultiplayerSample::SpawnDecalConfig>()
+            serializeContext->Class<MultiplayerSample::SpawnDecalConfig>()
                 ->Version(0)
+                ->Field("Scale", &SpawnDecalConfig::m_scale)
+                ->Field("Opacity", &SpawnDecalConfig::m_opacity)
+                ->Field("AttenuationAngle", &SpawnDecalConfig::m_attenutationAngle)
+                ->Field("LifeTime", &SpawnDecalConfig::m_lifeTime)
+                ->Field("FadeTime", &SpawnDecalConfig::m_fadeTime)
+                ->Field("SortKey", &SpawnDecalConfig::m_sortKey)
                 ;
+
+            if (auto editContext = serializeContext->GetEditContext())
+            {
+                editContext->Class<SpawnDecalConfig>("SpawnDecalConfig", "Configuration settings for spawning a decal.")
+                    ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
+                    ->Attribute(AZ::Edit::Attributes::AutoExpand, true)
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_scale, "Scale", "The scale of the decal.")
+                    ->DataElement(AZ::Edit::UIHandlers::Slider, &SpawnDecalConfig::m_opacity, "Opacity", "The opacity of the decal.")
+                        ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
+                        ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_attenutationAngle, "Angle attenuation", "How much to attenuate the opacity of the decal based on the different in the angle between the decal and the surface.")
+                        ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
+                        ->Attribute(AZ::Edit::Attributes::Max, 1.0f)
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_lifeTime, "Life time", "How long before the decal should begin to fade out, in seconds.")
+                        ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_fadeTime, "Fade time", "How long the decal should spend fading out at the end of its life time.")
+                        ->Attribute(AZ::Edit::Attributes::Min, 0.0f)
+                    ->DataElement(AZ::Edit::UIHandlers::Default, &SpawnDecalConfig::m_sortKey, "Sort key", "Used to sort the decal with other decals. Higher numbered decals show on top of lower number decals.")
+                    ;
+            }
         }
 
         if (auto behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))

+ 1 - 0
Gem/Code/Source/Components/ScriptableDecalComponent.cpp

@@ -146,6 +146,7 @@ namespace MultiplayerSample
             else
             {
                 float opacity = 1.0f - (currentFadeTimeMs / totalFadeTimeMs);
+                opacity *= decalInstance.m_config.m_opacity;
                 m_decalFeatureProcessor->SetDecalOpacity(decalInstance.m_handle, opacity);
                 ++i;
             }

+ 32 - 0
Gem/Code/Source/MultiplayerSampleSystemComponent.cpp

@@ -19,6 +19,9 @@
 #include <Source/Effects/GameEffect.h>
 #include <Multiplayer/Components/NetBindComponent.h>
 
+#include <AzFramework/Scene/Scene.h>
+#include <Atom/RPI.Public/Scene.h>
+
 namespace MultiplayerSample
 {
     using namespace AzNetworking;
@@ -51,6 +54,21 @@ namespace MultiplayerSample
                     ;
             }
         }
+
+        if (AZ::BehaviorContext* behaviorContext = azrtti_cast<AZ::BehaviorContext*>(context))
+        {
+            // This will put these methods into the 'azlmbr.atomtools.general' module
+            auto addGeneral = [](AZ::BehaviorContext::GlobalMethodBuilder methodBuilder)
+            {
+                methodBuilder->Attribute(AZ::Script::Attributes::Scope, AZ::Script::Attributes::ScopeFlags::Common)
+                    ->Attribute(AZ::Script::Attributes::Category, "MultiplayerSample")
+                    ->Attribute(AZ::Script::Attributes::Module, "MultiplayerSample.general");
+            };
+
+            addGeneral(behaviorContext->Method(
+                "GetRenderSceneIdByName", &MultiplayerSampleSystemComponent::GetRenderSceneIdByName, nullptr,
+                "Gets an RPI scene ID based on the name of the AzFramework Scene."));
+        }
     }
 
     void MultiplayerSampleSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
@@ -88,5 +106,19 @@ namespace MultiplayerSample
     void MultiplayerSampleSystemComponent::Deactivate()
     {
     }
+
+    AZ::Uuid MultiplayerSampleSystemComponent::GetRenderSceneIdByName(const AZStd::string& name)
+    {
+        AZStd::shared_ptr<AzFramework::Scene> scene = AzFramework::SceneSystemInterface::Get()->GetScene(name);
+        if (scene)
+        {
+            AZ::RPI::Scene* renderScene = scene->FindSubsystemInScene<AZ::RPI::Scene>();
+            if (renderScene)
+            {
+                return renderScene->GetId();
+            }
+        }
+        return AZ::Uuid::CreateInvalid();
+    }
 }
 

+ 2 - 1
Gem/Code/Source/MultiplayerSampleSystemComponent.h

@@ -9,7 +9,6 @@
 
 #include <AzCore/Component/Component.h>
 
-
 namespace MultiplayerSample
 {
     class MultiplayerSampleSystemComponent
@@ -31,5 +30,7 @@ namespace MultiplayerSample
         void Activate() override;
         void Deactivate() override;
         ////////////////////////////////////////////////////////////////////////
+
+        static AZ::Uuid GetRenderSceneIdByName(const AZStd::string& name);
     };
 }