第一次提交
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Interface.h"
|
||||
|
||||
#include "GCMS_CameraAssistInterface.generated.h"
|
||||
|
||||
/** */
|
||||
UINTERFACE(BlueprintType)
|
||||
class UGCMS_CameraAssistInterface : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
class GENERICCAMERASYSTEM_API IGCMS_CameraAssistInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
/**
|
||||
* Get the list of actors that we're allowing the camera to penetrate. Useful in 3rd person cameras
|
||||
* when you need the following camera to ignore things like the a collection of view targets, the pawn,
|
||||
* a vehicle..etc.
|
||||
*/
|
||||
virtual void GetIgnoredActorsForCameraPentration(TArray<const AActor*>& OutActorsAllowPenetration) const { }
|
||||
|
||||
/**
|
||||
* The target actor to prevent penetration on. Normally, this is almost always the view target, which if
|
||||
* unimplemented will remain true. However, sometimes the view target, isn't the same as the root actor
|
||||
* you need to keep in frame.
|
||||
*/
|
||||
virtual TOptional<AActor*> GetCameraPreventPenetrationTarget() const
|
||||
{
|
||||
return TOptional<AActor*>();
|
||||
}
|
||||
|
||||
/** Called if the camera penetrates the focal target. Useful if you want to hide the target actor when being overlapped. */
|
||||
virtual void OnCameraPenetratingTarget() { }
|
||||
};
|
||||
235
Plugins/GGS/Source/GenericCameraSystem/Public/GCMS_CameraMode.h
Normal file
235
Plugins/GGS/Source/GenericCameraSystem/Public/GCMS_CameraMode.h
Normal file
@@ -0,0 +1,235 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/World.h"
|
||||
#include "GameplayTagContainer.h"
|
||||
|
||||
#include "GCMS_CameraMode.generated.h"
|
||||
|
||||
class USpringArmComponent;
|
||||
class UCameraComponent;
|
||||
class AActor;
|
||||
class UCanvas;
|
||||
|
||||
/**
|
||||
* EGCMS_CameraModeBlendFunction
|
||||
*
|
||||
* Blend function used for transitioning between camera modes.
|
||||
*/
|
||||
UENUM(BlueprintType)
|
||||
enum class EGCMS_CameraModeBlendFunction : uint8
|
||||
{
|
||||
// Does a simple linear interpolation.
|
||||
Linear,
|
||||
|
||||
// Immediately accelerates, but smoothly decelerates into the target. Ease amount controlled by the exponent.
|
||||
EaseIn,
|
||||
|
||||
// Smoothly accelerates, but does not decelerate into the target. Ease amount controlled by the exponent.
|
||||
EaseOut,
|
||||
|
||||
// Smoothly accelerates and decelerates. Ease amount controlled by the exponent.
|
||||
EaseInOut,
|
||||
|
||||
COUNT UMETA(Hidden)
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* GCMS_CameraModeView
|
||||
*
|
||||
* View data produced by the camera mode that is used to blend camera modes.
|
||||
*/
|
||||
USTRUCT(BlueprintType)
|
||||
struct GENERICCAMERASYSTEM_API FGCMS_CameraModeView
|
||||
{
|
||||
public:
|
||||
GENERATED_BODY()
|
||||
|
||||
FGCMS_CameraModeView();
|
||||
|
||||
void Blend(const FGCMS_CameraModeView& Other, float OtherWeight);
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
FVector Location{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
FRotator Rotation{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
FVector SprintArmSocketOffset{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
FVector SprintArmTargetOffset{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
float SprintArmLength{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
FRotator ControlRotation{ForceInit};
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="GCMS")
|
||||
float FieldOfView{ForceInit};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* UGCMS_CameraMode
|
||||
*
|
||||
* Base class for all camera modes.
|
||||
*/
|
||||
UCLASS(Abstract, Blueprintable)
|
||||
class GENERICCAMERASYSTEM_API UGCMS_CameraMode : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UGCMS_CameraMode();
|
||||
|
||||
virtual UWorld* GetWorld() const override;
|
||||
|
||||
/**
|
||||
* @return Returns the target actor that owning camera is looking at. 返回所属相机当前跟随的目标Actor。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="CameraMode")
|
||||
AActor* GetTargetActor() const;
|
||||
|
||||
const FGCMS_CameraModeView& GetCameraModeView() const { return View; }
|
||||
|
||||
// Called when this camera mode is activated on the camera mode stack.
|
||||
virtual void OnActivation()
|
||||
{
|
||||
K2_OnActivation();
|
||||
};
|
||||
|
||||
// Called when this camera mode is deactivated on the camera mode stack.
|
||||
virtual void OnDeactivation()
|
||||
{
|
||||
K2_OnDeactivation();
|
||||
};
|
||||
|
||||
void UpdateCameraMode(float DeltaTime);
|
||||
|
||||
float GetBlendTime() const { return BlendTime; }
|
||||
float GetBlendWeight() const { return BlendWeight; }
|
||||
void SetBlendWeight(float Weight);
|
||||
|
||||
FGameplayTag GetCameraTypeTag() const
|
||||
{
|
||||
return CameraTypeTag;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="CameraMode")
|
||||
UCameraComponent* GetAssociatedCamera() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="CameraMode")
|
||||
USpringArmComponent* GetAssociatedSprintArm() const;
|
||||
|
||||
virtual void DrawDebug(UCanvas* Canvas) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called when this camera mode activated.
|
||||
* 在此相机模式激活时调用。
|
||||
*/
|
||||
UFUNCTION(BlueprintImplementableEvent, Category="CameraMode", meta=(DisplayName="OnActivation"))
|
||||
void K2_OnActivation();
|
||||
|
||||
/**
|
||||
* Called when this camera mode deactivated.
|
||||
* 在此相机模式禁用时调用。
|
||||
*/
|
||||
UFUNCTION(BlueprintImplementableEvent, Category="CameraMode", meta=(DisplayName="OnDeactivation"))
|
||||
void K2_OnDeactivation();
|
||||
|
||||
/**
|
||||
* Return the pivot location of this camera mode.
|
||||
* @details Default will return Character's capsule location(Taking crouching state in count), or fallback to Pawn's ViewLocation or fallback to PawnLocation.
|
||||
* 返回此相机模式的轴心位置。
|
||||
* @细节,默认实现是返回考虑到Character的蹲伏状态的胶囊体中心点,或者回退到Pawn的ViewLocation,或者回退到Pawn的Location。
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category="CameraMode")
|
||||
FVector GetPivotLocation() const;
|
||||
|
||||
/**
|
||||
* Return the pivot rotation of this camera mode.
|
||||
* @details Default will return TargetActor(Pawn)'s view rotation or fallback to actor rotation.
|
||||
* 返回此相机模式的轴心旋转。
|
||||
* @细节 默认会返回TargetActor(Pawn)的ViewRotation,或者回退到Actor的旋转。
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category="CameraMode")
|
||||
FRotator GetPivotRotation() const;
|
||||
|
||||
virtual void UpdateView(float DeltaTime);
|
||||
|
||||
virtual void UpdateBlending(float DeltaTime);
|
||||
|
||||
/**
|
||||
* This is where you update View(CameraModeView)
|
||||
* @param DeltaTime
|
||||
* @param PivotLocation Location returned from GetPivotLocation
|
||||
* @param PivotRotation Rotation returned from GetPivotRotation
|
||||
*/
|
||||
UFUNCTION(BlueprintNativeEvent, Category="CameraMode")
|
||||
void OnUpdateView(float DeltaTime, FVector PivotLocation, FRotator PivotRotation);
|
||||
virtual void OnUpdateView_Implementation(float DeltaTime, FVector PivotLocation, FRotator PivotRotation);
|
||||
|
||||
protected:
|
||||
// A tag that can be queried by gameplay code that cares when a kind of camera mode is active
|
||||
// without having to ask about a specific mode (e.g., when aiming downsights to get more accuracy)
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Blending")
|
||||
FGameplayTag CameraTypeTag;
|
||||
|
||||
// View output produced by the camera mode.
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category="View")
|
||||
FGCMS_CameraModeView View;
|
||||
|
||||
// The horizontal field of view (in degrees).
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "View", Meta = (UIMin = "5.0", UIMax = "170", ClampMin = "5.0", ClampMax = "170.0"))
|
||||
float FieldOfView;
|
||||
|
||||
// Minimum view pitch (in degrees).
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "View", Meta = (UIMin = "-89.9", UIMax = "89.9", ClampMin = "-89.9", ClampMax = "89.9"))
|
||||
float ViewPitchMin;
|
||||
|
||||
// Maximum view pitch (in degrees).
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "View", Meta = (UIMin = "-89.9", UIMax = "89.9", ClampMin = "-89.9", ClampMax = "89.9"))
|
||||
float ViewPitchMax;
|
||||
|
||||
/**
|
||||
* How long it takes to blend in this mode.
|
||||
* 此相机模式的混入时间。
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Blending")
|
||||
float BlendTime;
|
||||
|
||||
/**
|
||||
* Function used for blending.
|
||||
* 用于混合的方式。
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Blending")
|
||||
EGCMS_CameraModeBlendFunction BlendFunction;
|
||||
|
||||
// Exponent used by blend functions to control the shape of the curve.
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Blending")
|
||||
float BlendExponent;
|
||||
|
||||
// Linear blend alpha used to determine the blend weight.
|
||||
UPROPERTY(VisibleInstanceOnly, Category="Blending")
|
||||
float BlendAlpha;
|
||||
|
||||
// Blend weight calculated using the blend alpha and function.
|
||||
UPROPERTY(VisibleInstanceOnly, Category="Blending")
|
||||
float BlendWeight;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Duration")
|
||||
float ActiveTime;
|
||||
|
||||
/**
|
||||
* The max active time of this camera mode, When active time reach this value, this camera mode will auto popup.
|
||||
* 此相机模式的最大激活时间,当当前激活时间到达此时长,会返回到默认相机模式。
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "Duraction")
|
||||
float MaxActiveTime;
|
||||
|
||||
protected:
|
||||
/** If true, skips all interpolation and puts camera in ideal location. Automatically set to false next frame. */
|
||||
UPROPERTY(transient)
|
||||
uint32 bResetInterpolation : 1;
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GCMS_CameraMode.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "GCMS_CameraModeStack.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
* UGCMS_CameraModeStack
|
||||
*
|
||||
* Stack used for blending camera modes.
|
||||
*/
|
||||
UCLASS()
|
||||
class GENERICCAMERASYSTEM_API UGCMS_CameraModeStack : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UGCMS_CameraModeStack();
|
||||
|
||||
void ActivateStack();
|
||||
void DeactivateStack();
|
||||
|
||||
bool IsStackActivate() const { return bIsActive; }
|
||||
|
||||
void PushCameraMode(TSubclassOf<UGCMS_CameraMode> CameraModeClass);
|
||||
|
||||
void PopCameraMode(TSubclassOf<UGCMS_CameraMode> CameraModeClass);
|
||||
|
||||
bool EvaluateStack(float DeltaTime, FGCMS_CameraModeView& OutCameraModeView);
|
||||
|
||||
void DrawDebug(UCanvas* Canvas) const;
|
||||
|
||||
// Gets the tag associated with the top layer and the blend weight of it
|
||||
void GetBlendInfo(float& OutWeightOfTopLayer, FGameplayTag& OutTagOfTopLayer) const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Get or create new camera mode.
|
||||
*/
|
||||
UGCMS_CameraMode* GetCameraModeInstance(TSubclassOf<UGCMS_CameraMode> CameraModeClass);
|
||||
|
||||
void UpdateStack(float DeltaTime);
|
||||
void BlendStack(FGCMS_CameraModeView& OutCameraModeView) const;
|
||||
|
||||
protected:
|
||||
bool bIsActive;
|
||||
|
||||
/**
|
||||
* Cached camera mode instance pool.
|
||||
*/
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<UGCMS_CameraMode>> CameraModeInstances;
|
||||
|
||||
/**
|
||||
* The list of active camera mode.
|
||||
*/
|
||||
UPROPERTY()
|
||||
TArray<TObjectPtr<UGCMS_CameraMode>> CameraModeStack;
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
// // Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
//
|
||||
// #pragma once
|
||||
//
|
||||
// #include "Curves/CurveFloat.h"
|
||||
// #include "DrawDebugHelpers.h"
|
||||
// #include "GCMS_CameraMode_WithPenetrationAvoidance.h"
|
||||
// #include "GCMS_CameraMode_ThirdPerson.generated.h"
|
||||
//
|
||||
// class UCurveVector;
|
||||
//
|
||||
// /**
|
||||
// * UGCMS_CameraMode_ThirdPerson
|
||||
// *
|
||||
// * A basic third person camera mode.
|
||||
// */
|
||||
// UCLASS(Abstract, Blueprintable)
|
||||
// class UGCMS_CameraMode_ThirdPerson : public UGCMS_CameraMode_WithPenetrationAvoidance
|
||||
// {
|
||||
// GENERATED_BODY()
|
||||
//
|
||||
// public:
|
||||
// UGCMS_CameraMode_ThirdPerson();
|
||||
//
|
||||
// protected:
|
||||
//
|
||||
// virtual void UpdateView_Implementation(float DeltaTime) override;
|
||||
//
|
||||
// UFUNCTION(BlueprintCallable, Category="Third Person")
|
||||
// void UpdateForTarget(float DeltaTime);
|
||||
//
|
||||
// protected:
|
||||
// // Curve that defines local-space offsets from the target using the view pitch to evaluate the curve.
|
||||
// UPROPERTY(EditDefaultsOnly, Category = "Third Person", Meta = (EditCondition = "!bUseRuntimeFloatCurves"))
|
||||
// TObjectPtr<const UCurveVector> TargetOffsetCurve;
|
||||
//
|
||||
// // UE-103986: Live editing of RuntimeFloatCurves during PIE does not work (unlike curve assets).
|
||||
// // Once that is resolved this will become the default and TargetOffsetCurve will be removed.
|
||||
// UPROPERTY(EditDefaultsOnly, Category = "Third Person")
|
||||
// bool bUseRuntimeFloatCurves;
|
||||
//
|
||||
// // time will be [-ViewPitchMin,ViewPitchMax]
|
||||
// UPROPERTY(EditDefaultsOnly, Category = "Third Person", Meta = (EditCondition = "bUseRuntimeFloatCurves"))
|
||||
// FRuntimeFloatCurve TargetOffsetX;
|
||||
//
|
||||
// // time will be [-ViewPitchMin,ViewPitchMax]
|
||||
// UPROPERTY(EditDefaultsOnly, Category = "Third Person", Meta = (EditCondition = "bUseRuntimeFloatCurves"))
|
||||
// FRuntimeFloatCurve TargetOffsetY;
|
||||
//
|
||||
// // time will be [-ViewPitchMin,ViewPitchMax]
|
||||
// UPROPERTY(EditDefaultsOnly, Category = "Third Person", Meta = (EditCondition = "bUseRuntimeFloatCurves"))
|
||||
// FRuntimeFloatCurve TargetOffsetZ;
|
||||
//
|
||||
// // Alters the speed that a crouch offset is blended in or out
|
||||
// UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Third Person")
|
||||
// float CrouchOffsetBlendMultiplier = 5.0f;
|
||||
//
|
||||
// protected:
|
||||
// void SetTargetCrouchOffset(FVector NewTargetOffset);
|
||||
// void UpdateCrouchOffset(float DeltaTime);
|
||||
//
|
||||
// FVector InitialCrouchOffset = FVector::ZeroVector;
|
||||
// FVector TargetCrouchOffset = FVector::ZeroVector;
|
||||
// float CrouchOffsetBlendPct = 1.0f;
|
||||
// FVector CurrentCrouchOffset = FVector::ZeroVector;
|
||||
// };
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "DrawDebugHelpers.h"
|
||||
#include "GCMS_CameraMode.h"
|
||||
#include "GCMS_CameraPenetrationAvoidanceFeeler.h"
|
||||
#include "GCMS_CameraMode_WithPenetrationAvoidance.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract, Blueprintable)
|
||||
class GENERICCAMERASYSTEM_API UGCMS_CameraMode_WithPenetrationAvoidance : public UGCMS_CameraMode
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UGCMS_CameraMode_WithPenetrationAvoidance();
|
||||
|
||||
// Penetration prevention
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="PenetrationAvoidance")
|
||||
float PenetrationBlendInTime = 0.1f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="PenetrationAvoidance")
|
||||
float PenetrationBlendOutTime = 0.15f;
|
||||
|
||||
/** If true, does collision checks to keep the camera out of the world. */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="PenetrationAvoidance")
|
||||
bool bPreventPenetration = true;
|
||||
|
||||
/** If true, try to detect nearby walls and move the camera in anticipation. Helps prevent popping. */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="PenetrationAvoidance")
|
||||
bool bDoPredictiveAvoidance = true;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PenetrationAvoidance")
|
||||
float CollisionPushOutDistance = 2.f;
|
||||
|
||||
/** When the camera's distance is pushed into this percentage of its full distance due to penetration */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PenetrationAvoidance")
|
||||
float ReportPenetrationPercent = 0.f;
|
||||
|
||||
/**
|
||||
* These are the feeler rays that are used to find where to place the camera.
|
||||
* Index: 0 : This is the normal feeler we use to prevent collisions.
|
||||
* Index: 1+ : These feelers are used if you bDoPredictiveAvoidance=true, to scan for potential impacts if the player
|
||||
* were to rotate towards that direction and primitively collide the camera so that it pulls in before
|
||||
* impacting the occluder.
|
||||
*/
|
||||
UPROPERTY(EditDefaultsOnly, Category = "PenetrationAvoidance")
|
||||
TArray<FGCMS_CameraPenetrationAvoidanceFeeler> PenetrationAvoidanceFeelers;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
float AimLineToDesiredPosBlockedPct;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
TArray<TObjectPtr<const AActor>> DebugActorsHitDuringCameraPenetration;
|
||||
|
||||
#if ENABLE_DRAW_DEBUG
|
||||
mutable float LastDrawDebugTime = -MAX_FLT;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
UFUNCTION(BlueprintCallable, Category="CameraMode|PenetrationAvoidance")
|
||||
void UpdatePreventPenetration(float DeltaTime);
|
||||
UFUNCTION(BlueprintCallable, Category="CameraMode|PenetrationAvoidance")
|
||||
void PreventCameraPenetration(bool bSingleRayOnly, const float& DeltaTime, const AActor* ViewTarget, const FVector& SafeLoc, FVector& CameraLoc, float& DistBlockedPct);
|
||||
|
||||
virtual void DrawDebug(UCanvas* Canvas) const override;
|
||||
};
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Object.h"
|
||||
#include "GCMS_CameraPenetrationAvoidanceFeeler.generated.h"
|
||||
|
||||
|
||||
/**
|
||||
* Struct defining a feeler ray used for camera penetration avoidance.
|
||||
*/
|
||||
USTRUCT()
|
||||
struct GENERICCAMERASYSTEM_API FGCMS_CameraPenetrationAvoidanceFeeler
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
/** FRotator describing deviance from main ray */
|
||||
UPROPERTY(EditAnywhere, Category=PenetrationAvoidanceFeeler)
|
||||
FRotator AdjustmentRot;
|
||||
|
||||
/** how much this feeler affects the final position if it hits the world */
|
||||
UPROPERTY(EditAnywhere, Category=PenetrationAvoidanceFeeler)
|
||||
float WorldWeight;
|
||||
|
||||
/** how much this feeler affects the final position if it hits a APawn (setting to 0 will not attempt to collide with pawns at all) */
|
||||
UPROPERTY(EditAnywhere, Category=PenetrationAvoidanceFeeler)
|
||||
float PawnWeight;
|
||||
|
||||
/** extent to use for collision when tracing this feeler */
|
||||
UPROPERTY(EditAnywhere, Category=PenetrationAvoidanceFeeler)
|
||||
float Extent;
|
||||
|
||||
/** minimum frame interval between traces with this feeler if nothing was hit last frame */
|
||||
UPROPERTY(EditAnywhere, Category=PenetrationAvoidanceFeeler)
|
||||
int32 TraceInterval;
|
||||
|
||||
/** number of frames since this feeler was used */
|
||||
UPROPERTY(transient)
|
||||
int32 FramesUntilNextTrace;
|
||||
|
||||
|
||||
FGCMS_CameraPenetrationAvoidanceFeeler()
|
||||
: AdjustmentRot(ForceInit)
|
||||
, WorldWeight(0)
|
||||
, PawnWeight(0)
|
||||
, Extent(0)
|
||||
, TraceInterval(0)
|
||||
, FramesUntilNextTrace(0)
|
||||
{
|
||||
}
|
||||
|
||||
FGCMS_CameraPenetrationAvoidanceFeeler(const FRotator& InAdjustmentRot,
|
||||
const float& InWorldWeight,
|
||||
const float& InPawnWeight,
|
||||
const float& InExtent,
|
||||
const int32& InTraceInterval = 0,
|
||||
const int32& InFramesUntilNextTrace = 0)
|
||||
: AdjustmentRot(InAdjustmentRot)
|
||||
, WorldWeight(InWorldWeight)
|
||||
, PawnWeight(InPawnWeight)
|
||||
, Extent(InExtent)
|
||||
, TraceInterval(InTraceInterval)
|
||||
, FramesUntilNextTrace(InFramesUntilNextTrace)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
#include "GCMS_CameraSystemComponent.generated.h"
|
||||
|
||||
class UCameraComponent;
|
||||
class USpringArmComponent;
|
||||
class UCanvas;
|
||||
class AHUD;
|
||||
class UGCMS_CameraMode;
|
||||
class UGCMS_CameraModeStack;
|
||||
class UObject;
|
||||
struct FFrame;
|
||||
struct FGameplayTag;
|
||||
struct FMinimalViewInfo;
|
||||
template <class TClass>
|
||||
class TSubclassOf;
|
||||
|
||||
DECLARE_DELEGATE_RetVal(TSubclassOf<UGCMS_CameraMode>, FGMSCameraModeDelegate);
|
||||
|
||||
|
||||
/**
|
||||
* UGCMS_CameraSystemComponent
|
||||
*
|
||||
* The base camera component class used by GMS camera system.
|
||||
*/
|
||||
UCLASS(ClassGroup=GCMS, meta=(BlueprintSpawnableComponent))
|
||||
class GENERICCAMERASYSTEM_API UGCMS_CameraSystemComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UGCMS_CameraSystemComponent(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
static void OnShowDebugInfo(AHUD* HUD, UCanvas* Canvas, const FDebugDisplayInfo& DisplayInfo, float& YL, float& YPos);
|
||||
|
||||
// Returns the camera component if one exists on the specified actor.
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "GCMS|Camera", meta=(DefaultToSelf="Actor"))
|
||||
static UGCMS_CameraSystemComponent* GetCameraSystemComponent(const AActor* Actor) { return (Actor ? Actor->FindComponentByClass<UGCMS_CameraSystemComponent>() : nullptr); }
|
||||
|
||||
/**
|
||||
* Returns the target actor that the camera is looking at.
|
||||
*/
|
||||
virtual AActor* GetTargetActor() const { return GetOwner(); }
|
||||
|
||||
// Delegate used to query for the best camera mode.
|
||||
FGMSCameraModeDelegate DetermineCameraModeDelegate;
|
||||
|
||||
// Add an offset to the field of view. The offset is only for one frame, it gets cleared once it is applied.
|
||||
void AddFieldOfViewOffset(float FovOffset) { FieldOfViewOffset += FovOffset; }
|
||||
|
||||
// Push specified Camera Mode.
|
||||
UFUNCTION(BlueprintCallable, Category="GCMS|Camera")
|
||||
void PushCameraMode(TSubclassOf<UGCMS_CameraMode> NewCameraMode);
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="GCMS|Camera")
|
||||
void PushDefaultCameraMode();
|
||||
|
||||
/**
|
||||
* Initialize it with camera component and sprint arm component.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category="GCMS|Camera")
|
||||
void Initialize(UCameraComponent* NewCameraComponent, USpringArmComponent* NewSpringArmComponent);
|
||||
|
||||
virtual void DrawDebug(UCanvas* Canvas) const;
|
||||
|
||||
/**
|
||||
* Gets the camera mode tag associated with the top layer and the blend weight of it
|
||||
* 返回顶层相机模式的tag和当前权重。
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GCMS|Camera")
|
||||
void GetBlendInfo(float& OutWeightOfTopLayer, FGameplayTag& OutTagOfTopLayer) const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GCMS|Camera")
|
||||
UCameraComponent* GetAssociatedCamera() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category="GCMS|Camera")
|
||||
USpringArmComponent* GetAssociatedSprintArm() const;
|
||||
|
||||
virtual void Activate(bool bReset) override;
|
||||
virtual void Deactivate() override;
|
||||
|
||||
protected:
|
||||
virtual void OnRegister() override;
|
||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
|
||||
virtual void UpdateCameraModes();
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
TObjectPtr<UCameraComponent> AssociatedCameraComponent;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<USpringArmComponent> AssociatedSprintArmComponent;
|
||||
|
||||
// Stack used to blend the camera modes.
|
||||
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category="GCMS|Camera", meta=(ShowInnerProperties))
|
||||
TObjectPtr<UGCMS_CameraModeStack> CameraModeStack;
|
||||
|
||||
// Default camera mode will used.
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="GCMS|Camera")
|
||||
TSubclassOf<UGCMS_CameraMode> DefaultCameraMode;
|
||||
|
||||
// Offset applied to the field of view. The offset is only for one frame, it gets cleared once it is applied.
|
||||
float FieldOfViewOffset;
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
class FGenericCameraSystemModule : public IModuleInterface
|
||||
{
|
||||
public:
|
||||
|
||||
/** IModuleInterface implementation */
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
};
|
||||
Reference in New Issue
Block a user