예제 #1
0
        private void Update()
        {
            if (entityManager == null)
            {
                return;
            }

            var sharedAgentData = new SharedAgentData
            {
                SimulationTime       = simulationTime,
                VelocityRange        = velocityRange,
                Prey                 = transform.position,
                AlignmentFactor      = alignmentFactor,
                SeparationFactor     = separationFactor,
                CohesionFactor       = cohesionFactor,
                PreyFactor           = preyFactor,
                MaxCohesionDistance  = maxCohesionDistance,
                MaxAlignmentDistance = maxAlignmentDistance,
                MaxNeighborCount     = maxNeighborCount,
            };

            foreach (var sample in entityManager.GetAllEntities())
            {
                entityManager.SetSharedComponentData(sample, sharedAgentData);
            }
        }
예제 #2
0
 public AgentJob(int count)
 {
     timeDelta = Time.deltaTime;
     cluster   = new Cluster(count);
     positions = new ComponentDataArray <Position>();
     rotations = new ComponentDataArray <Rotation>();
     agents    = new ComponentDataArray <AgentData>();
     agentData = default(SharedAgentData);
 }
예제 #3
0
        private void SetEntityData(Entity entity)
        {
            var direction = new Vector3(
                Random.Range(-1f, 1f),
                Random.Range(-1f, 1f),
                Random.Range(-1f, 1f)).normalized;
            var velocity = Random.Range(velocityRange.x, velocityRange.y) * direction;
            var position = new Vector3(
                Random.Range(-1f, 1f),
                Random.Range(-1f, 1f),
                Random.Range(-1f, 1f));

            entityManager.SetComponentData(entity, new Position()
            {
                Value = position
            });
            entityManager.SetComponentData(entity, new Rotation()
            {
                Value = Quaternion.identity
            });
            entityManager.SetComponentData(entity, new Scale()
            {
                Value = meshScale * Vector3.one
            });
            entityManager.SetComponentData(entity, new AgentData()
            {
                Velocity = velocity,
            });
            entityManager.SetSharedComponentData(entity, new MeshInstanceRenderer
            {
                mesh     = mesh,
                material = material,
            });

            var sharedAgentData = new SharedAgentData
            {
                SimulationTime       = simulationTime,
                VelocityRange        = velocityRange,
                Prey                 = transform.position,
                AlignmentFactor      = alignmentFactor,
                SeparationFactor     = separationFactor,
                CohesionFactor       = cohesionFactor,
                PreyFactor           = preyFactor,
                MaxCohesionDistance  = maxCohesionDistance,
                MaxAlignmentDistance = maxAlignmentDistance,
                MaxNeighborCount     = maxNeighborCount,
            };

            entityManager.SetSharedComponentData(entity, sharedAgentData);
        }
예제 #4
0
        public void Update(AgentCollection agentCollection, SharedAgentData sharedAgentData)
        {
            cluster.SetAgentPositions(agentCollection.Positions);

            positions = agentCollection.Positions;
            rotations = agentCollection.Potations;
            agents    = agentCollection.Agents;
            agentData = sharedAgentData;

            switch (agentData.SimulationTime)
            {
            case SimulationTime.TimeDelta:
                timeDelta = Time.deltaTime;
                break;

            case SimulationTime.Constant10ms:
                timeDelta = 0.01f;
                break;

            default: throw new ArgumentOutOfRangeException();
            }
        }