Exemplo n.º 1
0
        public void UpdateHitBox(IGameEntity gameEntity)
        {
            var position        = gameEntity.Position.Value;
            var rotation        = gameEntity.GetComponent <OrientationComponent>().RotationYaw;
            var hitBoxComponent = GetHitBoxComponent(gameEntity.EntityKey);

            if (hitBoxComponent != null)
            {
                var playerEntity = GetPlayerEntity(gameEntity);

                playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

                PlayerEntityUtility.UpdateTransform(playerEntity,
                                                    gameEntity.GetComponent <NetworkAnimatorComponent>(),
                                                    gameEntity.GetComponent <PredictedAppearanceComponent>(),
                                                    gameEntity.GetComponent <OrientationComponent>());
                //_logger.DebugFormat("server animator {0}", gameEntity.GetComponent<NetworkAnimatorComponent>().ToStringExt());

                PlayerEntityUtility.UpdateTransform(playerEntity,
                                                    playerEntity.networkAnimator,
                                                    playerEntity.predictedAppearance,
                                                    playerEntity.orientation);

                playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;

                if (_logger.IsDebugEnabled)
                {
                    StringBuilder s = new StringBuilder();
                    hitBoxComponent.HitBoxGameObject.transform.Recursively(t => s.Append("[n " + t.name + ", p " + t.position.ToStringExt() + ", r " + t.rotation.ToStringExt() + "]"));
                    _logger.DebugFormat("hitbox pos {0}, rot {1}, transforms {2}, ", position, rotation, s);
                }
            }
        }
Exemplo n.º 2
0
        public override void UpdateHitBox(IGameEntity gameEntity, int renderTime, int cmdSeq)
        {
            var position        = gameEntity.Position.Value;
            var rotation        = gameEntity.GetComponent <OrientationComponent>().ModelView;
            var playerEntity    = GetPlayerEntity(gameEntity);
            var hitBoxComponent = GetHitBoxComponent(playerEntity);

            if (hitBoxComponent != null)
            {
                playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

                PlayerEntityUtility.UpdateTransform(playerEntity, gameEntity.GetComponent <NetworkAnimatorComponent>(),
                                                    gameEntity.GetComponent <PredictedAppearanceComponent>(),
                                                    gameEntity.GetComponent <OrientationComponent>());

                // DebugUtil.AppendShootText(renderTime, "server animator {0}",
                //     gameEntity.GetComponent<NetworkAnimatorComponent>().ToStringExt());

                playerEntity.RootGo().transform.SetPositionAndRotation(position, rotation);
                playerEntity.hitBox.RenderTime = renderTime;

                // if (_logger.IsDebugEnabled)
                // {
                //     StringBuilder s = new StringBuilder();
                //     hitBoxComponent.HitBoxGameObject.transform.Recursively(t => s.Append("[n " + t.name + ", p " + t.position.ToStringExt() + ", r " + t.rotation.ToStringExt() + "]"));
                // //    _logger.DebugFormat("hitbox pos {0}, rot {1}, transforms {2}, ", position, rotation, s);
                // DebugUtil.AppendShootText(cmdSeq,"hitbox pos {0}, rot {1}, transforms {2}, ", position, rotation, s);
                // }
                base.UpdateHitBox(gameEntity, renderTime, cmdSeq);
            }
        }
Exemplo n.º 3
0
        public void UpdateHitBox(IGameEntity gameEntity)
        {
            var position        = gameEntity.Position.Value;
            var rotation        = gameEntity.GetComponent <OrientationComponent>().RotationYaw;
            var hitBoxComponent = GetHitBoxComponent(gameEntity.EntityKey);

            if (hitBoxComponent != null)
            {
                hitBoxComponent.HitBoxGameObject.transform.position = position;
                hitBoxComponent.HitBoxGameObject.transform.rotation = rotation;

                var playerEntity = GetPlayerEntity(gameEntity);

                playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
                var provider = SingletonManager.Get <HitBoxTransformProviderCache>().GetProvider(playerEntity.thirdPersonModel.Value);
                provider.Update(position, rotation);
                HitBoxGameObjectUpdater.Update(hitBoxComponent.HitBoxGameObject.transform, provider);
                playerEntity.thirdPersonAnimator.UnityAnimator.cullingMode = AnimatorCullingMode.CullUpdateTransforms;

                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("client animator {0}", playerEntity.networkAnimator.ToStringExt());
                    StringBuilder s = new StringBuilder();
                    hitBoxComponent.HitBoxGameObject.transform.Recursively(t => s.Append("[n " + t.name + ", p " + t.position.ToStringExt() + ", r " + t.rotation.ToStringExt() + "]"));
                    _logger.DebugFormat("hitbox pos {0}, rot {1}, transforms {2}, ", position, rotation, s);
                }
            }
        }
