Beispiel #1
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <HasReynoldsSeekTargetPos> reynoldsArray = chunk.GetNativeArray(reynoldsType);
            NativeArray <GoHomeAction>             goHomeArray   = chunk.GetNativeArray(goHomeType);
            NativeArray <Translation> transArray    = chunk.GetNativeArray(translationType);
            BufferAccessor <Action>   actionBuffers = chunk.GetBufferAccessor <Action>(actionBufferType);



            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                DynamicBuffer <Action>   actions = actionBuffers[i];
                HasReynoldsSeekTargetPos seek    = reynoldsArray[i];
                GoHomeAction             data    = goHomeArray[i];
                Translation trans = transArray[i];

                //Debug.Log("Something? " + copy.Value);


                if (actions.Length > 0)                                             //if there are actions
                {
                    if (actions[0].id == data.id)                                   //if the current action is the same as the action in the first position
                    {
                        if (math.distance(trans.Value, seek.targetPos) < tolerance) // if the entity is within tolerance of the home point
                        //Remove the entity from the simulation (the crowd agent is going home)
                        {
                            Debug.Log("Going home!");
                            // loop through all of the actions in the agent's list, and destroy all of the data holder entities

                            /*for(int j = 0; j < actions.Length; j++){
                             *  entityCommandBuffer.DestroyEntity(chunkIndex,actions[j].dataHolder);
                             * }
                             * entityCommandBuffer.DestroyEntity(chunkIndex, entity); // remove the crowd agent*/
                            entityCommandBuffer.AddComponent <CrowdToDelete>(chunkIndex, entity, new CrowdToDelete {
                            });
                        }
                    }
                    else  // if there are actions but this action is not the right one
                    {
                        Debug.Log("Gotta change from going home!");
                        //If there were data to store, this would be the point to do it
                        entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity); // remove the seek target pos from the crowd agent
                        entityCommandBuffer.RemoveComponent <GoHomeAction>(chunkIndex, entity);             // remove the going home action from the crowd agent
                        entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                        });                                                                                 //signify that the action should be changed
                    }
                }
                else  // if there are no actions in the action queue
                {
                    Debug.Log("Nothin left!");
                    entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity); // remove the seek target pos from the crowd agent
                    entityCommandBuffer.RemoveComponent <GoHomeAction>(chunkIndex, entity);             // remove the going home action from the crowd agent
                    entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                    });                                                                                 //signify that the action should be changed (will remove action)
                }
            }
        }
Beispiel #2
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Translation>              transArray      = chunk.GetNativeArray(translationType);
            NativeArray <ReynoldsMovementValues>   movementArray   = chunk.GetNativeArray(reynoldsMovementValuesType);
            NativeArray <HasReynoldsSeekTargetPos> seekTargetArray = chunk.GetNativeArray(seekType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Translation              trans     = transArray[i];
                ReynoldsMovementValues   movement  = movementArray[i];
                HasReynoldsSeekTargetPos targetPos = seekTargetArray[i];

                float3 move = targetPos.targetPos - trans.Value;

                movementArray[i] = new ReynoldsMovementValues {
                    flockMovement = movement.flockMovement,
                    seekMovement  = move,
                    fleeMovement  = movement.fleeMovement
                };
            }
        }
Beispiel #3
0
        public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
        {
            NativeArray <Entity> entityArray = chunk.GetNativeArray(entityType);
            NativeArray <HasReynoldsSeekTargetPos> reynoldsArray = chunk.GetNativeArray(reynoldsType);
            NativeArray <FollowWayPointsAction>    followWPArray = chunk.GetNativeArray(followWPType);
            NativeArray <Translation> transArray    = chunk.GetNativeArray(translationType);
            BufferAccessor <Action>   actionBuffers = chunk.GetBufferAccessor <Action>(actionBufferType);
            BufferAccessor <WayPoint> wpBuffers     = chunk.GetBufferAccessor <WayPoint>(wayPointBufferType);

            for (int i = 0; i < chunk.Count; i++)
            {
                Entity entity = entityArray[i];
                DynamicBuffer <Action>   actions   = actionBuffers[i];
                DynamicBuffer <WayPoint> wayPoints = wpBuffers[i];
                HasReynoldsSeekTargetPos seek      = reynoldsArray[i];
                FollowWayPointsAction    data      = followWPArray[i];
                Translation trans = transArray[i];


                if (actions.Length > 0)                                                                //if there are actions
                {
                    if (actions[0].id == data.id)                                                      //if the current action is the same as the action in the first position
                    {
                        if (math.distance(trans.Value, wayPoints[data.curPointNum].value) < tolerance) // if the entity is within tolerance of the waypoint
                        {
                            if (data.curPointNum < wayPoints.Length - 1)                               // if the entity has at least one more waypoint to follow
                            {
                                data.curPointNum++;                                                    // the index increases by one
                                seek.targetPos = wayPoints[data.curPointNum].value;                    // move to the next point
                            }
                            else                                                                       // if there are no more waypoints
                                   //entityCommandBuffer.DestroyEntity(actions[0].dataHolder);//demolish the storage entity
                            {
                                Debug.Log("Got to last point");
                                entityCommandBuffer.AddComponent <RemoveAction>(chunkIndex, entity, new RemoveAction { // add a component that tells the system to remove the action from the queue
                                    id = data.id
                                });
                                entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity);
                                entityCommandBuffer.RemoveComponent <FollowWayPointsAction>(chunkIndex, entity);
                                //remove the current follow waypoints action
                            }
                        }
                    }
                    else  // if there are actions but this action is not the right one
                    {
                        Debug.Log("Gotta change!");
                        int j = 0;
                        while (j < actions.Length && actions[j].id != data.id) // find the location of the action in the actions queue
                        {
                            j++;
                        }
                        if (j < actions.Length)                                                                        // if the action was found in the queue
                        {
                            entityCommandBuffer.AddComponent <StoreWayPoints>(chunkIndex, entity, new StoreWayPoints { // store the data
                                id          = data.id,
                                dataHolder  = actions[j].dataHolder,
                                curPointNum = data.curPointNum
                            });
                        }
                        entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                        });                                                                                      //signify that the action should be changed
                    }
                }
                else  // if there are no actions in the action queue
                {
                    Debug.Log("Nothin left!");
                    entityCommandBuffer.RemoveComponent <HasReynoldsSeekTargetPos>(chunkIndex, entity);
                    entityCommandBuffer.RemoveComponent <FollowWayPointsAction>(chunkIndex, entity);
                    entityCommandBuffer.AddComponent <ChangeAction>(chunkIndex, entity, new ChangeAction {
                    });                                                                                      //signify that the action should be changed (will remove action)
                }
            }
        }