Kaynağa Gözat

Add visual apples

Alex Peterson 2 yıl önce
ebeveyn
işleme
197e43daee

+ 14 - 0
Project/Assets/Importer/apple_kraken_5.prefab

@@ -1764,6 +1764,13 @@
                         }
                     }
                 },
+                "Component_[4311952861573879719]": {
+                    "$type": "EditorTagComponent",
+                    "Id": 4311952861573879719,
+                    "Tags": [
+                        "Robot"
+                    ]
+                },
                 "Component_[5034300848744399910]": {
                     "$type": "EditorEntityIconComponent",
                     "Id": 5034300848744399910
@@ -3484,6 +3491,13 @@
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 10024056911688572127
                 },
+                "Component_[10784749401815499991]": {
+                    "$type": "EditorTagComponent",
+                    "Id": 10784749401815499991,
+                    "Tags": [
+                        "RobotCamera"
+                    ]
+                },
                 "Component_[12122484710959107959]": {
                     "$type": "{CA11DA46-29FF-4083-B5F6-E02C3A8C3A3D} EditorCameraComponent",
                     "Id": 12122484710959107959,

+ 3 - 0
Project/Assets/apple_tree/AppleTreeApples.fbx

@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:344f2e6d0e7c0c057757b7223a5125bc66d9716ee76fb26232b07598d3424f2d
+size 427884

+ 1 - 1
Project/Assets/apple_tree/AppleTreeRow4.fbx

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
-oid sha256:804ccda0faa1c03aeebda0261b3691f3bc9fa60dff67d25d17b5df5785460a86
+oid sha256:749a48d3d0d57f81e9a1d140faede18067c0f998c70d74921ba1324ef3ef4d10
 size 15531884

+ 31 - 36
Project/Levels/MainNoVegMerged/MainNoVegMerged.prefab

@@ -733,7 +733,7 @@
                     "Controller": {
                         "Configuration": {
                             "Field of View": 55.0,
-                            "EditorEntityId": 11168432045429722979
+                            "EditorEntityId": 11787391379556193736
                         }
                     }
                 },
@@ -768,7 +768,10 @@
                 },
                 "Component_[4139792706634450598]": {
                     "$type": "EditorTagComponent",
-                    "Id": 4139792706634450598
+                    "Id": 4139792706634450598,
+                    "Tags": [
+                        "FollowTarget"
+                    ]
                 },
                 "Component_[4270857261190589273]": {
                     "$type": "AZ::Render::EditorExposureControlComponent",
@@ -824,8 +827,7 @@
                     "$type": "GenericComponentWrapper",
                     "Id": 7255796294953281766,
                     "m_template": {
-                        "$type": "FlyCameraInputComponent",
-                        "Is enabled": false
+                        "$type": "FlyCameraInputComponent"
                     }
                 },
                 "Component_[8866210352157164042]": {
@@ -1021,7 +1023,7 @@
                                 },
                                 "assetHint": "reflectionprobes/refprobmain__c4ee43e2-3ffe-4955-9dee-679ca04c2a53__iblspecularcm256.dds.streamingimage"
                             },
-                            "EntityId": 4121900811854724983
+                            "EntityId": 16795520573185795105
                         }
                     },
                     "useBakedCubemap": false,
