Esempio n. 1
0
        protected override void OnUpdate()
        {
            Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref FireRpc req,
                                                                          ref ReceiveRpcCommandRequestComponent reqSrc) =>
            {
                PostUpdateCommands.DestroyEntity(reqEnt);
                m_Queue.Enqueue(req);
            });

            uint renderTick = m_NetworkTime.interpolateTargetTick;

            while (m_Queue.Count > 0)
            {
                var msg = m_Queue.Peek();
                if (msg.Tick > renderTick)
                {
                    break;
                }

                m_Queue.Dequeue();

                if (!m_GhostUpdateSystemGroup.GhostMap.TryGetValue(msg.OwnerGId, out GhostEntity item))
                {
                    return;
                }

                int localGhostId = EntityManager
                                   .GetComponentData <GhostComponent>(GetSingleton <CommandTargetComponent>().Target).Id;

                // 开枪人收到确认消息
                if (localGhostId == msg.OwnerGId)
                {
                    return;
                }

                Transform        mcc        = EntityManager.GetComponentObject <Transform>(item.Entity);
                LinkedPlayerView linkedView = mcc.GetComponent <GameObjectLinked>().Target
                                              .GetComponent <LinkedPlayerView>();
                linkedView.GenProjectile(World, msg.Pos, msg.Dir, false);

                Debug.Log($"收到开枪.");
            }

            NetDebug.Set($"开枪消息队列", m_Queue.Count);

            // 处理命中消息
            Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref ProjectileHit hit,
                                                                          ref ReceiveRpcCommandRequestComponent reqSrc) =>
            {
                PostUpdateCommands.DestroyEntity(reqEnt);
                if (!m_GhostUpdateSystemGroup.GhostMap.TryGetValue(hit.GId, out GhostEntity item))
                {
                    return;
                }

                var gcv = EntityManager.GetComponentObject <GameObjectLinked>(item.Entity).Target;
                gcv.GetComponent <PlayerHUD>()?.SetValue(hit.Hp / 100f);
                NetDebug.Set($"命中GhostId", $"Id={hit.GId} Hp={hit.Hp}");
            });
        }
Esempio n. 2
0
        protected override void OnUpdate()
        {
            // 玩家对象 插值
            Entities.With(_ownerPredicationQuery)
            .ForEach((Entity ent,
                      ref NetworkCharacterComponent n) =>
            {
                if (!_storeSystem.TryGetValue(ent, out var trans))
                {
                    return;
                }

                trans.GetComponent <KinematicCharacterMotor>().SetPositionAndRotation(n.Position, n.Rotation);
                LinkedPlayerView linkedPlayerView = trans.GetComponent <GameObjectLinked>().Target
                                                    .GetComponent <LinkedPlayerView>();

                var rot = Quaternion.Euler(n.AngleH, n.AngleV, 0);

                linkedPlayerView.Camera.transform.rotation = rot;
                linkedPlayerView.Camera.transform.position =
                    trans.transform.position + rot * linkedPlayerView.targetCamOffset;

                linkedPlayerView.Anim.SetFloat("Horizontal", n.AimH);
                linkedPlayerView.Anim.SetFloat("Vertical", n.AimV);
            });
        }
Esempio n. 3
0
        protected override void OnUpdate()
        {
            Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref GrenadeRpc msg,
                                                                          ref ReceiveRpcCommandRequestComponent reqSrc) =>
            {
                PostUpdateCommands.DestroyEntity(reqEnt);
                m_Queue.Enqueue(msg);
            });

            uint renderTick = m_NetworkTime.interpolateTargetTick;

            while (m_Queue.Count > 0)
            {
                var msg = m_Queue.Peek();
                if (msg.Tick > renderTick)
                {
                    break;
                }

                m_Queue.Dequeue();

                if (!m_GhostUpdateSystemGroup.GhostMap.TryGetValue(msg.OwnerGId, out GhostEntity item))
                {
                    return;
                }

                int localGhostId = EntityManager
                                   .GetComponentData <GhostComponent>(GetSingleton <CommandTargetComponent>().Target).Id;

                // 开枪人收到确认消息
                if (localGhostId == msg.OwnerGId)
                {
                    return;
                }

                Transform        mcc        = EntityManager.GetComponentObject <Transform>(item.Entity);
                LinkedPlayerView linkedView = mcc.GetComponent <GameObjectLinked>().Target
                                              .GetComponent <LinkedPlayerView>();
                linkedView.GenGrenade(World, msg.Pos, msg.Dir, false);
            }
        }