Exemplo n.º 4
0
        public void DoInsert(IGameEntity localEntity)
        {
            var entityKey  = localEntity.EntityKey;
            var sendFilter = _filter;

            if (_preEntitys.Contains(entityKey))
            {
                return;
            }
            if (sendFilter.IsIncludeEntity(localEntity))
            {
                if (sendFilter.IsEntitySelf(localEntity))
                {
                    _snapshot.AddEntity(localEntity.GetSelfEntityCopy(_seq));
                }
                else
                {
                    if (localEntity.HasPositionFilter)
                    {
                        var positionFilter = localEntity.GetComponent <PositionFilterComponent>();
                        var position       = localEntity.Position;
                        if (!positionFilter.Filter(position.Value, _filter.Position))
                        {
                            _snapshot.AddEntity(localEntity.GetNonSelfEntityCopy(_seq));
                        }
                    }
                    else
                    {
                        _snapshot.AddEntity(localEntity.GetNonSelfEntityCopy(_seq));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public override void ApplyPatchTo(IGameEntity entity, INetworkObjectSerializerManager serializerManager)
        {
            var                      componentTypeId     = Component.GetComponentId();
            INetworkObject           targetComponent     = entity.GetComponent(componentTypeId) as INetworkObject;
            INetworkObjectSerializer componentSerializer = serializerManager.GetSerializer(componentTypeId);

            componentSerializer.Merge(Component as INetworkObject, targetComponent, _bitMask);
        }
Exemplo n.º 6
0
        public void UpdateHitBoxes(VehicleEntity vehicle, IGameEntity gameEntity)
        {
            var config = GetShipConfig(vehicle);

            var hitBoxComp = gameEntity.GetComponent <ShipHitBoxComponent>();

            config.hitBoxRootImposter.transform.SetPositionAndRotation(hitBoxComp.BodyPosition, hitBoxComp.BodyRotation);
            var wheelCount = config.rudderHitBoxImposters.Length;

            for (int i = 0; i < wheelCount; ++i)
            {
                config.rudderHitBoxImposters[i].SetPositionAndRotation(hitBoxComp.RudderPositionList[i], hitBoxComp.RudderRotationList[i]);
            }
        }
Exemplo n.º 7
0
        public void OnLeftEntityMissing(IGameEntity rightEntity)
        {
            var         entityKey   = rightEntity.EntityKey;
            IGameEntity localEntity = _handler.CreateAndGetLocalEntity(entityKey);

            _logger.DebugFormat("create entity {0}", entityKey);
            foreach (var rightComponent in rightEntity.ComponentList)
            {
                if (!IsExcludeComponent(rightComponent) && localEntity.GetComponent(rightComponent.GetComponentId()) == null)
                {
                    _logger.DebugFormat("{2}add component {0}:{1}", entityKey, rightComponent.GetType(), rightComponent);
                    var leftComponent = (ILatestComponent)localEntity.AddComponent(rightComponent.GetComponentId(), rightComponent);
                }
            }
        }
        private void DoInsert(IGameEntity gameEntity)
        {
            var  entityKey = gameEntity.EntityKey;
            bool hasAdd    = false;

            if (preEntityKeys.Contains(entityKey))
            {
                hasAdd = true;
            }
            else if (sendSnapshotFilter.IsIncludeEntity(gameEntity))
            {
                if (sendSnapshotFilter.IsEntitySelf(gameEntity))
                {//获取自己的备份
                    snapshot.AddEntity(gameEntity.GetSelfEntityCopy(seq));
                    hasAdd = true;
                }
                else if (!isAccountStage)
                {
                    if (isPrepareStage && gameEntity.EntityType != (int)EEntityType.Player)
                    {
                        return;
                    }
                    //获取别人的备份
                    if (gameEntity.HasPositionFilter)
                    {
                        var positionFilter = gameEntity.GetComponent <PositionFilterComponent>();
                        var position       = gameEntity.Position;
                        if (!positionFilter.Filter(position.Value, sendSnapshotFilter.Position))
                        {
                            snapshot.AddEntity(gameEntity.GetNonSelfEntityCopy(seq));
                            hasAdd = true;
                        }
                    }
                    else
                    {
                        snapshot.AddEntity(gameEntity.GetNonSelfEntityCopy(seq));
                        hasAdd = true;
                    }
                }
            }

            if (hasAdd && onInsert != null)
            {
                onInsert(gameEntity, forPre);
            }
        }
Exemplo n.º 9
0
        public void UpdateHitBoxes(VehicleEntity vehicle, IGameEntity gameEntity)
        {
            var config = GetCarConfig(vehicle);

            var hitBoxComp = gameEntity.GetComponent <CarHitBoxComponent>();

            config.hitBoxRootImposter.transform.SetPositionAndRotation(hitBoxComp.BodyPosition, hitBoxComp.BodyRotation);

            var flexibleCount = config.flexibleHitBoxImposters.Length;

            for (int i = 0; i < flexibleCount; ++i)
            {
                var flexibleImposter = config.flexibleHitBoxImposters[i];
                if (flexibleImposter != null)
                {
                    flexibleImposter.SetPositionAndRotation(hitBoxComp.FlexiblePositionList[i], hitBoxComp.FlexibleRotationList[i]);
                }
            }

            var wheelCount = config.wheelHitBoxImposters.Length;
            var controller = GetController(vehicle);

            for (int i = 0; i < wheelCount; ++i)
            {
                var  outerGo  = config.wheelHitBoxImposters[i].OuterHitBox.gameObject;
                int  index    = config.wheelHitBoxIndices[i];
                bool isBroken = controller.GetWheelBroken(index);
                if (isBroken && outerGo.activeSelf)
                {
                    outerGo.SetActive(false);
                }
                else if (!outerGo.activeSelf && !isBroken)
                {
                    outerGo.SetActive(true);
                }

                var hitBoxRoot = config.wheelHitBoxImposters[i].GetHitBoxRoot();
                hitBoxRoot.SetPositionAndRotation(hitBoxComp.WheelPositionList[i], hitBoxComp.WheelRotationList[i]);
            }
        }
        public void SyncToEntity(IPlayerUserCmdGetter getter, UpdateLatestPacakge package)
        {
            PlayerEntity playerEntity = getter.OwnerEntity as PlayerEntity;
            IGameEntity  gameEntity   = playerEntity.entityAdapter.SelfAdapter;
            int          count        = package.UpdateComponents.Count;

            for (var i = 0; i < count; i++)
            {
                IUpdateComponent component = package.UpdateComponents[i];
                var id     = component.GetComponentId();
                var target = gameEntity.GetComponent(id);
                if (target == null)
                {
                    target = gameEntity.AddComponent(id);
                }

                var p = GetProfile(component.GetComponentId());
                try
                {
                    p.BeginProfileOnlyEnableProfile();
                    ((INetworkObject)target).CopyFrom(component);
                    if (id == (int)EComponentIds.SendUserCmd)
                    {
                        UserCmd cmd = UserCmd.Allocate();
                        CopyForm(cmd, component as SendUserCmdComponent);
                        playerEntity.userCmd.AddLatest(cmd);
                        cmd.Seq        = package.Head.LastUserCmdSeq;
                        cmd.SnapshotId = package.Head.LastSnapshotId;
                        cmd.ReleaseReference();
                    }
                }
                finally
                {
                    p.EndProfileOnlyEnableProfile();
                }
            }
        }
Exemplo n.º 11
0
        public void SyncToEntity(IUserCmdOwner owner, UpdateLatestPacakge package)
        {
            PlayerEntity playerEntity = owner.OwnerEntity as PlayerEntity;
            IGameEntity  gameEntity   = playerEntity.entityAdapter.SelfAdapter;

            foreach (var component in package.UpdateComponents)
            {
                var target = gameEntity.GetComponent(component.GetComponentId());
                if (target == null)
                {
                    target = gameEntity.AddComponent(component.GetComponentId());
                }
                ((INetworkObject)target).CopyFrom(component);
                if (component is SendUserCmdComponent)
                {
                    UserCmd cmd = UserCmd.Allocate();
                    CopyForm(cmd, component as SendUserCmdComponent);
                    playerEntity.userCmd.AddLatest(cmd);
                    cmd.Seq        = package.Head.UserCmdSeq;
                    cmd.SnapshotId = package.Head.LastSnapshotId;
                    cmd.ReleaseReference();
                }
            }
        }
Exemplo n.º 12
0
 public virtual void UpdateHitBox(IGameEntity gameEntity, int renderTime, int cmdSeq)
 {
     DebugUtil.AppendShootText(cmdSeq, "[animator] {0}", gameEntity.GetComponent <NetworkAnimatorComponent>().ToStringExt());
     DebugUtil.AppendShootText(cmdSeq, "[collider]\n{0}", GetCollidersDebugDatas(gameEntity.EntityKey));
 }
Exemplo n.º 13
0
 public void AttachTo(IGameEntity entity)
 {
     _spatial = (SpatialComponent)entity.GetComponent("Spatial");
     OnAttach();
 }