Esempio n. 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var inputDepsA = new AutoExplosionByRaycastJob
            {
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }.Schedule(this, inputDeps);

            var inputDepsB = new AutoExplosionByAngleJob
            {
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }.Schedule(this, inputDeps);

            var inputDepsC = new AutoExplosionByTouchJob
            {
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }.Schedule(this, inputDeps);

            var ds = JobHandle.CombineDependencies(inputDepsA, inputDepsB, inputDepsC);

            endBarrier.AddJobHandleForProducer(ds);

            return(ds);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (zeroToActorDeath)
            {
                if (modifyHandleType == ModifyHandleType.Sample)
                {
                    inputDeps = new SampleAttribute3ModifysAndZeroToActorDeathJob
                    {
                        OnDestroyMessage = typeof(OnDestroyMessage),
                        endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
                    }
                    .Schedule(this, inputDeps);
                }
                else if (modifyHandleType == ModifyHandleType.Default)
                {
                    inputDeps = new Attribute3ModifysAndZeroToActorDeathJob
                    {
                        OnDestroyMessage = typeof(OnDestroyMessage),
                        endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
                    }
                    .Schedule(this, inputDeps);
                }

                endBarrier.AddJobHandleForProducer(inputDeps);
            }
            else
            {
                if (modifyHandleType == ModifyHandleType.Sample)
                {
                    inputDeps = new SampleAttribute3ModifysJob {
                    }.Schedule(this, inputDeps);
                }
                else if (modifyHandleType == ModifyHandleType.Default)
                {
                    inputDeps = new Attribute3ModifysJob {
                    }.Schedule(this, inputDeps);
                }
            }

            if (regainEnable)
            {
                inputDeps = new Attribute3RegainJob
                {
                    fixedDeltaTime = Time.fixedDeltaTime,
                }
                .Schedule(this, inputDeps);
            }

            return(inputDeps);
        }
        public void Disconnected()
        {
            if (connectEntity == Entity.Null)
            {
                Debug.LogError("connectEntity == Entity.Null");
                return;
            }
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            endCommandBuffer.AddComponent(connectEntity, new NetworkDisconnectedMessage {
                error = (short)DisconnectedErrors.Disconnect
            });
            connectEntity = Entity.Null;
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //
            inputDeps = new AddJob
            {
                NetworkHeartbeat = typeof(NetworkHeartbeat),
                commandBuffer    = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);



            //
            using (var commandBuffer = new SampleCommandBuffer <NetworkDisconnectedMessage>(Allocator.TempJob))
            {
                inputDeps = new Heartbeat2CJob
                {
                    commandBuffer    = commandBuffer.ToConcurrent(),
                    fixedDeltaTime   = Time.fixedDeltaTime,
                    disconnectedTime = disconnectedTime,
                }
                .Schedule(this, inputDeps);

                inputDeps.Complete();
                commandBuffer.Playback(EntityManager);
            }


            //endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 5
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var actorOwnerFromEntity       = GetComponentDataFromEntity <ActorOwner>(true);
            var playerActorArrayFromEntity = GetComponentDataFromEntity <PlayerActorArray>();
            var slotFromEntity             = GetComponentDataFromEntity <Slot>(true);

            inputDeps = new WeaponUninstallJob
            {
                actorOwnerFromEntity       = actorOwnerFromEntity,
                playerActorArrayFromEntity = playerActorArrayFromEntity,
                slotFromEntity             = slotFromEntity,
            }
            .ScheduleSingle(this, inputDeps);

            inputDeps = new WeaponInstallJob
            {
                actorOwnerFromEntity       = actorOwnerFromEntity,
                playerActorArrayFromEntity = playerActorArrayFromEntity,
                slotFromEntity             = slotFromEntity,
            }
            .ScheduleSingle(this, inputDeps);


            inputDeps = new ShipDestroyMessageJob
            {
                Player_OnShipDestroy_NextFrameMessage = typeof(Player_OnShipDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 6
0
        protected override void OnUpdate()
        {
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsSphereCastAll, OnPhysicsCallMessage>()
            .WithNone <OnDestroyMessage>()
            .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsSphereCastAll sphereCastAll) =>
            {
                int numFound = Physics.SphereCastNonAlloc(sphereCastAll.ray, sphereCastAll.radius, results, sphereCastAll.distance, sphereCastAll.layerMask);
                if (numFound > 0)
                {
                    var rs = results
                             .Take(numFound)
                             .Where(x => x.rigidbody != null);

                    if (sphereCastAll.distinctDisable == false)
                    {
                        rs = rs.Distinct(raycastHitCompareByRigidbody);
                    }


                    foreach (var hitInfo in rs)
                    {
                        if (EntityBehaviour.getEntity(hitInfo.rigidbody, out var entity, World))
                        {
                            raycastResults.Add(new PhysicsRaycastResults {
                                entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance
                            });
                        }
                    }
                }
            });
        }
Esempio n. 7
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //
            var inputDepsA = new PowerLevelJob
            {
            }
            .Schedule(this, inputDeps);


            //
            var inputDepsB = new DisableInputTimeJob
            {
                fixedDeltaTime        = Time.fixedDeltaTime,
                ShipDisableInputState = typeof(ShipLostInputState),
                endCommandBuffer      = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);


            //
            inputDepsA = new ActorAttribute3ServerSystem <_Power> .SampleAttribute3ModifysJob
            {
            }
            .Schedule(this, inputDepsA);

            //
            inputDepsA = new DisableInputJob
            {
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDepsA);

            //
            inputDepsA = new PowerRegainJob
            {
                fixedDeltaTime = Time.fixedDeltaTime,
            }
            .Schedule(this, inputDepsA);

            //
            inputDeps = JobHandle.CombineDependencies(inputDepsA, inputDepsB);
            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 8
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new FireInputJob
            {
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
        protected override void OnUpdate()
        {
            var driver           = networkStreamSystem.driver;
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAllReadOnly <NetworkDisconnectedMessage, NetworkConnection>()
            .ForEach((ref NetworkDisconnectedMessage disconnected, ref NetworkConnection connection) =>
            {
                onClosed();
            });
        }
Esempio n. 10
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new AMJob
            {
                hpModifyFromEntity = GetBufferFromEntity <ActorAttribute3Modifys <_HP> >(),

                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .ScheduleSingle(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 11
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new WeaponUninstallJob
            {
                SlotUsingState = typeof(SlotUsingState),

                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 12
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new LifetimeJob
            {
                fixedDeltaTime   = Time.fixedDeltaTime,
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 13
0
        protected override void OnUpdate()
        {
            if (enterGameQuery.IsEmptyIgnoreFilter == false)
            {
                using (var enterGamePlayerEntitys = enterGameQuery.ToEntityArray(Allocator.TempJob))
                {
                    for (var i = 0; i < enterGamePlayerEntitys.Length; ++i)
                    {
                        if (EntityManager.HasComponent <PlayerActorType>(enterGamePlayerEntitys[i]) == false)
                        {
                            EntityManager.AddComponentData(enterGamePlayerEntitys[i], new PlayerActorType {
                                value = actorTypeBegin
                            });
                            //endBarrier.curCommandBuffer.AddComponent(enterGamePlayerEntitys[i], new PlayerActorType { value = 1 });
                        }
                    }
                }
            }


            //
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAllReadOnly <NetworkConnection, PlayerActorSelectNetMessage>()   //可以没有Player时修改PlayerActorType
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity playerEntity, ref PlayerActorSelectNetMessage playerActorSelectNetMessage) =>
            {
                if (playerActorSelectNetMessage.value > actorTypeEnd || playerActorSelectNetMessage.value < actorTypeBegin)
                {
                    endCommandBuffer.AddComponent(playerEntity, new NetworkDisconnectedMessage {
                        error = (short)DisconnectedErrorsInSystem.PlayerActorSelect
                    });
                    return;
                }

                var playerActorType = new PlayerActorType {
                    value = playerActorSelectNetMessage.value
                };

                if (EntityManager.HasComponent <PlayerActorType>(playerEntity))
                {
                    EntityManager.SetComponentData(playerEntity, playerActorType);
                }
                else
                {
                    EntityManager.AddComponentData(playerEntity, playerActorType);
                    //endBarrier.curCommandBuffer.AddComponent(playerEntity, playerActorType);
                }
            });
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new WeaponByShipDestroyJob
            {
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);



            endBarrier.AddJobHandleForProducer(inputDeps);
            return inputDeps;
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new AMJob
            {
                random = new Unity.Mathematics.Random((uint)UnityEngine.Random.Range(1, int.MaxValue)),
                translationFromEntity = GetComponentDataFromEntity <Translation>(true),
                hpModifyFromEntity    = GetBufferFromEntity <ActorAttribute3Modifys <_HP> >(),

                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .ScheduleSingle(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new PhysicsTriggerFxJob
            {
                withoutBullet         = withoutBullet,
                bulletFromEntity      = GetComponentDataFromEntity <Bullet>(true),
                translationFromEntity = GetComponentDataFromEntity <Translation>(true),

                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 17
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new LaserControlJobA
            {
                weaponTranslationFromEntity = GetComponentDataFromEntity <Translation>(true),
                weaponRotationFromEntity    = GetComponentDataFromEntity <Rotation>(true),

                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            inputDeps = new LaserControlJobB
            {
            }
            .Schedule(this, inputDeps);

            return(inputDeps);
        }
Esempio n. 18
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //
            if (enterGameQuery.IsEmptyIgnoreFilter == false)
            {
                //var endCommandBuffer = endBarrier.CreateCommandBuffer();
                using (var enterGamePlayerEntitys = enterGameQuery.ToEntityArray(Allocator.TempJob))
                {
                    for (var i = 0; i < enterGamePlayerEntitys.Length; ++i)
                    {
                        EntityManager.AddComponentData(enterGamePlayerEntitys[i], new PlayerGameReady {
                            countdown = gameReadyTime
                        });
                        //endCommandBuffer.AddComponent(enterGamePlayerEntitys[i], new PlayerGameReady { countdown = gameReadyTime });
                    }
                }
            }


            //
            inputDeps = new FindGameReadyPlayerJob
            {
                gameReadyTime = gameReadyTime,
            }
            .Schedule(this, inputDeps);


            //
            inputDeps = new GameReadyCountdownJob
            {
                gameReadyTime  = gameReadyTime,
                fixedDeltaTime = Time.fixedDeltaTime,

                PlayerGameStartNetMessage = typeof(PlayerGameStartNetMessage),

                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
        protected override void OnUpdate()
        {
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsRaycast, OnPhysicsCallMessage>()
            .WithNone <OnDestroyMessage>()
            .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsRaycast raycast) =>
            {
                if (Physics.Raycast(raycast.ray, out RaycastHit hitInfo, raycast.distance, raycast.layerMask))
                {
                    if (EntityBehaviour.getEntity(hitInfo.rigidbody, out var entity, World))
                    {
                        raycastResults.Add(new PhysicsRaycastResults {
                            entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance
                        });
                    }
                }
            });
        }
Esempio n. 20
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            using (var commandBuffer = new EntityCommandBuffer(Allocator.TempJob))
            {
                inputDeps = new MessageTriggerJob
                {
                    fixedDeltaTime   = Time.fixedDeltaTime,
                    CallTrigger      = typeof(CallTrigger),
                    commandBuffer    = commandBuffer.ToConcurrent(),
                    endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
                }
                .Schedule(this, inputDeps);

                inputDeps.Complete();
                commandBuffer.Playback(EntityManager);
            }

            //endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 21
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new ShieldControlJobA
            {
                weaponInstalledStateFromEntity = GetComponentDataFromEntity <WeaponInstalledState>(true),
                weaponRotationFromEntity       = GetComponentDataFromEntity <Rotation>(true),

                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            inputDeps = new ShieldControlJobB
            {
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            //enter Game
            if (enterGameQuery.IsEmptyIgnoreFilter == false)
            {
                EntityManager.AddComponent <PlayerActorArray>(enterGameQuery);
            }


            //quit Game
            inputDeps = new QuitGameJob
            {
                //PlayerActorArray = typeof(PlayerActorArray),
                OnDestroyMessage = typeof(OnDestroyMessage),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
        protected override void OnUpdate()
        {
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsLinecast, OnPhysicsCallMessage>()
            .WithNone <OnDestroyMessage>()
            .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsLinecast linecast) =>
            {
                //Debug.DrawLine(linecast.start, linecast.end, Color.white, 0.25f);

                if (Physics.Linecast(linecast.start, linecast.end, out var hitInfo, linecast.layerMask))
                {
                    if (EntityBehaviour.getEntity(hitInfo.rigidbody, out Entity entity, World))
                    {
                        raycastResults.Add(new PhysicsRaycastResults {
                            entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance
                        });
                    }
                }
            });
        }
        protected override void OnUpdate()
        {
            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            Entities
            .WithAllReadOnly <NetworkConnection, PlayerCreateNetMessages>()
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity entity, DynamicBuffer <PlayerCreateNetMessages> playerCreateNetMessages) =>
            {
                foreach (var playerCreateNetMessage in playerCreateNetMessages)
                {
                    if (playerClientSystem.playerEntityFromPlayerId.TryGetValue(playerCreateNetMessage.id, out Entity playerEntity) == false)
                    {
                        Debug.LogError($"{World.Name} => playerEntityFromPlayerId.TryGetValue(playerCreateNetMessage.id={playerCreateNetMessage.id}, out Entity playerEntity) == false");
                        endCommandBuffer.AddComponent <NetworkDisconnectedMessage>(entity);
                        break;
                    }

                    PostUpdateCommands.AddComponent <PlayerActorArray>(playerEntity);
                }
            });
        }
        protected override void OnUpdate()
        {
            var endCommandBuffer = endBarrier.CreateCommandBuffer();


            //Result
            Entities
            .WithAllReadOnly <NetworkConnection, PlayerEnterGameResultNetMessage>()
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity entity, ref PlayerEnterGameResultNetMessage playerEnterGameResultNetMessage) =>
            {
                if (playerEnterGameResultNetMessage.success)
                {
                    //PostUpdateCommands.AddComponent(entity, new PlayerInGameState { });

                    PostUpdateCommands.AddComponent(entity, new PlayerEnterGameMessage {
                    });
                    endCommandBuffer.RemoveComponent <PlayerEnterGameMessage>(entity);
                }

                playerEnterGameResult(playerEnterGameResultNetMessage);
            });
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var inputDepsA = new WeaponUninstallJobA
            {
                //uninstallInputTimeScale = uninstallInputTimeScale,
                //endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            var inputDepsB = new WeaponUninstallJobB
            {
                WeaponInstalledState = typeof(WeaponInstalledState),
                OnDestroyMessage     = typeof(OnDestroyMessage),
                endCommandBuffer     = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            var inputDepsAB = JobHandle.CombineDependencies(inputDepsA, inputDepsB);

            endBarrier.AddJobHandleForProducer(inputDepsAB);

            var inputDepsC = new WeaponUninstallJobC
            {
                uninstallForce = uninstallForce,
            }
            .Schedule(this, inputDeps);

            var inputDepsD = new WeaponUninstallJobD
            {
                uninstallTorque = uninstallTorque,
            }
            .Schedule(this, inputDeps);


            inputDeps = JobHandle.CombineDependencies(inputDepsAB, inputDepsC, inputDepsD);
            return(inputDeps);
        }
Esempio n. 27
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            using (var commandBuffer = new EntityCommandBuffer(Allocator.TempJob))
            {
                inputDeps = new ShipDestroyMessageJob
                {
                    OnDestroyMessage = typeof(OnDestroyMessage),

                    Weapon_OnShipDestroyMessage = typeof(Weapon_OnShipDestroyMessage),
                    Player_OnShipDestroyMessage = typeof(Player_OnShipDestroyMessage),

                    commandBuffer    = commandBuffer.ToConcurrent(),
                    endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),

                    playerFromEntity = GetComponentDataFromEntity <Player>(true),
                }
                .Schedule(this, inputDeps);

                inputDeps.Complete();
                commandBuffer.Playback(EntityManager);
            }

            return(inputDeps);
        }
Esempio n. 28
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            inputDeps = new UninstallJob
            {
                OnWeaponUninstallMessage = typeof(OnWeaponUninstallMessage),
                ctrlCommandBuffer        = controlBarrier.CreateCommandBuffer().ToConcurrent(),
                endCommandBuffer         = endBarrier.CreateCommandBuffer().ToConcurrent(),

                Weapon_OnShipDestroyMessageFromEntity = GetComponentDataFromEntity <Weapon_OnShipDestroyMessage>(true),
            }
            .Schedule(this, inputDeps);

            inputDeps.Complete();//ChangedFilter 需要inputDeps.Complete()

            var translationFromEntity = GetComponentDataFromEntity <Translation>(true);

            inputDeps = new FirePrepareJob
            {
                powerFromEntity       = GetComponentDataFromEntity <ActorAttribute3 <_Power> >(true),
                translationFromEntity = translationFromEntity,
            }
            .Schedule(this, inputDeps);


            inputDeps = new FireDirectionJob
            {
                slotRotationFromEntity  = GetComponentDataFromEntity <Rotation>(true),
                weaponControlFromEntity = GetComponentDataFromEntity <WeaponControl>(true),
            }
            .Schedule(this, inputDeps);

            /*inputDeps = new FollowShipJob
             * {
             *  translationFromEntity = translationFromEntity
             * }
             * .Schedule(this, inputDeps);*/


            //
            inputDeps = new FireJobA
            {
                fixedDeltaTime = Time.fixedDeltaTime,

                OnWeaponControlFirePrepareMessage = typeof(OnWeaponControlFirePrepareMessage),
                ctrlCommandBuffer = controlBarrier.CreateCommandBuffer().ToConcurrent(),
                endCommandBuffer  = endBarrier.CreateCommandBuffer().ToConcurrent(),

#if false
                OnWeaponControlFireOnMessage          = typeof(OnWeaponControlFireOnMessage),
                weaponControlInFireStateCommandBuffer = weaponControlInFireStateCommandBuffer.ToConcurrent(),
#endif
            }
            .Schedule(this, inputDeps);

            /*inputDeps = new FireJobB
             * {
             *  fixedDeltaTime = Time.fixedDeltaTime,
             *
             *  OnWeaponControlFirePrepareMessage = typeof(OnWeaponControlFirePrepareMessage),
             *  ctrlCommandBuffer = controlBarrier.CreateCommandBuffer().ToConcurrent(),
             *  endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
             * }
             * .Schedule(this, inputDeps);*/

#if false
            inputDeps = new WeaponFireStateJob
            {
                fixedDeltaTime = Time.fixedDeltaTime,

                WeaponControlInFireState      = typeof(WeaponControlInFireState),
                OnWeaponControlFireOffMessage = typeof(OnWeaponControlFireOffMessage),
                commandBuffer    = controlBarrier.CreateCommandBuffer().ToConcurrent(),
                endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(),
            }
            .Schedule(this, inputDeps);

            weaponControlInFireStateCommandBuffer.Playback(EntityManager);
#endif


            controlBarrier.AddJobHandleForProducer(inputDeps);
            //endBarrier.AddJobHandleForProducer(inputDeps);
            return(inputDeps);
        }
Esempio n. 29
0
        /*public Entity CreateInClient(short actorType, int actorId, in ActorOwner actorOwner)
         * {
         *  return actorSpawners.CreateInClient(actorType, actorId, actorOwner);
         * }*/


        protected override void OnUpdate()
        {
            Entities
            .WithAllReadOnly <NetworkConnection, NetworkConnectedMessage>()
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity entity) =>
            {
                EntityManager.AddComponent <ActorCreateSerializeNetMessage>(entity);
            });



            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            //
            //接收服务器上发来的所有ActorCreateNetMessage
            var q = Entities
                    .WithAllReadOnly <NetworkConnection, ActorCreateSerializeNetMessage>()
                    .WithNone <NetworkDisconnectedMessage>();

            using (var actorCreateNetMessageList = q.AllBufferElementToList <ActorCreateSerializeNetMessage>(Allocator.Temp))
                using (var entitys = q.ToEntityQuery().ToEntityArray(Allocator.TempJob))
                {
                    if (entitys.Length > 1)
                    {
                        Debug.LogError("entitys.Length > 1");
                    }

                    for (int i = 0; i < actorCreateNetMessageList.Length; ++i)
                    {
                        var actorType = actorCreateNetMessageList[i].actorType;
                        var playerId  = actorCreateNetMessageList[i].ownerPlayerId;
                        var actorId   = actorCreateNetMessageList[i].actorId;
                        var dates     = actorCreateNetMessageList[i].datas;

                        Entity playerEntity;

                        if (playerId <= 0)//服务器自己创建的actor
                        {
                            playerEntity = Entity.Null;
                        }
                        else
                        {
                            if (playerClientSystem.playerEntityFromPlayerId.TryGetValue(playerId, out playerEntity) == false)
                            {
                                Debug.LogError($"{World.Name} => playerEntityFromPlayerId.TryGetValue(playerId={playerId}, out Entity playerEntity) == false");
                                endCommandBuffer.AddComponent <NetworkDisconnectedMessage>(entitys[0]);
                                break;
                            }
                        }

                        //Debug.LogWarning($"{World.Name} =>  playerId={playerId}  actorType={actorType}  actorId={actorId}  playerEntity={playerEntity}");

                        var actorEntity = actorSpawnerMap.CreateInClient(actorType, actorId, new ActorOwner {
                            playerEntity = playerEntity, playerId = playerId
                        }, dates);


                        //ActorSpawner.needActorId => false 时 id是-1
                        if (actorId <= 0)
                        {
                            continue;
                        }


                        //
                        if (_actorEntityFromActorId.TryAdd(actorId, actorEntity) == false)
                        {
                            //actorId是连续的 客户端的删除也有可能延迟 所以这里有可能会出现旧的actorEntity还没删除 所以这里可以直接覆盖掉
                            //还有一种情况是服务器的entity只有一阵的生命周期 而客户端的entity的生命周期找过一阵  服务器的id已经回收并且重新分配给新的entity  解决方案是把这类型的ActorSpawner.needActorId => false
                            Debug.LogWarning($"{World.Name} => actorEntityFromPlayerId.TryAdd(index, entity) == false  playerId={playerId}  actorType={actorType}  actorId={actorId}");


                            _actorEntityFromActorId[actorId] = actorEntity;
                        }
                    }
                }
        }
Esempio n. 30
0
        protected override void OnUpdate()
        {
            Entities
            .WithAllReadOnly <NetworkConnection, NetworkConnectedMessage>()
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity entity) =>
            {
                EntityManager.AddComponent <PlayerTeamNetMessages>(entity);
            });



            var endCommandBuffer = endBarrier.CreateCommandBuffer();

            //接收服务器上发来的所有新名字或修改的名字
            Entities
            .WithAllReadOnly <NetworkConnection, PlayerTeamNetMessages>()
            .WithNone <NetworkDisconnectedMessage>()
            .ForEach((Entity entity, DynamicBuffer <PlayerTeamNetMessages> newPlayerTeamNetMessages) =>
            {
                for (int i = 0; i < newPlayerTeamNetMessages.Length; ++i)
                {
                    var playerId   = newPlayerTeamNetMessages[i].playerId;
                    var playerTeam = newPlayerTeamNetMessages[i].value;

                    if (playerClientSystem.playerEntityFromPlayerId.TryGetValue(playerId, out Entity playerEntity) == false)
                    {
                        Debug.LogError($"{World.Name} => playerEntityFromPlayerId.TryGetValue(playerId={playerId}, out Entity playerEntity) == false");
                        endCommandBuffer.AddComponent <NetworkDisconnectedMessage>(entity);
                        continue;
                    }


                    if (EntityManager.HasComponent <PlayerTeam>(playerEntity))
                    {
                        PostUpdateCommands.SetComponent(playerEntity, new PlayerTeam {
                            value = playerTeam
                        });
                    }
                    else
                    {
                        PostUpdateCommands.AddComponent(playerEntity, new PlayerTeam {
                            value = playerTeam
                        });
                    }
                }
            });


            //接收服务器上发来的所有delete PlayerId
            //PlayerEntity已经删除了 这里就不用删除PlayerTeam



            //离开游戏场景后的处理 并没有断开
            //客户端断开后的处理

            /*Entities
             *  .WithAll<NetworkStreamConnection>()
             *  .WithAny<NetworkStreamDisconnectedMessage, PlayerQuitGameMessage>()
             *  .ForEach((Entity _) =>
             *  {
             *  });*/
        }