public unsafe void Execute(Entity entity, int index, DynamicBuffer <NetworkInBuffer> inBuffer, ref NetworkConnection connection) { //if (!connection.value.IsCreated) return; if (inBuffer.Length > 0) { inBuffer.Clear(); endCommandBuffer.AddComponent(entity, new NetworkDisconnectedMessage { error = (short)DisconnectedErrors.Receive_InBufferLength }); return; } DataStreamReader reader; NetworkEvent.Type networkEvent; while ((networkEvent = driver.PopEventForConnection(connection.value, out reader)) != NetworkEvent.Type.Empty) { //Debug.LogWarning($"networkEvent={networkEvent}"); switch (networkEvent) { case NetworkEvent.Type.Connect: commandBuffer.AddComponent(index, entity, NetworkConnectedMessage); break; case NetworkEvent.Type.Disconnect: //Debug.Log($"Disconnect entity={entity}"); // Flag the connection as lost, it will be deleted in a separate system, giving user code one frame to detect and respond to lost connection endCommandBuffer.AddComponent(entity, new NetworkDisconnectedMessage { error = (short)DisconnectedErrors.Disconnect }); return; case NetworkEvent.Type.Data: var oldLen = inBuffer.Length; inBuffer.ResizeUninitialized(oldLen + reader.Length); UnsafeUtility.MemCpy(((byte *)inBuffer.GetUnsafePtr()) + oldLen, reader.GetUnsafeReadOnlyPtr(), reader.Length); break; default: #if ENABLE_UNITY_COLLECTIONS_CHECKS throw new InvalidOperationException("Received unknown network event " + networkEvent); #else break; #endif } } }
public void Execute(Entity weaponEntity, int index, [ReadOnly] ref WeaponInput weaponInput, [ReadOnly] ref WeaponControlInfo weaponControlInfo, [ReadOnly] ref WeaponInstalledState weaponInstalledState, ref WeaponControl weaponControl, ref WeaponAttribute weaponAttribute) { var fireEvent = weaponControl.OnFire(fixedDeltaTime, weaponControlInfo); if (fireEvent == WeaponControl.FireEvent.Prepare) { ctrlCommandBuffer.AddComponent(index, weaponEntity, OnWeaponControlFirePrepareMessage); endCommandBuffer.RemoveComponent(index, weaponEntity, OnWeaponControlFirePrepareMessage); } else if (fireEvent == WeaponControl.FireEvent.Fire) { if (weaponAttribute.itemCount == 0) { return; } if (weaponAttribute.itemCount > 0) { --weaponAttribute.itemCount; } ctrlCommandBuffer.AddBuffer <ActorAttribute3Modifys <_Power> >(index, weaponInstalledState.shipEntity).Add( new ActorAttribute3Modifys <_Power> { //player = weaponInstalledState.shipActorOwner.playerEntity,//自己消耗自己的power 就不需要知道是谁消耗了 value = -weaponControlInfo.GetConsumePower(weaponInstalledState.slot.main), attribute3ModifyType = Attribute3SubModifyType.ValueOffset }); var fireActorType = weaponControlInfo.GetFireActorType(weaponInstalledState.slot.main); var attributeScale = weaponControlInfo.GetAttributeScale(weaponInstalledState.slot.main); if (fireActorType != ActorTypes.None) { var e = ctrlCommandBuffer.CreateEntity(index); ctrlCommandBuffer.AddComponent(index, e, new FireCreateData { actorOwner = weaponInstalledState.shipActorOwner, shipEntity = weaponInstalledState.shipEntity, weaponEntity = weaponEntity, fireActorType = fireActorType, firePosition = weaponInput.firePosition, attributeOffsetScale = attributeScale, }); } #if false else { weaponControlInFireStateCommandBuffer.AddComponent(weaponEntity, new WeaponControlInFireState { duration = weaponControlInfo.fireDuration }); commandBuffer.AddComponent(index, weaponEntity, OnWeaponControlFireOnMessage); endCommandBuffer.RemoveComponent(index, weaponEntity, OnWeaponControlFireOnMessage); } #endif } }
public void Execute(Entity entity, int index, DynamicBuffer <NetworkReliableOutBuffer> outBuffer) { commandBuffer.AddComponent(entity, new NetworkId { value = entity.Index }); var s = new NetworkIdSerialize { value = entity.Index }; s._DoSerialize(outBuffer); }
public void Execute(Entity entity, int index, [ReadOnly] DynamicBuffer <NetworkInBuffer> inBuffer, ref NetworkHeartbeat heartbeat) { if (inBuffer.Length > 0) { heartbeat.time = 0; } else { heartbeat.time += fixedDeltaTime; if (heartbeat.time > disconnectedTime) { commandBuffer.AddComponent(entity, new NetworkDisconnectedMessage { error = (short)DisconnectedErrorsInSystem.Heartbeat }); } } }