protected override void OnUpdate()
        {
            for (var i = 0; i != m_Group.Length; i++)
            {
                var ev = m_Group.Events[i];

                if (IsConnectedOrHosting ? !ServerEntityMgr.HasEntity(ev.ServerTarget) : !EntityManager.Exists(ev.ServerTarget))
                {
                    continue;
                }

                var entity = IsConnectedOrHosting ? ServerEntityMgr.GetEntity(ev.ServerTarget) : ev.ServerTarget;

                if (!EntityManager.HasComponent <StStamina>(entity) || !EntityManager.HasComponent <DefStJumpStaminaUsageData>(entity))
                {
                    continue;
                }

                var staminaComponent = EntityManager.GetComponentData <StStamina>(entity);
                var usageComponent   = EntityManager.GetComponentData <DefStJumpStaminaUsageData>(entity);

                var removal = usageComponent.BaseRemove;
                if (EntityManager.HasComponent <StVelocity>(entity))
                {
                    var flatSpeed = EntityManager.GetComponentData <StVelocity>(entity).Value.ToGrid(1).magnitude;
                    removal += flatSpeed * usageComponent.RemoveBySpeedFactor01;
                }

                staminaComponent.Value -= removal;

                Debug.Log("Updated stamina usage (from jump) -= " + removal);

                PostUpdateCommands.SetComponent(entity, staminaComponent);
            }
        }
コード例 #2
0
        public Entity CreateProjectile(EntityCommandBuffer ecb)
        {
            Debug.Assert(CanExecuteServerActions, "CanExecuteServerActions");

            if (!CanExecuteServerActions)
            {
                return(Entity.Null);
            }

            var entity = EntityManager.CreateEntity(m_EntityArchetype);

            ServerEntityMgr.ConvertAsNetworkable(ecb, entity, entity);

            Debug.Log("Create a projectile!");

            return(entity);
        }
コード例 #3
0
        public void SendProjectile(Entity entity)
        {
            var ownerComponent    = EntityManager.GetComponentData <ProjectileOwner>(entity);
            var velocityComponent = EntityManager.GetComponentData <StVelocity>(entity);
            var positionComponent = EntityManager.GetComponentData <Position>(entity);

            ServerEntityMgr.BroadcastEntity(entity.GetComponentData <NetworkEntity>(), EntityType.PureEntity, true);

            var data = CreateMessage(MsgStartProjectile);

            data.Put(entity);
            data.Put(ownerComponent.Target);
            data.Put(positionComponent.Value);
            data.Put(velocityComponent.Value);

            ServerSendToAll(data);

            Debug.Log("Sending a projectile! " + entity);
        }
コード例 #4
0
        public void Callback(EventReceiveData.Arguments args)
        {
            if (!args.Reader.Type.IsPattern())
            {
                return;
            }

            var conMsgMgr = args.PeerInstance.GetPatternManager();

            var msg = conMsgMgr.GetPattern(args.Reader);
            var ecb = new EntityCommandBuffer(Allocator.Temp);

            if (msg == MsgTestCreateProj)
            {
                var position = args.Reader.Data.GetVec3();
                var aim      = args.Reader.Data.GetVec3();
                var proj     = CreateProjectile(ecb);

                EntityManager.SetComponentData(proj, new Position {
                    Value = position
                });
                EntityManager.SetComponentData(proj, new StVelocity(aim * 42f));

                Debug.Log($"Creating a new projectile. P: {position}; A: {aim}");

                SendProjectile(proj);
            }
            else if (msg == MsgStartProjectile)
            {
                var serverEntity = args.Reader.GetEntity();
                var owner        = default(Entity);
                var position     = args.Reader.Data.GetVec3();
                var velocity     = args.Reader.Data.GetVec3();

                var clientEntity = EntityManager.CreateEntity(m_EntityArchetype);

                ServerEntityMgr.ConvertAsNetworkable(ecb, clientEntity, serverEntity);

                EntityManager.SetOrAddComponentData(clientEntity, new ProjectileTag());
                EntityManager.SetOrAddComponentData(clientEntity, new ProjectileOwner(owner));
                EntityManager.SetOrAddComponentData(clientEntity, new Position {
                    Value = position
                });
                EntityManager.SetOrAddComponentData(clientEntity, new StVelocity(velocity));

                Debug.Log("We got a new projectile from server!");
            }
            else if (msg == MsgEndProjectile)
            {
                var serverEntity = args.Reader.GetEntity();
                var clientEntity = GetEntity(serverEntity);

                Debug.Log($"Destroying projectile... c: {clientEntity}, s: {serverEntity}");

                var projGO = ClientProjectileRocketExplosion[0];
                projGO.transform.position = clientEntity.GetComponentData <Position>().Value;
                projGO.GetComponentInChildren <ParticleSystem>().Play(true);

                ServerEntityMgr.DestroyEntity(serverEntity);
                ecb.DestroyEntity(clientEntity);
            }

            ecb.Playback(EntityManager);
            ecb.Dispose();
        }