// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "GlobeAwareDefaultPawn.h" #include "Interfaces/IHttpRequest.h" #include "Rover.generated.h" class UInputAction; struct FInputActionValue; class UInputMappingContext; class ADefaultPawnController; class UCesiumFlyToComponent; class ARoverController; class UCameraComponent; class USpringArmComponent; enum class ESelecteItemMode :uint8 { ESM_Single, ESM_Multiple, ESM_Default }; enum class ETSAction :uint8 { ETS_Default, ETS_RotationOrZoom, ETS_UPDown }; /** * */ UCLASS() class BXSSP_API ARover : public AGlobeAwareDefaultPawn { GENERATED_BODY() public: ARover(); virtual void Tick(float DeltaTime)override; UFUNCTION(BlueprintCallable) void UpdateOrignLongitudeLatitude(float Time = 0.01f); UFUNCTION(BlueprintCallable) void FlyTo(const FVector& LongitudeLatitude, double YawAtDestination, double PitchAtDestination); /*UFUNCTION(BlueprintCallable) void FlyTo(const FVector& LongitudeLatitude, double YawAtDestination, double PitchAtDestination);*/ UFUNCTION(BlueprintCallable) void AssistMouseRollDistance(float Value, const FVector2D& ZoomScreenPosition = FVector2D(-1, -1)); // 辅助通过滚动轴缩进距离 void AssistMouseRollDistance(float Value, std::optional _TS_ZoomHitResult, std::optional ZoomScreenPosition = std::nullopt); FVector GetCurrentLongitudeLatitude(); bool IsPressMouseLeft() { return bPressMouseLeftKey; } //检测是否更新原点经纬度 UFUNCTION(BlueprintCallable) void CheckUpdateOrignLongitudeLatitude(); float GetHeight()const; FORCEINLINE ARoverController* GetPlayerController()const { return PlayerController; } FORCEINLINE TSoftObjectPtr GetGeoreference() { return Georeference; } FORCEINLINE bool IsPressRightKey()const { return bPressMouseRightKey; } UFUNCTION(BlueprintCallable) FORCEINLINE void SetAssistMouseLeftMoveActor(TSoftObjectPtr Object) { AssistMouseLeftMoveActor = Object; } FORCEINLINE void SetSelectedModeStatus(ESelecteItemMode Mode) { LastSelecteItemMode = SelecteItemMode; SelecteItemMode = Mode; } FORCEINLINE ESelecteItemMode GetSelectedModeStatus()const { return SelecteItemMode; } FORCEINLINE ESelecteItemMode GetLastSelectedModeStatus()const { return LastSelecteItemMode; } //绕中心点旋转视角 UFUNCTION(BlueprintCallable) void AroundPointRotation(float TheValue, EAxis::Type AxisType = EAxis::Y, FVector _RotationPoint = FVector(-1)); FORCEINLINE bool IsTempStopAutoRotate()const { return bTempStopAutoRotate; } // 更新屏幕中心点位置 UFUNCTION(BlueprintCallable) void UpdatascreenCenterPointLocation(); //通过高度调整速度 void AdjustSpeedByHeight(); // fly开始时调用 UFUNCTION(BlueprintImplementableEvent) void OnFlyStart(const FVector& LongitudeLatitudeHeightDestination, double YawAtDestination, double PitchAtDestination); UFUNCTION(BlueprintCallable) void ModifyMaxRollCoefficient(float Coefficient); UCameraComponent* GetFollowCamera()const { return Camera; } void _MoveRight(const FInputActionValue& TheValue); UFUNCTION(BlueprintCallable) void UpdateCurrentHeight(); FORCEINLINE float GetCurrentHeight()const { return CurrentHeight; } // 重置玩家对象属性,用于因某些原因导致的系统事件失效情况 UFUNCTION(BlueprintCallable) void ResetPlayerProperty(); UFUNCTION(BlueprintCallable) void MoveToLongitudeLatitudeHeight(const FVector& LongitudeLatitudeHeight); UFUNCTION(BlueprintPure) bool IsFlying() { return bFlying; } UFUNCTION(BlueprintCallable) void EnableCameraLag(bool bOpen); UFUNCTION(BlueprintCallable) void SetMaxRollDistance(float _MaxDistance); FConvexVolume GetViewFrustum(); bool CheckPointInViewFrustum(const FVector& Point); // 停止按键移动 UFUNCTION(BlueprintCallable) void StopKeyMove(); // 允许按键移动 UFUNCTION(BlueprintCallable) void StartKeyMove(); UFUNCTION(BlueprintCallable) void SetEnabledAroundPointRotation(bool bEnabled) { IsEnabledAroundPointRotation = bEnabled; } UFUNCTION(BlueprintCallable) void ClearCurrentSlowStopMoveOffsetTime(); public: //正在创建对象 UPROPERTY(BlueprintReadWrite) bool IsCreatingActor; protected: virtual void BeginPlay()override; virtual void SetupPlayerInputComponent(UInputComponent* InInputComponent) override; void PressMouseMiddleButton(); void ReleaseMouseMiddleButton(); UFUNCTION(BlueprintCallable) void PressMouseLeftButton(); UFUNCTION(BlueprintCallable) void ReleaseMouseLeftButton(); UFUNCTION(BlueprintCallable) void PressMouseRightButton(); UFUNCTION(BlueprintCallable) void ReleaseMouseRightButton(); void _TurnAtRate(const FInputActionValue& Value); void GamePadTurnAtRate(const FInputActionValue& Value); void _LookUpAtRate(const FInputActionValue& Value); void GamePadLookUpAtRate(const FInputActionValue& Value); // 通过滚动轴缩进距离 void MouseRollDistance(const FInputActionValue& Value); void TS_TriggeredTwoTouch(const FInputActionValue& Value); void TS_MouseRollDistance(const FInputActionValue& Value); void TS_PressTwoTouch(); void TS_ReleaseTwoTouch(); void TS_FOVRotation(const FInputActionValue& Value); void TS_UpDownPitch(const FInputActionValue& Value); void TS_StartAction(); void MouseLeftMovePawn(const FInputActionValue& Value); UFUNCTION(BlueprintCallable) void TouchMovePawn(FVector2D CurScreenPosition, FVector2D LastScreenPosition); void UpdataMoveToLocation(float DeltaTime); UFUNCTION(BlueprintCallable) FORCEINLINE void SetGeoreference(TSoftObjectPtr TheGeoreference) { Georeference = TheGeoreference; } void _MoveForward(const FInputActionValue& TheValue); void ReleaseMoveButton(); void StopMoveForward(); void StopMoveRight(); UFUNCTION(BlueprintImplementableEvent) void UpdateOriginCoordinate(); // 设置是否允许鼠标左键移动 UFUNCTION(BlueprintCallable) void AllowLeftMouseMovePlayer(bool bAllow); UFUNCTION(BlueprintCallable) bool GetKeyMoveState(); UFUNCTION(BlueprintCallable) bool GetPressLeftMouseKey() { return bPressMouseLeftKey; }; // 自动更新,通过鼠标右键进行旋转时产生的滑动效果 void UpdateSlideRotation(float DeltaTime); protected: //鼠标中键值 UPROPERTY(BlueprintReadOnly) float MiddleKeyValue; private: void StartSlowStopMove(); // 停止通过鼠标左键移动 void StopMouseLeftMove(); // 延迟更新原点 void DelayUpdateOrigin(float DelayTime = 0.1); // 当鼠标左键移动以后的缓冲惯性移动 void InertialMove(float DeltaTime); private: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MouseLeftAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MouseRightAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* TurnAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* LookUpAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MouseRollAxisAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MouseMiddleAxisAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MoveForwardAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* MoveRightAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* TS_TwoTouchAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* GamePadTurnAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputAction* GamePadLookUPAsset; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UInputMappingContext* BaseInputAction; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Controller, meta = (AllowPrivateAccess = "true")) ARoverController* PlayerController; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UCesiumFlyToComponent* FlyComp; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) UCameraComponent* Camera; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) USpringArmComponent* SpringArm; // 是否按下鼠标中键 bool bPressMouseMiddleKey; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) float SelfBaseTurnRate; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InputAction, meta = (AllowPrivateAccess = "true")) float SelfBaseLookUpRate; // 滚动中键时的缩放速度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float ZoomRollSpeed; // 当绕中间旋转时保存的屏幕中间位置 FVector screenMiddleLocation; // 按下中键旋转的角度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float RotateAngle; // 是否按下鼠标右键 bool bPressMouseRightKey; // 是否按下鼠标左键 bool bPressMouseLeftKey; FVector2D MousePosition; FVector2D LastMousePosition; FVector2D TestMousePosition; FVector2D TestLastMousePosition; // 鼠标左键基础移动速率 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float BaseMouseLeftMoveRate; // 通过鼠标左键移动到的位置 FVector MoveToLocation; UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter = SetGeoreference, Category = Property, meta = (AllowPrivateAccess = "true")) TSoftObjectPtr Georeference; // 刷新当前原点经纬度 FTimerHandle RefreshOriginLongitudeLatitudeTimer; // 当超过最大距离时刷新原点经纬度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float MaxDistance; // 当前是否在向(前/后)移动 bool bMoveForward; // 当前是否在向(左/右)移动 bool bMoveRight; FVector ForwardDirection; FVector RightDirection; // 按键移动速度 float MoveSpeed; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Class, meta = (AllowPrivateAccess = "true")) TSubclassOf QuitGameDialogClass; // 是否限制绕点旋转的视角 bool bLimitViewport; // 是否允许鼠标左键移动 bool bAllowMouseLeftMove; // 当使用左键移动时,控制高度来控制移动速度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float ControlHeightMulitiplier; // 当使用左键移动时,控制高度来控制移动速度乘数 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float LongitudeLatitudeControlHeightMulitiplier; // 鼠标左键移动时的缓慢停止移动计时器 FTimerHandle SlowStopMoveTimer; // 鼠标移动偏移乘数(用于多少时间停止移动的乘数) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float MouseMoveOffsetMulitiplier; // 是否允许更新鼠标左键移动 bool bAllowUpdataMove; // 鼠标最后一次移动的方向 FVector MoveDirectionLast; // 缓慢停止时的移动速度 float SlowStopMoveSpeed; // 总的缓慢停止时的拖尾移动时间 float TotalSlowStopMoveOffsetTime; // 当前缓慢停止时的拖尾移动时间 float CurrentSlowStopMoveOffsetTime; // 高度转变鼠标移动方式的阈值 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float ChangeHeightThreshold; // 更新原点经纬度计时器 FTimerHandle UpdateOriginLongitudeLatitdeTimer; // 当前是否正在飞行 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) bool bFlying; // 当进行滚动轴缩放时,滚动点离屏幕中心点远时的平移缩放偏移乘数 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float ZoomOffsetMulitiplier; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) // 当高于该阈值时更新缩放偏移 float ZoomOffsetHeightValue; // 当前是否跟随运动轨迹 bool bFollowSportTrace; // 在飞行途中更新原点计时器 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Timer, meta = (AllowPrivateAccess = "true")) FTimerHandle UpdateFlyOriginTimer; // 从当前位置到移动位置的距离 double CurrentMoveDistance; // 移动速度乘数 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) double MoveSpeedMultiplier; // 是否允许惯性移动 bool bAllowInertialMove; FVector MouseClickLongitudeLatitude; UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter = SetAssistMouseLeftMoveActor, Category = Move, meta = (AllowPrivateAccess = "true")) TSoftObjectPtr< AStaticMeshActor> AssistMouseLeftMoveActor; ECollisionChannel CheckMoveCollisionChannel; // 当前选择的模式 ESelecteItemMode SelecteItemMode; // 上一次选择的模式 ESelecteItemMode LastSelecteItemMode; // 当正在进行自动旋转时,如果按下鼠标右键自行选择角度时临时停止旋转 bool bTempStopAutoRotate; // 当前高亮模型对象 USkeletalMeshComponent* CurrentHightLightModel; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) bool bHDRIMode = false; // 鼠标右键的滑动速度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float SlideSpeed = 1; // 滑动时间 float SlideTime = 0; float TotalSlideTime = 0; // 滑动速度乘数 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float SlideSpeedMulitiplier = 0.01f; // 当前最大滚动距离 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float CurrentMaxRollDistance = 1000000000.0f; //最大滚动系数 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Move, meta = (AllowPrivateAccess = "true")) float MaxRollCoefficient = 1.f; // 是否按下移动按钮(W,S,A,D) bool bPressMoveButton = false; // 绕一个点旋转的极限值 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Rotate, meta = (AllowPrivateAccess = "true")) float LimitValueOfRotateAroundPoint = 911352.5488545; // 当前是否按下双指缩放 bool bTS_PressTwoTouch = false; FVector2D Touch1, Touch2; FVector2D LastTouch1, LastTouch2; bool bPressTouch1, bPressTouch2; FTimerHandle TS_ActionTimer; bool bTS_StartAction = false; ETSAction TS_ActionStatus = ETSAction::ETS_Default; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float TS_DelayTime = 0.07f; std::optional TS_ZoomHitResult = std::nullopt; // 双指触摸延迟释放 FTimerHandle TS_DelayReleaseTimer; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float CurrentHeight = 0; // 最大跨越纬度 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property, meta = (AllowPrivateAccess = "true")) float MaxCrossingLatitude = 75.f; // 当通过鼠标左键移动地球时,鼠标没有点到地形的情况下运行 bool bAllowUpdateSlide = false; // 当角色纬度超过正负MaxCrossingLatitude时,启用平滑过渡 FTimerHandle CrossingLatitudeTimer; // 更新高度计时器 FTimerHandle UpdateHeightTimer; // 用于更新在太空没有击中地面时是否使用缓慢滑行 bool bAllowSlowStopMove = true; // 当前是否在仰视天空,如果在仰视且点中天空就执行平移变旋转视角 bool bCurrentLookingup = false; // 当在旋转时释放移动操作 FTimerHandle ReleaseMoveButtonTimer; std::atomic PlayerLongitudeLatitudeHeight = FVector(0); bool bKeyMove = true; bool IsEnabledAroundPointRotation = true; public: static ARover* PlayerPawn; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Property) bool IsUpdateOrignLongitudeLatitude = true; };