Sfoglia il codice sorgente

Added a runtime switch for filtering example

Signed-off-by: AMZN-Olex <[email protected]>
AMZN-Olex 4 anni fa
parent
commit
e69846a98b

+ 4 - 2
Gem/Code/Source/Components/ExampleFilteredEntityComponent.cpp

@@ -8,6 +8,8 @@
 #include <AzCore/Serialization/EditContext.h>
 #include <Components/ExampleFilteredEntityComponent.h>
 
+AZ_CVAR(bool, mps_EnableFilteringEntities, true, nullptr, AZ::ConsoleFunctorFlags::Null, "If true, enables the example of filtering entities");
+
 namespace MultiplayerSample
 {
     void ExampleFilteredEntityComponent::Reflect(AZ::ReflectContext* context)
@@ -47,7 +49,7 @@ namespace MultiplayerSample
         [[maybe_unused]] Multiplayer::ConstNetworkEntityHandle controllerEntity,
         [[maybe_unused]] AzNetworking::ConnectionId connectionId)
     {
-        if (m_enabled)
+        if (m_enabled && mps_EnableFilteringEntities)
         {
             // Note: @IsEntityFiltered is a hot code path, so do your best to optimize this method.
             // This example just uses entity names for filtering, for the sake of simplicity.
@@ -55,7 +57,7 @@ namespace MultiplayerSample
 
             const bool evenConnectionId = static_cast<uint32_t>(connectionId) % 2 == 0;
 
-            if (entity->GetName().starts_with( evenConnectionId ? "Even" : "Odd" ))
+            if (entity->GetName().starts_with( evenConnectionId ? "Filter Even" : "Filter Odd" ))
             {
                 return true;
             }

+ 27 - 27
Prefabs/FilteredGroup.prefab

@@ -55,7 +55,7 @@
     "Entities": {
         "Entity_[3048586795269]": {
             "Id": "Entity_[3048586795269]",
-            "Name": "Odd - Center",
+            "Name": "Filter Odd - Center",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -115,9 +115,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            10.697113037109377,
+                            15.454638481140137,
                             -0.8704566955566406,
-                            13.459696769714356
+                            7.447368621826172
                         ],
                         "Scale": 2.0
                     },
@@ -215,7 +215,7 @@
         },
         "Entity_[3052881762565]": {
             "Id": "Entity_[3052881762565]",
-            "Name": "Even Ball - Right",
+            "Name": "Filter Even Ball - Right",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -275,9 +275,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            13.09963607788086,
+                            17.857162475585939,
                             -7.941593170166016,
-                            12.56361198425293
+                            6.551283836364746
                         ],
                         "Scale": 1.600000023841858
                     },
@@ -375,7 +375,7 @@
         },
         "Entity_[3366414375173]": {
             "Id": "Entity_[3366414375173]",
-            "Name": "Even Ball - Top",
+            "Name": "Filter Even Ball - Top",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -435,9 +435,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            10.70023822784424,
+                            15.457763671875,
                             -0.8600778579711914,
-                            14.918845176696778
+                            8.906517028808594
                         ],
                         "Scale": 1.600000023841858
                     },
@@ -536,7 +536,7 @@
         },
         "Entity_[3490968426757]": {
             "Id": "Entity_[3490968426757]",
-            "Name": "Even Ball - Left",
+            "Name": "Filter Even Ball - Left",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -596,9 +596,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            8.307453155517579,
+                            13.06497859954834,
                             -7.691213607788086,
-                            12.674665451049805
+                            6.662337303161621
                         ],
                         "Scale": 1.600000023841858
                     },
@@ -697,7 +697,7 @@
         },
         "Entity_[3645587249413]": {
             "Id": "Entity_[3645587249413]",
-            "Name": "Even Ball - Bottom",
+            "Name": "Filter Even Ball - Bottom",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -757,9 +757,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            10.677578926086426,
+                            15.435104370117188,
                             -0.8600778579711914,
-                            10.35712718963623
+                            4.344799041748047
                         ],
                         "Scale": 1.600000023841858
                     },
@@ -858,7 +858,7 @@
         },
         "Entity_[1560636048684]": {
             "Id": "Entity_[1560636048684]",
-            "Name": "Odd",
+            "Name": "Filter Odd",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -918,9 +918,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            12.98590087890625,
+                            17.743427276611329,
                             19.999998092651368,
-                            15.586392402648926
+                            9.574064254760743
                         ],
                         "Scale": 2.0
                     },
@@ -1019,7 +1019,7 @@
         },
         "Entity_[1805449184556]": {
             "Id": "Entity_[1805449184556]",
-            "Name": "Odd",
+            "Name": "Filter Odd",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -1079,9 +1079,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            12.98590087890625,
+                            17.743427276611329,
                             19.999998092651368,
-                            11.36227035522461
+                            5.349942207336426
                         ],
                         "Scale": 2.0
                     },
@@ -1180,7 +1180,7 @@
         },
         "Entity_[2080327091500]": {
             "Id": "Entity_[2080327091500]",
-            "Name": "Odd",
+            "Name": "Filter Odd",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -1240,9 +1240,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            8.249576568603516,
+                            13.007102012634278,
                             19.999998092651368,
-                            11.36227035522461
+                            5.349942207336426
                         ],
                         "Scale": 2.0
                     },
@@ -1341,7 +1341,7 @@
         },
         "Entity_[2385269769516]": {
             "Id": "Entity_[2385269769516]",
-            "Name": "Odd",
+            "Name": "Filter Odd",
             "Components": {
                 "Component_[11768834068539124644]": {
                     "$type": "SelectionComponent",
@@ -1401,9 +1401,9 @@
                     },
                     "Cached World Transform": {
                         "Translation": [
-                            8.249576568603516,
+                            13.007102012634278,
                             19.999998092651368,
-                            15.641016006469727
+                            9.628687858581543
                         ],
                         "Scale": 2.0
                     },