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) } } }
void GoHome() { Debug.Log("CharacterControl -> GoHome"); StopAllActions(); status = Status.GoingHome; GoHomeAction action = new GoHomeAction(this); currentActions.Add(action); action.Start(); }