引入 Cinemachine 和 CameraModule,添加摄像机跟随缓动效果
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.CameraModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 相机效果配置参数。
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct CameraEffectSettings
|
||||
{
|
||||
[Header("跟随缓动 (FollowDamping)")]
|
||||
[Tooltip("X 轴阻尼,值越大跟随后的响应越慢")]
|
||||
[Range(0f, 20f)]
|
||||
public float dampingX;
|
||||
|
||||
[Tooltip("Y 轴阻尼")]
|
||||
[Range(0f, 20f)]
|
||||
public float dampingY;
|
||||
|
||||
[Tooltip("Z 轴阻尼")]
|
||||
[Range(0f, 20f)]
|
||||
public float dampingZ;
|
||||
|
||||
[Header("移动方向偏移 (MovementDirectionOffset)")]
|
||||
[Tooltip("偏移强度系数,值越大偏移越明显")]
|
||||
[Range(0f, 10f)]
|
||||
public float offsetStrength;
|
||||
|
||||
[Tooltip("最大偏移距离(世界单位)")]
|
||||
[Range(0f, 20f)]
|
||||
public float maxOffsetDistance;
|
||||
|
||||
[Tooltip("偏移平滑速度")]
|
||||
[Range(0f, 20f)]
|
||||
public float offsetSmoothing;
|
||||
|
||||
[Tooltip("偏移采样速度低于此值时不产生偏移")]
|
||||
[Range(0f, 5f)]
|
||||
public float offsetDeadZone;
|
||||
|
||||
/// <summary>
|
||||
/// 默认配置:适中的阻尼和偏移参数。
|
||||
/// </summary>
|
||||
public static CameraEffectSettings Default => new CameraEffectSettings
|
||||
{
|
||||
dampingX = 1f,
|
||||
dampingY = 1f,
|
||||
dampingZ = 1f,
|
||||
offsetStrength = 2f,
|
||||
maxOffsetDistance = 3f,
|
||||
offsetSmoothing = 5f,
|
||||
offsetDeadZone = 0.1f,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d1e0d1682fb702543b5fd918d51c72c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SepCore.CameraModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 相机效果类型,用于开关控制。
|
||||
/// </summary>
|
||||
public enum CameraEffectType
|
||||
{
|
||||
/// <summary>
|
||||
/// 跟随缓动 —— 相机跟随目标时的阻尼平滑。
|
||||
/// </summary>
|
||||
FollowDamping,
|
||||
|
||||
/// <summary>
|
||||
/// 移动方向偏移 —— 相机根据目标移动方向产生额外偏移。
|
||||
/// </summary>
|
||||
MovementDirectionOffset,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7676c458713132547a745d42db4cf179
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace SepCore.CameraModule
|
||||
{
|
||||
/// <summary>
|
||||
/// 相机控制器接口。Base 层定义,Runtime 层(Cinemachine)实现。
|
||||
/// </summary>
|
||||
public interface ICameraController
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前跟随目标。
|
||||
/// </summary>
|
||||
Transform Target { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置跟随目标。传 null 则停止跟随。
|
||||
/// </summary>
|
||||
void SetTarget(Transform target);
|
||||
|
||||
/// <summary>
|
||||
/// 启用指定效果。
|
||||
/// </summary>
|
||||
void EnableEffect(CameraEffectType effect);
|
||||
|
||||
/// <summary>
|
||||
/// 禁用指定效果。
|
||||
/// </summary>
|
||||
void DisableEffect(CameraEffectType effect);
|
||||
|
||||
/// <summary>
|
||||
/// 查询指定效果是否启用。
|
||||
/// </summary>
|
||||
bool IsEffectEnabled(CameraEffectType effect);
|
||||
|
||||
/// <summary>
|
||||
/// 应用效果配置参数。会立即生效。
|
||||
/// </summary>
|
||||
void ApplySettings(CameraEffectSettings settings);
|
||||
|
||||
/// <summary>
|
||||
/// 当前生效的配置参数。
|
||||
/// </summary>
|
||||
CameraEffectSettings CurrentSettings { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c239333c308a174685e7f732738603b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "SepCore.CameraModule.Base",
|
||||
"rootNamespace": "SepCore.CameraModule",
|
||||
"references": [
|
||||
"GUID:363c5eb08ff8e6a439b85e37b8c20d96",
|
||||
"GUID:a04b272484018094ab427253f20c416c"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e6a2ce06de727c44965fbc35958920f
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user