@@ -1358,7 +1360,7 @@
                     "$type": "EditorImageGradientComponent",
                     "Id": 6913475367130875979,
                     "Previewer": {
-                        "BoundsEntity": "Entity_[296994751178328]"
+                        "BoundsEntity": ""
                     },
                     "Configuration": {
                         "StreamingImageAsset": {
@@ -1561,7 +1563,7 @@
                     "$type": "EditorImageGradientComponent",
                     "Id": 10707924659521035089,
                     "Previewer": {
-                        "BoundsEntity": "Entity_[357799673674485]"
+                        "BoundsEntity": ""
                     },
                     "Configuration": {
                         "StreamingImageAsset": {
@@ -1645,7 +1647,7 @@
                     "$type": "EditorImageGradientComponent",
                     "Id": 10707924659521035089,
                     "Previewer": {
-                        "BoundsEntity": "Entity_[357812558576373]"
+                        "BoundsEntity": ""
                     },
                     "Configuration": {
                         "StreamingImageAsset": {
@@ -1921,7 +1923,7 @@
                     "$type": "EditorImageGradientComponent",
                     "Id": 10707924659521035089,
                     "Previewer": {
-                        "BoundsEntity": "Entity_[382784004585584]"
+                        "BoundsEntity": ""
                     },
                     "Configuration": {
                         "StreamingImageAsset": {
@@ -2005,7 +2007,7 @@
                     "$type": "EditorImageGradientComponent",
                     "Id": 10707924659521035089,
                     "Previewer": {
-                        "BoundsEntity": "Entity_[382814069356656]"
+                        "BoundsEntity": ""
                     },
                     "Configuration": {
                         "StreamingImageAsset": {
@@ -3133,13 +3135,6 @@
                     "$type": "EditorInspectorComponent",
                     "Id": 10878762063760925208
                 },
-                "Component_[17233418583781224299]": {
-                    "$type": "EditorTagComponent",
-                    "Id": 17233418583781224299,
-                    "Tags": [
-                        "SourceAppleTree"
-                    ]
-                },
                 "Component_[18002101140342279467]": {
                     "$type": "EditorVisibilityComponent",
                     "Id": 18002101140342279467
@@ -3192,13 +3187,13 @@
                                     "$type": "AzFramework::ScriptPropertyNumber",
                                     "id": 1140549467,
                                     "name": "DetectionRadius",
-                                    "value": 4.0
+                                    "value": 6.0
                                 },
                                 {
                                     "$type": "AzFramework::ScriptPropertyString",
                                     "id": 3805913359,
                                     "name": "FollowTag",
-                                    "value": "FollowTarget"
+                                    "value": "Robot"
                                 },
                                 {
                                     "$type": "AzFramework::ScriptPropertyNumber",
@@ -3209,7 +3204,7 @@
                                     "$type": "AzFramework::ScriptPropertyNumber",
                                     "id": 28318590,
                                     "name": "NumPrefabsToSpawn",
-                                    "value": 9.0
+                                    "value": 1.0
                                 },
                                 {
                                     "$type": "AzFramework::ScriptPropertyNumber",
@@ -4159,7 +4154,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/1",
-                    "value": -100.01538848876953
+                    "value": -100.01538848876952
                 },
                 {
                     "op": "replace",
@@ -4494,7 +4489,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Rotate/2",
-                    "value": -99.90465545654297
+                    "value": -99.90465545654295
                 },
                 {
                     "op": "replace",
@@ -4594,7 +4589,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Rotate/2",
-                    "value": 145.12881469726563
+                    "value": 145.12881469726565
                 },
                 {
                     "op": "replace",
@@ -4709,7 +4704,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/0",
-                    "value": 21.829490661621094
+                    "value": 21.829490661621097
                 },
                 {
                     "op": "replace",
@@ -4859,7 +4854,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Rotate/2",
-                    "value": -109.19132995605469
+                    "value": -109.19132995605467
                 },
                 {
                     "op": "replace",
@@ -6684,17 +6679,17 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[16951455423041694634]/Transform Data/Translate/0",
-                    "value": -75.07823181152344
+                    "value": -59.564151763916016
                 },
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[16951455423041694634]/Transform Data/Translate/1",
-                    "value": 42.87899398803711
+                    "value": 32.441165924072266
                 },
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[16951455423041694634]/Transform Data/Translate/2",
-                    "value": 0.83591628074646
+                    "value": 0.28093504905700684
                 },
                 {
                     "op": "add",
@@ -6715,7 +6710,7 @@
                 {
                     "op": "replace",
                     "path": "/Entities/Entity_[453802196716717]/Components/Component_[12122484710959107959]/Controller/Configuration/EditorEntityId",
-                    "value": 8567848446665491544
+                    "value": 195231005818683466
                 }
             ]
         },
@@ -7270,7 +7265,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/1",
-                    "value": -98.51800537109375
+                    "value": -98.51800537109376
                 },
                 {
                     "op": "replace",
@@ -7320,7 +7315,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/1",
-                    "value": -92.29850769042969
+                    "value": -92.29850769042967
                 },
                 {
                     "op": "replace",
@@ -7625,7 +7620,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Rotate/2",
-                    "value": -124.03113555908203
+                    "value": -124.03113555908205
                 },
                 {
                     "op": "replace",
@@ -7715,7 +7710,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/1",
-                    "value": 1.4167890548706055
+                    "value": 1.4167890548706057
                 },
                 {
                     "op": "replace",
@@ -7910,7 +7905,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/1",
-                    "value": -21.739900588989258
+                    "value": -21.739900588989254
                 },
                 {
                     "op": "replace",
@@ -8065,7 +8060,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Translate/0",
-                    "value": 10.548652648925781
+                    "value": 10.54865264892578
                 },
                 {
                     "op": "replace",
@@ -8160,7 +8155,7 @@
                 {
                     "op": "replace",
                     "path": "/ContainerEntity/Components/Component_[17478803486732630354]/Transform Data/Rotate/2",
-                    "value": -15.471959114074707
+                    "value": -15.471959114074709
                 },
                 {
                     "op": "replace",

+ 1 - 0
Project/Prefabs/Apple.prefab

@@ -167,6 +167,7 @@
                     "Id": 7138985039715548058,
                     "Configuration": {
                         "entityId": "",
+                        "Start Asleep": true,
                         "Gravity Enabled": false
                     }
                 },

Dosya farkı çok büyük olduğundan ihmal edildi
+ 217 - 132
Project/Prefabs/AppleTreeApples.prefab


+ 187 - 1
Project/Prefabs/AppleTreeGroup4.prefab

@@ -58,10 +58,52 @@
                     "$type": "EditorVisibilityComponent",
                     "Id": 10482022883704485451
                 },
+                "Component_[13256697750700106701]": {
+                    "$type": "AZ::Render::EditorMeshComponent",
+                    "Id": 13256697750700106701,
+                    "Controller": {
+                        "Configuration": {
+                            "ModelAsset": {
+                                "assetId": {
+                                    "guid": "{6938817F-A68A-5861-B8D3-8D1FF3B12FAE}",
+                                    "subId": 271211390
+                                },
+                                "assetHint": "assets/apple_tree/appletreeapples.azmodel"
+                            },
+                            "IsRayTracingEnabled": false,
+                            "LodType": 1,
+                            "MinimumScreenCoverage": 0.05000000074505806,
+                            "QualityDecayRate": 0.800000011920929
+                        }
+                    }
+                },
                 "Component_[14409809941983633030]": {
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 14409809941983633030
                 },
+                "Component_[15585962792479463770]": {
+                    "$type": "EditorMaterialComponent",
+                    "Id": 15585962792479463770,
+                    "Controller": {
+                        "Configuration": {
+                            "materials": [
+                                {
+                                    "Key": {
+                                        "materialSlotStableId": 1676432290
+                                    },
+                                    "Value": {
+                                        "MaterialAsset": {
+                                            "assetId": {
+                                                "guid": "{C21C23D1-C6CE-5D5C-8EB3-D5AC825461E6}"
+                                            },
+                                            "assetHint": "assets/apple_tree/apple_applemat.azmaterial"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                },
                 "Component_[15978725969754585124]": {
                     "$type": "{27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0} TransformComponent",
                     "Id": 15978725969754585124,
@@ -132,6 +174,25 @@
                     "$type": "EditorVisibilityComponent",
                     "Id": 10482022883704485451
                 },
+                "Component_[1362925325646035617]": {
+                    "$type": "AZ::Render::EditorMeshComponent",
+                    "Id": 1362925325646035617,
+                    "Controller": {
+                        "Configuration": {
+                            "ModelAsset": {
+                                "assetId": {
+                                    "guid": "{6938817F-A68A-5861-B8D3-8D1FF3B12FAE}",
+                                    "subId": 271211390
+                                },
+                                "assetHint": "assets/apple_tree/appletreeapples.azmodel"
+                            },
+                            "IsRayTracingEnabled": false,
+                            "LodType": 1,
+                            "MinimumScreenCoverage": 0.05000000074505806,
+                            "QualityDecayRate": 0.800000011920929
+                        }
+                    }
+                },
                 "Component_[14409809941983633030]": {
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 14409809941983633030
@@ -145,6 +206,11 @@
                             0.0,
                             3.0,
                             0.0
+                        ],
+                        "Rotate": [
+                            0.0,
+                            0.0,
+                            140.3091278076172
                         ]
                     }
                 },
@@ -199,6 +265,29 @@
                         }
                     }
                 },
+                "Component_[9021025404808262205]": {
+                    "$type": "EditorMaterialComponent",
+                    "Id": 9021025404808262205,
+                    "Controller": {
+                        "Configuration": {
+                            "materials": [
+                                {
+                                    "Key": {
+                                        "materialSlotStableId": 1676432290
+                                    },
+                                    "Value": {
+                                        "MaterialAsset": {
+                                            "assetId": {
+                                                "guid": "{C21C23D1-C6CE-5D5C-8EB3-D5AC825461E6}"
+                                            },
+                                            "assetHint": "assets/apple_tree/apple_applemat.azmaterial"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                },
                 "Component_[913127425512539204]": {
                     "$type": "EditorLockComponent",
                     "Id": 913127425512539204
@@ -226,6 +315,11 @@
                             0.0,
                             6.0,
                             0.0
+                        ],
+                        "Rotate": [
+                            0.0,
+                            0.0,
+                            57.42329788208008
                         ]
                     }
                 },
@@ -244,10 +338,52 @@
                     "$type": "EditorOnlyEntityComponent",
                     "Id": 2474345706400577025
                 },
+                "Component_[2637852875434279734]": {
+                    "$type": "AZ::Render::EditorMeshComponent",
+                    "Id": 2637852875434279734,
+                    "Controller": {
+                        "Configuration": {
+                            "ModelAsset": {
+                                "assetId": {
+                                    "guid": "{6938817F-A68A-5861-B8D3-8D1FF3B12FAE}",
+                                    "subId": 271211390
+                                },
+                                "assetHint": "assets/apple_tree/appletreeapples.azmodel"
+                            },
+                            "IsRayTracingEnabled": false,
+                            "LodType": 1,
+                            "MinimumScreenCoverage": 0.05000000074505806,
+                            "QualityDecayRate": 0.800000011920929
+                        }
+                    }
+                },
                 "Component_[319287915754503450]": {
                     "$type": "EditorPendingCompositionComponent",
                     "Id": 319287915754503450
                 },
+                "Component_[3637817752601745473]": {
+                    "$type": "EditorMaterialComponent",
+                    "Id": 3637817752601745473,
+                    "Controller": {
+                        "Configuration": {
+                            "materials": [
+                                {
+                                    "Key": {
+                                        "materialSlotStableId": 1676432290
+                                    },
+                                    "Value": {
+                                        "MaterialAsset": {
+                                            "assetId": {
+                                                "guid": "{C21C23D1-C6CE-5D5C-8EB3-D5AC825461E6}"
+                                            },
+                                            "assetHint": "assets/apple_tree/apple_applemat.azmaterial"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                },
                 "Component_[5360396437947281098]": {
                     "$type": "EditorEntityIconComponent",
                     "Id": 5360396437947281098
@@ -298,6 +434,25 @@
                     "$type": "EditorDisabledCompositionComponent",
                     "Id": 14409809941983633030
                 },
+                "Component_[14790625882184055621]": {
+                    "$type": "AZ::Render::EditorMeshComponent",
+                    "Id": 14790625882184055621,
+                    "Controller": {
+                        "Configuration": {
+                            "ModelAsset": {
+                                "assetId": {
+                                    "guid": "{6938817F-A68A-5861-B8D3-8D1FF3B12FAE}",
+                                    "subId": 271211390
+                                },
+                                "assetHint": "assets/apple_tree/appletreeapples.azmodel"
+                            },
+                            "IsRayTracingEnabled": false,
+                            "LodType": 1,
+                            "MinimumScreenCoverage": 0.05000000074505806,
+                            "QualityDecayRate": 0.800000011920929
+                        }
+                    }
+                },
                 "Component_[15978725969754585124]": {
                     "$type": "{27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0} TransformComponent",
                     "Id": 15978725969754585124,
@@ -307,6 +462,11 @@
                             0.0,
                             9.0,
                             0.0
+                        ],
+                        "Rotate": [
+                            0.0,
+                            0.0,
+                            -89.93547058105469
                         ]
                     }
                 },
@@ -337,6 +497,29 @@
                     "$type": "EditorEntitySortComponent",
                     "Id": 5627772272655405898
                 },
+                "Component_[6623201874098388994]": {
+                    "$type": "EditorMaterialComponent",
+                    "Id": 6623201874098388994,
+                    "Controller": {
+                        "Configuration": {
+                            "materials": [
+                                {
+                                    "Key": {
+                                        "materialSlotStableId": 1676432290
+                                    },
+                                    "Value": {
+                                        "MaterialAsset": {
+                                            "assetId": {
+                                                "guid": "{C21C23D1-C6CE-5D5C-8EB3-D5AC825461E6}"
+                                            },
+                                            "assetHint": "assets/apple_tree/apple_applemat.azmaterial"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                },
                 "Component_[7827092108012797729]": {
                     "$type": "EditorColliderComponent",
                     "Id": 7827092108012797729,
@@ -554,7 +737,10 @@
                                 "assetHint": "assets/apple_tree/appletreerow4.azmodel"
                             },
                             "SortKey": 111,
-                            "IsRayTracingEnabled": false
+                            "IsRayTracingEnabled": false,
+                            "LodType": 1,
+                            "MinimumScreenCoverage": 0.0010000000474974513,
+                            "QualityDecayRate": 0.800000011920929
                         }
                     }
                 },

+ 123 - 0
Project/Prefabs/ApplesTreeApplesMerged.prefab

@@ -0,0 +1,123 @@
+{
+    "ContainerEntity": {
+        "Id": "ContainerEntity",
+        "Name": "ApplesTreeApplesMerged",
+        "Components": {
+            "Component_[12357740958852226533]": {
+                "$type": "EditorOnlyEntityComponent",
+                "Id": 12357740958852226533
+            },
+            "Component_[13812273328046242140]": {
+                "$type": "{27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0} TransformComponent",
+                "Id": 13812273328046242140,
+                "Parent Entity": ""
+            },
+            "Component_[16484934751235229960]": {
+                "$type": "EditorLockComponent",
+                "Id": 16484934751235229960
+            },
+            "Component_[18331098067477393580]": {
+                "$type": "EditorPrefabComponent",
+                "Id": 18331098067477393580
+            },
+            "Component_[3974787074906848552]": {
+                "$type": "EditorEntityIconComponent",
+                "Id": 3974787074906848552
+            },
+            "Component_[5177679470274993997]": {
+                "$type": "EditorInspectorComponent",
+                "Id": 5177679470274993997
+            },
+            "Component_[7453930348392549452]": {
+                "$type": "EditorPendingCompositionComponent",
+                "Id": 7453930348392549452
+            },
+            "Component_[7531601386347208923]": {
+                "$type": "EditorVisibilityComponent",
+                "Id": 7531601386347208923
+            },
+            "Component_[7607581642361195785]": {
+                "$type": "EditorEntitySortComponent",
+                "Id": 7607581642361195785,
+                "Child Entity Order": [
+                    "Entity_[2053704798327921]"
+                ]
+            },
+            "Component_[9118495500421901515]": {
+                "$type": "EditorDisabledCompositionComponent",
+                "Id": 9118495500421901515
+            }
+        }
+    },
+    "Entities": {
+        "Entity_[2053704798327921]": {
+            "Id": "Entity_[2053704798327921]",
+            "Name": "Apples",
+            "Components": {
+                "Component_[12197425480073056921]": {
+                    "$type": "{27F1E1A1-8D9D-4C3B-BD3A-AFB9762449C0} TransformComponent",
+                    "Id": 12197425480073056921,
+                    "Parent Entity": "ContainerEntity"
+                },
+                "Component_[12375894025103386920]": {
+                    "$type": "EditorVisibilityComponent",
+                    "Id": 12375894025103386920
+                },
+                "Component_[12585428660057228262]": {
+                    "$type": "EditorEntityIconComponent",
+                    "Id": 12585428660057228262
+                },
+                "Component_[1478373033339521626]": {
+                    "$type": "EditorDisabledCompositionComponent",
+                    "Id": 1478373033339521626
+                },
+                "Component_[16306460592995385326]": {
+                    "$type": "EditorPendingCompositionComponent",
+                    "Id": 16306460592995385326
+                },
+                "Component_[17154853628568533178]": {
+                    "$type": "AZ::Render::EditorMeshComponent",
+                    "Id": 17154853628568533178,
+                    "Controller": {
+                        "Configuration": {
+                            "ModelAsset": {
+                                "assetId": {
+                                    "guid": "{6938817F-A68A-5861-B8D3-8D1FF3B12FAE}",
+                                    "subId": 271211390
+                                },
+                                "assetHint": "assets/apple_tree/appletreeapples.azmodel"
+                            },
+                            "IsRayTracingEnabled": false,
+                            "LodOverride": 2
+                        }
+                    }
+                },
+                "Component_[18381910141153642210]": {
+                    "$type": "EditorLockComponent",
+                    "Id": 18381910141153642210
+                },
+                "Component_[3880383294177176955]": {
+                    "$type": "EditorOnlyEntityComponent",
+                    "Id": 3880383294177176955
+                },
+                "Component_[8207269358700608772]": {
+                    "$type": "EditorInspectorComponent",
+                    "Id": 8207269358700608772,
+                    "ComponentOrderEntryArray": [
+                        {
+                            "ComponentId": 12197425480073056921
+                        },
+                        {
+                            "ComponentId": 17154853628568533178,
+                            "SortIndex": 1
+                        }
+                    ]
+                },
+                "Component_[8411187859326940957]": {
+                    "$type": "EditorEntitySortComponent",
+                    "Id": 8411187859326940957
+                }
+            }
+        }
+    }
+}

+ 182 - 152
Project/Scripts/DynamicAppleSpawner.lua

@@ -23,6 +23,8 @@ function DynamicAppleSpawner:OnActivate()
  	self.lastPos = Vector3(0,0,0)
  	self.update = false
  	self.closestAppleTrees = {}
+ 	self.numPrefabsToSpawn = 0 -- don't spawn prefabs until a follow target exists
+ 	self.spawningPrefabs = false
  		
 	self.appleTreeTag = Crc32(self.Properties.DestAppleTreeTag)
 	
@@ -39,197 +41,221 @@ function DynamicAppleSpawner:OnActivate()
 end
 
 function DynamicAppleSpawner:OnSpawn(spawnTicket, entityList)
-
-	
 	-- first entity should be the root
 	table.insert(self.freeAppleGroups, entityList[1])
+	self:SetPhysicsEnabled(entityList[1], false)
+	local entityName  = GameEntityContextRequestBus.Broadcast.GetEntityName(entityList[1])
+	Debug.Log("$5 Spawned " .. tostring(entityName))
+	
+	if self.numPrefabsSpawned >= self.numPrefabsToSpawn then
+		self.spawningPrefabs = false
+	end 
+	
+	local children = TransformBus.Event.GetChildren(entityList[1])
+	for i=1,#children do
+		local childId = children[i]
+		local pos = TransformBus.Event.GetLocalTranslation(childId)
+		Debug.Log("("..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z).."),")
+	end
+	
+	-- mark all follow targets to update in case they are waiting on groups
+	for k,followTarget in pairs(self.followTargets) do
+		followTarget.update = true
+	end
 end
 
 function DynamicAppleSpawner.DestTagHandler:OnEntityTagAdded(entityId)
 	table.insert(self.component.appleTrees, entityId)
 end
 
-function DynamicAppleSpawner.FollowTagHandler:OnEntityTagAdded(entityId)
-	if self.component.followTargets == nil then
-		self.component.followTargets = {}
+function DynamicAppleSpawner:AddFollowTarget(entityId)
+	if self.followTargets == nil then
+		self.followTargets = {}
 	end
-	table.insert(self.component.followTargets, entityId)
+	
+	self.followTargets[entityId] = { 
+		position=Vector3(0,0,0), 
+		update=false, 
+		handler = nil,
+		OnTransformChanged = function(followTarget, localTM, worldTM) 
+			local translation = worldTM:GetTranslation()
+			translation.z = self.Properties.GroundHeight
+			
+			-- only set this target to update if we moved over the threshold
+			if followTarget.update == false and followTarget.position:GetDistanceSq(translation) > self.Properties.TranslationThreshold then
+				followTarget.update = true
+				followTarget.position = translation
+				followTarget.position.z = self.Properties.GroundHeight
+			end
+		 end  
+		 }
+
+	self.followTargets[entityId].handler  = TransformNotificationBus.Connect(self.followTargets[entityId], entityId)
+	
+	self.numPrefabsToSpawn = self.numPrefabsToSpawn + self.Properties.NumPrefabsToSpawn
+
 	local entityName  = GameEntityContextRequestBus.Broadcast.GetEntityName(entityId)
-	Debug.Log("$5 Follow target entity: " .. tostring(entityName))
+	Debug.Log("$5 Follow target added " .. tostring(entityName))
 end
 
-function DynamicAppleSpawner:OnTransformChanged(localTM, worldTM)
-	local translation = worldTM:GetTranslation()
-	translation.z = self.Properties.GroundHeight
-	
-	if self.Properties.DebugColliders then
-		local pos = worldTM:GetTranslation() + worldTM:GetBasisY() *3.0
-		local tm = Transform.CreateTranslation(pos)
-		local overlapRequest = CreateSphereOverlapRequest( 0.5, tm)
-		local physicsSystem = GetPhysicsSystem()
-		local sceneHandle = physicsSystem:GetSceneHandle(DefaultPhysicsSceneName)
-		local scene = physicsSystem:GetScene(sceneHandle)
-		hits = scene:QueryScene(overlapRequest)
-		
-		DebugDrawRequestBus.Broadcast.DrawSphereAtLocation(pos, 0.5, Color(0.0,0.0,1.0), 0.2)
-		
-		if #hits.HitArray > 1 then
-			Debug.Log("NumSphereHits " ..tostring(#hits.HitArray))
+function DynamicAppleSpawner.FollowTagHandler:OnEntityTagAdded(entityId)
+	self.component:AddFollowTarget(entityId)
+end
+
+function DynamicAppleSpawner:SetPhysicsEnabled(entityId, enabled)
+	-- change the physics settings on all descendents
+	local descendants = TransformBus.Event.GetAllDescendants(entityId)
+	if enabled then
+		for i=1,#descendants do
+			local descendantEntityId = descendants[i]
+			SimulatedBodyComponentRequestBus.Event.DisablePhysics(descendantEntityId)
+		end
+	else
+		for i=1,#descendants do
+			local descendantEntityId = descendants[i]
+			SimulatedBodyComponentRequestBus.Event.EnablePhysics(descendantEntityId)
 		end
 	end
-		
-	if self.update == false and self.lastPos:GetDistanceSq(translation) > self.Properties.TranslationThreshold then
-		self.update = true
-		self.lastPos = translation
+end
 
-		self.lastPos.z = self.Properties.GroundHeight
+ function getAppleTreeIndex(appleTrees, entityId)
+	for k,tree in ipairs(appleTrees) do
+		if tree.entityId == entityId then
+			return k
+		end
 	end
+	return -1
+end
+
+function hitEntityId(hitArray, entityId)
+	for i=1,#hitArray  do
+		if hitArray[i].EntityId == entityId then
+			return true
+		end
+	end
+	return false
 end
 
 function DynamicAppleSpawner:OnTick(delaTime, scriptTime)
+	local physicsSystem = GetPhysicsSystem()
+	local sceneHandle = physicsSystem:GetSceneHandle(DefaultPhysicsSceneName)
+	local scene = physicsSystem:GetScene(sceneHandle)
+	local needMorePrefabs = false
+	
+	for k,followTarget in pairs(self.followTargets) do
+		if  followTarget.update then
+			followTarget.update = false
+			local tm = Transform.CreateTranslation(followTarget.position)
+			-- use a small height to avoid intersecting apples if possible
+			-- otherwise need to filter
+			local dimensions = Vector3(self.Properties.DetectionRadius, self.Properties.DetectionRadius, 0.1)
+			local overlapRequest = CreateBoxOverlapRequest(dimensions, tm)			
+			local hits = scene:QueryScene(overlapRequest)
 
-	if self.update then
-		self.update = false
-		local tm = Transform.CreateTranslation(self.lastPos)
-		-- use a small height to avoid intersecting apples if possible
-		-- otherwise need to filter
-		local dimensions = Vector3(self.Properties.DetectionRadius, self.Properties.DetectionRadius, 0.1)
-		local overlapRequest = CreateBoxOverlapRequest(dimensions, tm)
-		
-		local physicsSystem = GetPhysicsSystem()
-		local sceneHandle = physicsSystem:GetSceneHandle(DefaultPhysicsSceneName)
-		local scene = physicsSystem:GetScene(sceneHandle)
-		hits = scene:QueryScene(overlapRequest)
-		local treesToRemove = {}
-		local treesToAdd = {}
-		local closestTrees = {}
-		
-		function getAppleTreeIndex(appleTrees, entityId)
-			for k,tree in ipairs(appleTrees) do
-				if tree.entityId == entityId then
-					return k
-				end
-			end
-			return -1
-		end
-		
-		function hitEntityId(hitArray, entityId)
-			for i=1,#hitArray  do
-				if hitArray[i].EntityId == entityId then
-					return true
-				end
-			end
-			return false
-		end
-		
-		if hits.HitArray :Size()> 0 then
-		
-			if self.Properties.Debug then
-				local aabb = Aabb.CreateCenterHalfExtents(self.lastPos, dimensions * 0.5)
-				DebugDrawRequestBus.Broadcast.DrawAabb(aabb, Color(1.0,1.0,0.0), 1.0)
-				Debug.Log("hit " .. tostring(hits.HitArray:Size()) .. " objects")
-			end
+			local treesToRemove = {}
+			local treesToAdd = {}
+			local closestTrees = {}
 			
-			for k,tree in ipairs(self.closestAppleTrees) do
-				if hitEntityId(hits.HitArray, tree.entityId) == false then
-					if self.Properties.Debug then
-						Debug.Log("Removing apple group entity " ..tostring(tree.applesEntityId))
-					end
-					-- remove this tree and free the apple group
-					if tree.applesEntityId ~= -1 then
-						table.insert(self.freeAppleGroups, tree.applesEntityId)
-						TransformBus.Event.SetWorldTranslation(tree.applesEntityId, Vector3(0,0,-100))
+			if hits.HitArray :Size()> 0 then
+				if self.Properties.Debug then
+					local aabb = Aabb.CreateCenterHalfExtents(followTarget.position, dimensions * 0.5)
+					DebugDrawRequestBus.Broadcast.DrawAabb(aabb, Color(1.0,1.0,0.0), 1.0)
+					Debug.Log("hit " .. tostring(hits.HitArray:Size()) .. " objects")
+				end
+				
+				for k,tree in ipairs(self.closestAppleTrees) do
+					if hitEntityId(hits.HitArray, tree.entityId) == false then
+						if self.Properties.Debug then
+							Debug.Log("Removing apple group entity " ..tostring(tree.applesEntityId))
+						end
+						RenderMeshComponentRequestBus.Event.SetVisibility(tree.entityId, true)
+						
+						-- remove this tree and free the apple group
+						if tree.applesEntityId ~= -1 then
+							table.insert(self.freeAppleGroups, tree.applesEntityId)
+							self:SetPhysicsEnabled(tree.applesEntityId, false)
+							TransformBus.Event.SetWorldTranslation(tree.applesEntityId, Vector3(0,0,1))
+						end
+						table.insert(treesToRemove, tree.entityId)
 					end
-					table.insert(treesToRemove, tree.entityId)
 				end
-			end
-			
-			
-			for i=1,#hits.HitArray do
-				local entityId = hits.HitArray[i].EntityId
-				local index = getAppleTreeIndex(self.closestAppleTrees, entityId)
 				
-				if index ~= -1 then
-					table.insert(closestTrees, self.closestAppleTrees[index])
-				elseif TagComponentRequestBus.Event.HasTag(entityId, self.appleTreeTag) then
-					local applesEntityId = -1
-					if #self.freeAppleGroups > 0 then
-						applesEntityId = self.freeAppleGroups[#self.freeAppleGroups]
-						if applesEntityId == nil or type(applesEntityId) == "number" then
-							Debug.Log("Non EntityId found in freeAppleGroups " ..tostring(applesEntityId) .. " contains " ..#self.freeAppleGroups.." items")
-						else
+				for i=1,#hits.HitArray do
+					local entityId = hits.HitArray[i].EntityId
+					local index = getAppleTreeIndex(self.closestAppleTrees, entityId)
+					
+					if index ~= -1 and self.closestAppleTrees[index].applesEntityId ~= -1 then
+						table.insert(closestTrees, self.closestAppleTrees[index])
+					elseif TagComponentRequestBus.Event.HasTag(entityId, self.appleTreeTag) then
+						local applesEntityId = -1
+						if #self.freeAppleGroups > 0 then
+							applesEntityId = self.freeAppleGroups[#self.freeAppleGroups]
+							if applesEntityId == nil or type(applesEntityId) == "number" then
+								Debug.Log("Non EntityId found in freeAppleGroups " ..tostring(applesEntityId) .. " contains " ..#self.freeAppleGroups.." items")
+								followTarget.update = true
+								needMorePrefabs =  true
+							else
+								if self.Properties.Debug then
+									Debug.Log("Claiming apple group " ..tostring(applesEntityId))
+								end
+								local treeTM = TransformBus.Event.GetWorldTM(entityId)
+								self:SetPhysicsEnabled(applesEntityId, false)
+								TransformBus.Event.SetWorldTM(applesEntityId, treeTM)
+								self:SetPhysicsEnabled(applesEntityId, true)
+								
+								-- hide the render meshes
+								RenderMeshComponentRequestBus.Event.SetVisibility(entityId, false)
+								table.remove(self.freeAppleGroups)
+								table.insert(closestTrees, {entityId=entityId, applesEntityId=applesEntityId})		
+								table.insert(treesToAdd, entityId)
+							end
+						else 
 							if self.Properties.Debug then
-								Debug.Log("Claiming apple group " ..tostring(applesEntityId))
+								Debug.Log("$4 Couldn't find free apple tree group in free pool of size" .. tostring(#self.freeAppleGroups))
 							end
-							local treeTM = TransformBus.Event.GetWorldTM(entityId)
-							TransformBus.Event.SetWorldTM(applesEntityId, treeTM)
-							table.remove(self.freeAppleGroups)
+							needMorePrefabs =  true
+							followTarget.update = true
 						end
-					elseif self.Properties.Debug then
-						Debug.Log("$4 Couldn't find free apple tree group containing" .. tostring(#self.freeAppleGroups) .. " elements")
 					end
-					table.insert(closestTrees, {entityId=entityId, applesEntityId=applesEntityId})
-					table.insert(treesToAdd, entityId)
+				end
+			else
+				for k,tree in ipairs(self.closestAppleTrees) do
+					table.insert(treesToRemove, tree.entityId)
 				end
 			end
-		else
-			for k,tree in ipairs(self.closestAppleTrees) do
-				table.insert(treesToRemove, tree.entityId)
-			end
-		end
-		
-		
-		if self.Properties.Debug then
-			for k,tree in ipairs(closestTrees) do
-				DebugDrawRequestBus.Broadcast.DrawSphereOnEntity(tree.entityId, 0.5, Color(1.0,0.0,0.0), 1.0)
-			end
-		end
-		self.closestAppleTrees = closestTrees
-	end
-	
-	if self.followTargets ~= nil then
-		self.transformHandler = TransformNotificationBus.Connect(self, self.followTargets[1])
-	end
-	
-	-- get apple tree positions
-	if self.appleTreePositions == nil and false then
-		local positions = {}
-		self.appleTreePositions = {}
-		for k,entityId in ipairs(self.appleTrees) do
-			local tm = TransformBus.Event.GetWorldTM(entityId)
-			local position = tm:GetTranslation()
-			table.insert(positions, {entityId=entityId, transform=tm,  position2D=Vector2(position.x, position.y)})
-			
-			self.appleTreePositions[entityId] = {transform=tm, closest={}}
-			--table.insert(self.appleTreePositions, {EntityId=entityId, Transform=tm, Closest={}})
-		end
-		
-		local numClosest = 16
-		-- do a one time distance analysis (slow, but better than runtime check)
-		for k,appleTree in ipairs(appleTreePositions) do
-			local translation = appleTree.tm:GetTranslation()
-			local position2D = Vector2(translation.x, translation.y)
 			
-			table.sort(positions, function (a,b)  return position2D:GetDistanceSq(a.position2D) < position2D:GetDistanceSq(b.position2D) end)
 			
-			for j,otherPosition in ipairs(positions) do
-				table.insert(appleTree.closest, otherPosition.entityId)
+			if self.Properties.Debug then
+				for k,tree in ipairs(closestTrees) do
+					DebugDrawRequestBus.Broadcast.DrawSphereOnEntity(tree.entityId, 0.5, Color(1.0,0.0,0.0), 1.0)
+				end
 			end
+			self.closestAppleTrees = closestTrees
 		end
 	end
+
+	if needMorePrefabs and  self.spawningPrefabs  == false then
+		self.numPrefabsToSpawn = self.numPrefabsToSpawn + 1
+	end
 	
-	
-	-- spawn apples in pool
-	if self.numPrefabsSpawned < self.Properties.NumPrefabsToSpawn  then
-		self.numPrefabsSpawned = self.numPrefabsSpawned + 1
-		Debug.Log("$7 Spawning apple group " .. tostring(self.numPrefabsSpawned ))
-		local tm = TransformBus.Event.GetWorldTM(self.entityId)
-		local translation = tm:GetTranslation()
-		local rotation = tm:GetRotation():GetEulerRadians()
-		self.spawnableMediator:SpawnAndParentAndTransform(self.ticket, self.entityId, translation, rotation, 1.0)
+	-- spawn one apple group per frame for now
+	if self.numPrefabsSpawned < self.numPrefabsToSpawn  then
+		self:SpawnAppleGroup()
 	end
 end
 
+function DynamicAppleSpawner:SpawnAppleGroup()
+	self.numPrefabsSpawned = self.numPrefabsSpawned + 1
+	
+	local tm = TransformBus.Event.GetWorldTM(self.entityId)
+	local translation = tm:GetTranslation()
+	local rotation = tm:GetRotation():GetEulerRadians()
+
+	Debug.Log("$7 Spawning apple group " .. tostring(self.numPrefabsSpawned ))
+	self.spawningPrefabs = true
+	self.spawnableMediator:SpawnAndParentAndTransform(self.ticket, self.entityId, translation, rotation, 1.0)
+end
+
 function DynamicAppleSpawner:OnDeactivate()
 	if self.tickHandler ~= nil then
 		self.tickHandler:Disconnect()
@@ -243,6 +269,10 @@ function DynamicAppleSpawner:OnDeactivate()
 	self.DestTagHandler.handler = nil
 	self.FollowTagHandler.handler:Disconnect()
 	self.FollowTagHandler.handler = nil
+	
+	for k,followTarget in pairs(self.followTargets) do
+		followTarget.handler:Disconnect()
+	end
 end
 
 return DynamicAppleSpawner

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor