protected override void OnUpdate() { //加入房间请求事件 EventSystem <AddPlayerEvent> .AddMissingBuffers(Entities, RoomName_Query_MissingAddPlayer, EntityManager); Entities.With(RoomEntity_Query).ForEach((Entity entity, DynamicBuffer <AddPlayerEvent> buffer) => { //Debug.Log("遍历RoomEntity"); var length = buffer.Length; for (int i = 0; i < length; i++) { var ev = buffer[i]; Debug.Log("开始处理一个事件"); //创建Player //实现查找到PlayerSpawner var playerSpawner = GetSingleton <RoomPlayerSpawnerComponent>(); var player = EntityManager.Instantiate(playerSpawner.RoomPlayerPrefab); EntityManager.SetName(player, "Player_" + ev.PlayerId); Debug.Log("处理一个事件结束"); } //Debug.Log("处理所有事件结束"); }); }
protected override void OnUpdate() { GraphData graphData = GetSingleton <GraphData>(); { EventSystem <AddPointEvent> .AddMissingBuffers(Entities, DestroyPickup_Query_MissingAddPointEvent, EntityManager); Entities.With(DestroyPickup_Query).ForEach((Unity.Entities.Entity DestroyPickup_QueryEntity) => { var DestroyPickup_Query_AddPointEventBuffer = EntityManager.GetBuffer <AddPointEvent>(DestroyPickup_QueryEntity); PostUpdateCommands.DestroyEntity(DestroyPickup_QueryEntity); DestroyPickup_Query_AddPointEventBuffer.Add(new AddPointEvent { }); graphData.Pickups_Amount = (graphData.Pickups_Amount - 1); } ); } { Entities.With(Empty_Query_WithAddPointEvent).ForEach((Unity.Entities.Entity Empty_QueryEntity, DynamicBuffer <AddPointEvent> eventBuffer) => { for (int event_index = 0; event_index < eventBuffer.Length; event_index++) { AddPointEvent ev = eventBuffer[event_index]; { var GameManager_QueryEntities = GameManager_Query.ToEntityArray(Allocator.TempJob); for (int GameManager_QueryIdx = 0; GameManager_QueryIdx < GameManager_QueryEntities.Length; GameManager_QueryIdx++) { var GameManager_QueryEntity = GameManager_QueryEntities[GameManager_QueryIdx]; var GameManager_QueryGameManager = EntityManager.GetSharedComponentData <GameManager>(GameManager_QueryEntity); graphData.Game_Score++; GameManager_QueryGameManager.Score.text = graphData.Game_Score.ToString(); if ((graphData.Pickups_Amount <= 0)) { GameManager_QueryGameManager.WinText.enabled = true; Time.timeScale = 0F; } PostUpdateCommands.SetSharedComponent <GameManager>(GameManager_QueryEntities[GameManager_QueryIdx], GameManager_QueryGameManager); } GameManager_QueryEntities.Dispose(); } } } ); } { Entities.With(GameManager_Query0Enter).ForEach((Unity.Entities.Entity GameManager_QueryEntity, GameManager GameManager_Query0EnterGameManager) => { { var PickupObjects_QueryEntities = PickupObjects_Query.ToEntityArray(Allocator.TempJob); for (int PickupObjects_QueryIdx = 0; PickupObjects_QueryIdx < PickupObjects_QueryEntities.Length; PickupObjects_QueryIdx++) { var PickupObjects_QueryEntity = PickupObjects_QueryEntities[PickupObjects_QueryIdx]; graphData.Pickups_Amount = (graphData.Pickups_Amount + 1); } PickupObjects_QueryEntities.Dispose(); } GameManager_Query0EnterGameManager.Score.text = graphData.Game_Score.ToString(); GameManager_Query0EnterGameManager.WinText.enabled = false; PostUpdateCommands.AddComponent <GameManager_QueryTracking>(GameManager_QueryEntity, default(GameManager_QueryTracking)); } ); } SetSingleton(graphData); }