Пример #1
0
        public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player)
        {
            Vector3    remotePosition  = vehicleModel.Position;
            Vector3    remoteVelocity  = vehicleModel.Velocity;
            Quaternion remoteRotation  = vehicleModel.Rotation;
            Vector3    angularVelocity = vehicleModel.AngularVelocity;

            Vehicle vehicle = null;
            SubRoot subRoot = null;

            Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id);

            if (opGameObject.HasValue)
            {
                GameObject gameObject = opGameObject.Value;

                vehicle = gameObject.GetComponent <Vehicle>();
                subRoot = gameObject.GetComponent <SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot != null)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                    subRoot.GetComponent <LiveMixin>().health = vehicleModel.Health;
                }
                else if (vehicle != null)
                {
                    SeaMoth seamoth = vehicle as SeaMoth;
                    Exosuit exosuit = vehicle as Exosuit;

                    if (seamoth)
                    {
                        mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>();
                    }
                    else if (exosuit)
                    {
                        mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>();
                        if (vehicleModel.GetType() == typeof(ExosuitMovementData))
                        {
                            ExosuitMovementData exoSuitMovement = (ExosuitMovementData)vehicleModel;
                            mvc.SetArmPositions(exoSuitMovement.LeftAimTarget, exoSuitMovement.RightAimTarget);
                        }
                        else
                        {
                            Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData");
                        }
                    }

                    vehicle.GetComponent <LiveMixin>().health = vehicleModel.Health;
                }

                if (mvc != null)
                {
                    mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity);
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }

            if (player.HasValue)
            {
                RemotePlayer playerInstance = player.Value;
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }
Пример #2
0
        public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player)
        {
            Vehicle vehicle = null;
            SubRoot subRoot = null;

            Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id);

            if (opGameObject.HasValue)
            {
                GameObject gameObject = opGameObject.Value;

                Rocket rocket = gameObject.GetComponent <Rocket>();
                vehicle = gameObject.GetComponent <Vehicle>();
                subRoot = gameObject.GetComponent <SubRoot>();

                MultiplayerVehicleControl mvc = null;

                if (subRoot)
                {
                    mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>();
                }
                else if (vehicle)
                {
                    if (vehicle.docked)
                    {
                        Log.Debug($"For vehicle {vehicleModel.Id} position update while docked, will not execute");
                        return;
                    }
                    SeaMoth seamoth = vehicle as SeaMoth;
                    Exosuit exosuit = vehicle as Exosuit;

                    if (seamoth)
                    {
                        mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>();
                    }
                    else if (exosuit)
                    {
                        mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>();

                        if (vehicleModel is ExosuitMovementData)
                        {
                            ExosuitMovementData exoSuitMovement = (ExosuitMovementData)vehicleModel;
                            mvc.SetArmPositions(exoSuitMovement.LeftAimTarget.ToUnity(), exoSuitMovement.RightAimTarget.ToUnity());
                        }
                        else
                        {
                            Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData");
                        }
                    }
                }
                else if (rocket)
                {
                    opGameObject.Value.transform.position = vehicleModel.Position.ToUnity();
                    opGameObject.Value.transform.rotation = vehicleModel.Rotation.ToUnity();
                }

                if (mvc)
                {
                    mvc.SetPositionVelocityRotation(
                        vehicleModel.Position.ToUnity(),
                        vehicleModel.Velocity.ToUnity(),
                        vehicleModel.Rotation.ToUnity(),
                        vehicleModel.AngularVelocity.ToUnity()
                        );
                    mvc.SetThrottle(vehicleModel.AppliedThrottle);
                    mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch);
                }
            }

            if (player.HasValue)
            {
                RemotePlayer playerInstance = player.Value;
                playerInstance.SetVehicle(vehicle);
                playerInstance.SetSubRoot(subRoot);
                playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>());
                playerInstance.AnimationController.UpdatePlayerAnimations = false;
            }
        }