引入 Cinemachine 和 CameraModule,添加摄像机跟随缓动效果
This commit is contained in:
@@ -124,134 +124,6 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 8294607788038773239}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &5383497626468778460
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 5901618247908801032}
|
||||
- component: {fileID: 4064848608618185461}
|
||||
- component: {fileID: 4294245010031275705}
|
||||
m_Layer: 7
|
||||
m_Name: Camera
|
||||
m_TagString: MainCamera
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &5901618247908801032
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5383497626468778460}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
|
||||
m_LocalPosition: {x: 0, y: 10, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 9112716898534404901}
|
||||
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
|
||||
--- !u!20 &4064848608618185461
|
||||
Camera:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5383497626468778460}
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_ClearFlags: 1
|
||||
m_BackGroundColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
m_projectionMatrixMode: 1
|
||||
m_GateFitMode: 2
|
||||
m_FOVAxisMode: 0
|
||||
m_Iso: 200
|
||||
m_ShutterSpeed: 0.005
|
||||
m_Aperture: 16
|
||||
m_FocusDistance: 10
|
||||
m_FocalLength: 50
|
||||
m_BladeCount: 5
|
||||
m_Curvature: {x: 2, y: 11}
|
||||
m_BarrelClipping: 0.25
|
||||
m_Anamorphism: 0
|
||||
m_SensorSize: {x: 36, y: 24}
|
||||
m_LensShift: {x: 0, y: 0}
|
||||
m_NormalizedViewPortRect:
|
||||
serializedVersion: 2
|
||||
x: 0
|
||||
y: 0
|
||||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 50
|
||||
field of view: 80
|
||||
orthographic: 1
|
||||
orthographic size: 10
|
||||
m_Depth: 0
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_RenderingPath: -1
|
||||
m_TargetTexture: {fileID: 0}
|
||||
m_TargetDisplay: 0
|
||||
m_TargetEye: 3
|
||||
m_HDR: 1
|
||||
m_AllowMSAA: 1
|
||||
m_AllowDynamicResolution: 0
|
||||
m_ForceIntoRT: 0
|
||||
m_OcclusionCulling: 1
|
||||
m_StereoConvergence: 10
|
||||
m_StereoSeparation: 0.022
|
||||
--- !u!114 &4294245010031275705
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5383497626468778460}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_RenderShadows: 1
|
||||
m_RequiresDepthTextureOption: 2
|
||||
m_RequiresOpaqueTextureOption: 2
|
||||
m_CameraType: 0
|
||||
m_Cameras: []
|
||||
m_RendererIndex: -1
|
||||
m_VolumeLayerMask:
|
||||
serializedVersion: 2
|
||||
m_Bits: 1
|
||||
m_VolumeTrigger: {fileID: 0}
|
||||
m_VolumeFrameworkUpdateModeOption: 2
|
||||
m_RenderPostProcessing: 0
|
||||
m_Antialiasing: 0
|
||||
m_AntialiasingQuality: 2
|
||||
m_StopNaN: 0
|
||||
m_Dithering: 0
|
||||
m_ClearDepth: 1
|
||||
m_AllowXRRendering: 1
|
||||
m_AllowHDROutput: 1
|
||||
m_UseScreenCoordOverride: 0
|
||||
m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0}
|
||||
m_RequiresDepthTexture: 0
|
||||
m_RequiresColorTexture: 0
|
||||
m_Version: 2
|
||||
m_TaaSettings:
|
||||
m_Quality: 3
|
||||
m_FrameInfluence: 0.1
|
||||
m_JitterScale: 1
|
||||
m_MipBias: 0
|
||||
m_VarianceClampScale: 0.9
|
||||
m_ContrastAdaptiveSharpening: 0
|
||||
--- !u!1 &6372140121958224629
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -390,7 +262,6 @@ Transform:
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children:
|
||||
- {fileID: 5901618247908801032}
|
||||
- {fileID: 8294607788038773239}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace SepCore.Procedure
|
||||
|
||||
GameEntry.UIRouter.CloseUIAsync(UIFormType.HudForm).Forget();
|
||||
|
||||
GameEntry.CameraModule?.SetTarget(null);
|
||||
Player = null;
|
||||
GameEntry.SimulationWorld?.ClearSimulationState();
|
||||
|
||||
@@ -126,6 +127,7 @@ namespace SepCore.Procedure
|
||||
try
|
||||
{
|
||||
Player = await GameEntry.Entity.ShowPlayerAsync(_currentPlayerData);
|
||||
GameEntry.CameraModule?.SetTarget(Player != null ? Player.CachedTransform : null);
|
||||
await GameEntry.UIRouter.OpenUIAsync(UIFormType.HudForm);
|
||||
|
||||
int selectedRoleId = procedureOwner.GetData<VarInt32>("SelectedRoleId").Value;
|
||||
|
||||
@@ -3,6 +3,7 @@ using SepCore.DamageText;
|
||||
using SepCore.EnemyManager;
|
||||
using SepCore.HPBar;
|
||||
using SepCore.InputModule.Runtime;
|
||||
using SepCore.CameraModule;
|
||||
using SepCore.SpriteCache;
|
||||
using SepCore.UIRouter;
|
||||
using SepCore.Simulation;
|
||||
@@ -28,6 +29,8 @@ public partial class GameEntry
|
||||
|
||||
public static InputModuleComponent InputModule { get; private set; }
|
||||
|
||||
public static CameraModuleComponent CameraModule { get; private set; }
|
||||
|
||||
private static void InitCustomComponents()
|
||||
{
|
||||
BuiltinData = UnityGameFramework.Runtime.GameEntry.GetComponent<BuiltinDataComponent>();
|
||||
@@ -38,5 +41,6 @@ public partial class GameEntry
|
||||
SpriteCache = UnityGameFramework.Runtime.GameEntry.GetComponent<SpriteCacheComponent>();
|
||||
UIRouter = UnityGameFramework.Runtime.GameEntry.GetComponent<UIRouterComponent>();
|
||||
InputModule = UnityGameFramework.Runtime.GameEntry.GetComponent<InputModuleComponent>();
|
||||
CameraModule = UnityGameFramework.Runtime.GameEntry.GetComponent<CameraModuleComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c8aaad9a99f4e65a6ef8c47bc18873e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace SepCore.CameraModule
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityGameFramework 侧的相机模块组件。
|
||||
/// 作为 GameEntry.CameraModule 访问入口,统一持有并转发 CameraModule 控制器能力。
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
public class CameraModuleComponent : GameFrameworkComponent
|
||||
{
|
||||
[SerializeField] private CinemachineCameraController _cinemachineController;
|
||||
[SerializeField] private bool _autoSearchController = true;
|
||||
[SerializeField] private bool _logMissingControllerWarnings = true;
|
||||
|
||||
private ICameraController _controller;
|
||||
private bool _hasLoggedMissingController;
|
||||
|
||||
public ICameraController Controller
|
||||
{
|
||||
get
|
||||
{
|
||||
ResolveController(false);
|
||||
return IsControllerValid(_controller) ? _controller : null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasController => Controller != null;
|
||||
|
||||
public Transform Target => Controller?.Target;
|
||||
|
||||
public CameraEffectSettings CurrentSettings => Controller?.CurrentSettings ?? CameraEffectSettings.Default;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
ResolveController(false);
|
||||
}
|
||||
|
||||
public void RegisterController(ICameraController controller)
|
||||
{
|
||||
if (!IsControllerValid(controller))
|
||||
{
|
||||
Log.Warning("CameraModuleComponent.RegisterController() controller is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_controller = controller;
|
||||
_hasLoggedMissingController = false;
|
||||
if (controller is CinemachineCameraController cinemachineController)
|
||||
{
|
||||
_cinemachineController = cinemachineController;
|
||||
}
|
||||
}
|
||||
|
||||
public void UnregisterController(ICameraController controller)
|
||||
{
|
||||
if (controller != null && !ReferenceEquals(_controller, controller))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_controller = null;
|
||||
_cinemachineController = null;
|
||||
}
|
||||
|
||||
public void SetTarget(Transform target)
|
||||
{
|
||||
if (!EnsureController())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_controller.SetTarget(target);
|
||||
}
|
||||
|
||||
public void ApplySettings(CameraEffectSettings settings)
|
||||
{
|
||||
if (!EnsureController())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_controller.ApplySettings(settings);
|
||||
}
|
||||
|
||||
public void EnableEffect(CameraEffectType effect)
|
||||
{
|
||||
if (!EnsureController())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_controller.EnableEffect(effect);
|
||||
}
|
||||
|
||||
public void DisableEffect(CameraEffectType effect)
|
||||
{
|
||||
if (!EnsureController())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_controller.DisableEffect(effect);
|
||||
}
|
||||
|
||||
public bool IsEffectEnabled(CameraEffectType effect)
|
||||
{
|
||||
return EnsureController() && _controller.IsEffectEnabled(effect);
|
||||
}
|
||||
|
||||
private bool EnsureController()
|
||||
{
|
||||
ResolveController(_logMissingControllerWarnings);
|
||||
return IsControllerValid(_controller);
|
||||
}
|
||||
|
||||
private void ResolveController(bool logWarning)
|
||||
{
|
||||
if (IsControllerValid(_controller))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_cinemachineController != null)
|
||||
{
|
||||
_controller = _cinemachineController;
|
||||
_hasLoggedMissingController = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_autoSearchController)
|
||||
{
|
||||
LogMissingController(logWarning);
|
||||
return;
|
||||
}
|
||||
|
||||
_cinemachineController = GetComponentInChildren<CinemachineCameraController>(true);
|
||||
if (_cinemachineController == null)
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
_cinemachineController = FindFirstObjectByType<CinemachineCameraController>(FindObjectsInactive.Include);
|
||||
#else
|
||||
_cinemachineController = FindObjectOfType<CinemachineCameraController>(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_cinemachineController != null)
|
||||
{
|
||||
_controller = _cinemachineController;
|
||||
_hasLoggedMissingController = false;
|
||||
return;
|
||||
}
|
||||
|
||||
LogMissingController(logWarning);
|
||||
}
|
||||
|
||||
private void LogMissingController(bool logWarning)
|
||||
{
|
||||
if (!logWarning || _hasLoggedMissingController)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_hasLoggedMissingController = true;
|
||||
Log.Warning(
|
||||
"CameraModuleComponent requires a CinemachineCameraController. " +
|
||||
"Assign one in Inspector or place one in the loaded scene.");
|
||||
}
|
||||
|
||||
private static bool IsControllerValid(ICameraController controller)
|
||||
{
|
||||
if (controller == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (controller is Object unityObject && unityObject == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b77e5f4f170e44f38f20d5ac2dd287e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -11,7 +11,9 @@
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:fca0f81bc71f1944887dd65f134c54a0",
|
||||
"GUID:47a82ffa13c291447ab895cd0bc251cd",
|
||||
"GUID:d54b9488b03814a44ab937f0aeb738b1"
|
||||
"GUID:d54b9488b03814a44ab937f0aeb738b1",
|
||||
"GUID:0e6a2ce06de727c44965fbc35958920f",
|
||||
"GUID:1ddd9fc6811c1d14bbde99bd57869070"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
@@ -22,4 +24,4 @@
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user