Exemple #1
0
        private void SpawnAgents(int numAgentsToSpawn, float minSpawnRadius, float maxSpawnRadius)
        {
            var world         = World.DefaultGameObjectInjectionWorld;
            var entityManager = world.EntityManager;
            var settings      = GameObjectConversionSettings.FromWorld(world, null);

            agentPrefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(agentPrefab, settings);

            for (var agentIndex = 0; agentIndex < numAgentsToSpawn; agentIndex++)
            {
                activeAgent = entityManager.Instantiate(agentPrefabEntity);

                var agentPosition = RandomPosition.MakeRandomPosition(minSpawnRadius, maxSpawnRadius);

                entityManager.SetComponentData(activeAgent, new Translation()
                {
                    Value = agentPosition
                });

                entityManager.AddComponentData(activeAgent, new PathLocomotionData()
                {
                    destinationReached = true,
                    maxVelocity        = Random.Range(agentMinVelocity, agentMaxVelocity)
                });;
            }
        }
        private void SetNewDestination(Entity entity, Translation translation)
        {
            var newDestination = RandomPosition.MakeRandomPosition(MinSpawnRadius, MaxSpawnRadius);

            var newDestinationQuery = new QueryPathRequestData()
            {
                agentTypeId         = 0,
                areaCostIndex       = 0,
                areaMask            = walkableAreaMask,
                startPosition       = translation.Value,
                destinationPosition = newDestination,
                mapPositionExtents  = new float3(1f, 1f, 1f)
            };

            if (EntityManager.HasComponent <QueryPathRequestData>(entity))
            {
                EntityManager.SetComponentData(entity, newDestinationQuery);
            }
            else
            {
                EntityManager.AddComponentData(entity, newDestinationQuery);
            }
        }