From 2a6bc6edf82d884fa431a21a18b863972d2cba75 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Fri, 28 Nov 2025 10:24:33 +0800 Subject: [PATCH] =?UTF-8?q?Cinemachine=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Convention | 2 +- Assets/Scenes/Game/GameScene.unity | 138 +++++++----------- Assets/Scripts/Framework/CameraObject.cs | 62 ++++---- .../Framework/GameContent/GameController.cs | 4 +- Packages/manifest.json | 8 +- Packages/packages-lock.json | 13 +- 6 files changed, 99 insertions(+), 128 deletions(-) diff --git a/Assets/Convention b/Assets/Convention index 0b563f3..b643949 160000 --- a/Assets/Convention +++ b/Assets/Convention @@ -1 +1 @@ -Subproject commit 0b563f393b631e97a014c2d3e96f4f2f8cfd0be5 +Subproject commit b6439492df77064707f9a3085b7719e8abe8f3ef diff --git a/Assets/Scenes/Game/GameScene.unity b/Assets/Scenes/Game/GameScene.unity index 71990a3..2401f54 100644 --- a/Assets/Scenes/Game/GameScene.unity +++ b/Assets/Scenes/Game/GameScene.unity @@ -13,7 +13,7 @@ OcclusionCullingSettings: --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 - serializedVersion: 9 + serializedVersion: 10 m_Fog: 0 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogMode: 3 @@ -42,8 +42,8 @@ RenderSettings: --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 12 - m_GIWorkflowMode: 1 + serializedVersion: 13 + m_BakeOnSceneLoad: 0 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -66,9 +66,6 @@ LightmapSettings: m_LightmapParameters: {fileID: 0} m_LightmapsBakeMode: 1 m_TextureCompression: 1 - m_FinalGather: 0 - m_FinalGatherFiltering: 1 - m_FinalGatherRayCount: 256 m_ReflectionCompression: 2 m_MixedBakeMode: 2 m_BakeBackend: 1 @@ -96,7 +93,7 @@ LightmapSettings: m_ExportTrainingData: 0 m_TrainingDataDestination: TrainingData m_LightProbeSampleCountMultiplier: 4 - m_LightingDataAsset: {fileID: 0} + m_LightingDataAsset: {fileID: 20201, guid: 0000000000000000f000000000000000, type: 0} m_LightingSettings: {fileID: 0} --- !u!196 &4 NavMeshSettings: @@ -122,50 +119,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &776331052 -GameObject: - m_ObjectHideFlags: 3 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 776331053} - - component: {fileID: 776331054} - m_Layer: 0 - m_Name: cm - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &776331053 -Transform: - m_ObjectHideFlags: 3 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 776331052} - serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 1984701874} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &776331054 -MonoBehaviour: - m_ObjectHideFlags: 3 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 776331052} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &828905098 GameObject: m_ObjectHideFlags: 0 @@ -215,11 +168,9 @@ MonoBehaviour: m_EditorClassIdentifier: MainAudio: {fileID: 1869596524} MainCamera: {fileID: 1984701875} - MainObject: {fileID: 0} - IsHideTrackRender: 0 - CurrentProjectDefaultFileStyle: 0 + SongOffset: 0 + CurrentTime: 0 GlobalLight: {fileID: 1538927610} - DashLine: {fileID: 2100000, guid: 977d9c4664cbc254280b373cf83d901a, type: 2} IsEnableUpdate: 0 --- !u!1 &1538927608 GameObject: @@ -247,9 +198,8 @@ Light: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1538927608} m_Enabled: 1 - serializedVersion: 10 + serializedVersion: 11 m_Type: 1 - m_Shape: 0 m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} m_Intensity: 1 m_Range: 10 @@ -299,8 +249,12 @@ Light: m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} m_UseBoundingSphereOverride: 0 m_UseViewFrustumForShadowCasterCull: 1 + m_ForceVisible: 0 m_ShadowRadius: 0 m_ShadowAngle: 0 + m_LightUnit: 1 + m_LuxAtDistance: 1 + m_EnableSpotReflector: 1 --- !u!4 &1538927610 Transform: m_ObjectHideFlags: 0 @@ -328,17 +282,23 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 474bcb49853aa07438625e644c072ee6, type: 3} m_Name: m_EditorClassIdentifier: - m_Version: 3 m_UsePipelineSettings: 1 m_AdditionalLightsShadowResolutionTier: 2 - m_LightLayerMask: 1 - m_RenderingLayers: 1 m_CustomShadowLayers: 0 - m_ShadowLayerMask: 1 - m_ShadowRenderingLayers: 1 m_LightCookieSize: {x: 1, y: 1} m_LightCookieOffset: {x: 0, y: 0} m_SoftShadowQuality: 0 + m_RenderingLayersMask: + serializedVersion: 0 + m_Bits: 1 + m_ShadowRenderingLayersMask: + serializedVersion: 0 + m_Bits: 1 + m_Version: 4 + m_LightLayerMask: 1 + m_ShadowLayerMask: 1 + m_RenderingLayers: 1 + m_ShadowRenderingLayers: 1 --- !u!1 &1869596521 GameObject: m_ObjectHideFlags: 0 @@ -383,6 +343,7 @@ AudioSource: serializedVersion: 4 OutputAudioMixerGroup: {fileID: 24300002, guid: 8d8c64a4848e9d849a8e2eddaae1c049, type: 2} m_audioClip: {fileID: 0} + m_Resource: {fileID: 0} m_PlayOnAwake: 0 m_Volume: 1 m_Pitch: 1 @@ -793,8 +754,7 @@ Transform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 776331053} + m_Children: [] m_Father: {fileID: 828905099} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1984701875 @@ -806,36 +766,40 @@ MonoBehaviour: m_GameObject: {fileID: 1984701871} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 45e653bab7fb20e499bda25e1b646fea, type: 3} + m_Script: {fileID: 11500000, guid: f9dfa5b682dcd46bda6128250e975f58, type: 3} m_Name: - m_EditorClassIdentifier: - m_ExcludedPropertiesInInspector: - - m_Script - m_LockStageInInspector: - m_StreamingVersion: 20170927 - m_Priority: 10 - m_StandbyUpdate: 2 - m_LookAt: {fileID: 0} - m_Follow: {fileID: 0} - m_Lens: + m_EditorClassIdentifier: Unity.Cinemachine::Unity.Cinemachine.CinemachineCamera + Priority: + Enabled: 0 + m_Value: 0 + OutputChannel: 1 + StandbyUpdate: 2 + m_StreamingVersion: 0 + m_LegacyPriority: 0 + Target: + TrackingTarget: {fileID: 0} + LookAtTarget: {fileID: 0} + CustomLookAtTarget: 0 + Lens: FieldOfView: 40 OrthographicSize: 10 NearClipPlane: 0.1 FarClipPlane: 5000 Dutch: 0 ModeOverride: 0 - LensShift: {x: 0, y: 0} - GateFit: 2 - FocusDistance: 10 - m_SensorSize: {x: 1, y: 1} - m_Transitions: - m_BlendHint: 0 - m_InheritPosition: 0 - m_OnCameraLive: - m_PersistentCalls: - m_Calls: [] - m_LegacyBlendHint: 0 - m_ComponentOwner: {fileID: 776331053} + PhysicalProperties: + GateFit: 2 + SensorSize: {x: 21.946, y: 16.002} + LensShift: {x: 0, y: 0} + FocusDistance: 10 + Iso: 200 + ShutterSpeed: 0.005 + Aperture: 16 + BladeCount: 5 + Curvature: {x: 2, y: 11} + BarrelClipping: 0.25 + Anamorphism: 0 + BlendHint: 0 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Framework/CameraObject.cs b/Assets/Scripts/Framework/CameraObject.cs index 4bc3b6c..ccb9042 100644 --- a/Assets/Scripts/Framework/CameraObject.cs +++ b/Assets/Scripts/Framework/CameraObject.cs @@ -1,14 +1,27 @@ using System.Collections; +#if UNITY_6000_0_OR_NEWER +using Unity.Cinemachine; +#else using Cinemachine; +#endif using Convention.WindowsUI.Variant; using UnityEngine; namespace Demo.Game -{ +{ public class CameraObject : ScriptableObject { - private Camera MainCamera; - private CinemachineVirtualCamera VirtualCamera; + private Camera MainCamera => Camera.main; + private CinemachineCamera m_VirtualCamera; + private CinemachineCamera VirtualCamera + { + get + { + if (m_VirtualCamera == null) + m_VirtualCamera = GetComponent(); + return m_VirtualCamera; + } + } public static CameraObject MakeCameraObject() { @@ -19,21 +32,15 @@ namespace Demo.Game return null; } // Binding Output - FindObjectOfType().ModuleCamera = - mainCameraTransform.gameObject.GetComponent(); + FindFirstObjectByType().ModuleCamera = + mainCameraTransform.gameObject.GetComponent(); return mainCameraTransform.gameObject.AddComponent(); } - private void Start() - { - MainCamera = Camera.main; - VirtualCamera = GetComponent(); - } - public override IEnumerator UnloadScript() { yield return base.UnloadScript(); - FindObjectOfType().ModuleCamera = null; + FindFirstObjectByType().ModuleCamera = null; } /// @@ -117,10 +124,10 @@ namespace Demo.Game [Convention.RScript.Variable.Attr.Method] public void SetVirtualCameraFollowOffset(float x, float y, float z) { - var body = VirtualCamera.GetCinemachineComponent(); + var body = VirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineFollow; if (body != null) { - body.m_FollowOffset = new Vector3(x, y, z); + body.FollowOffset = new Vector3(x, y, z); } } @@ -130,17 +137,17 @@ namespace Demo.Game /// X轴阻尼 /// Y轴阻尼 /// Z轴阻尼 - [Convention.RScript.Variable.Attr.Method] - public void SetVirtualCameraFollowDamping(float x, float y, float z) - { - var body = VirtualCamera.GetCinemachineComponent(); - if (body != null) - { - body.m_XDamping = x; - body.m_YDamping = y; - body.m_ZDamping = z; - } - } + //[Convention.RScript.Variable.Attr.Method] + //public void SetVirtualCameraFollowDamping(float x, float y, float z) + //{ + // var body = VirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineFollow; + // if (body != null) + // { + // body.XDamping = x; + // body.YDamping = y; + // body.ZDamping = z; + // } + //} /// /// 设置虚拟相机观察阻尼 @@ -151,11 +158,10 @@ namespace Demo.Game [Convention.RScript.Variable.Attr.Method] public void SetVirtualCameraLookAtDamping(float x, float y, float z) { - var aim = VirtualCamera.GetCinemachineComponent(); + var aim = VirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineRotationComposer; if (aim != null) { - aim.m_HorizontalDamping = x; - aim.m_VerticalDamping = y; + aim.Damping = new(x, y); } } } diff --git a/Assets/Scripts/Framework/GameContent/GameController.cs b/Assets/Scripts/Framework/GameContent/GameController.cs index d659786..8436a55 100644 --- a/Assets/Scripts/Framework/GameContent/GameController.cs +++ b/Assets/Scripts/Framework/GameContent/GameController.cs @@ -1,9 +1,9 @@ -using Cinemachine; using Convention; using System; using System.Collections; using System.Collections.Generic; using System.IO; +using Unity.Cinemachine; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; @@ -13,7 +13,7 @@ namespace Demo.Game public partial class GameController : MonoBehaviour { [Resources, SerializeField] public BasicAudioSystem MainAudio; - [Resources, SerializeField] private CinemachineVirtualCamera MainCamera; + [Resources, SerializeField] private CinemachineVirtualCameraBase MainCamera; [Resources, SerializeField] public GlobalConfig MainConfig; [Content] private RootObject MainObject; diff --git a/Packages/manifest.json b/Packages/manifest.json index c6a7204..1d2d320 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,14 +1,14 @@ { "dependencies": { "com.unity.assetbundlebrowser": "https://github.com/Unity-Technologies/AssetBundles-Browser.git", - "com.unity.cinemachine": "2.10.4", + "com.unity.cinemachine": "3.1.5", "com.unity.cloud.gltfast": "6.14.0", "com.unity.collab-proxy": "2.9.3", "com.unity.feature.2d": "2.0.1", - "com.unity.ide.visualstudio": "2.0.23", + "com.unity.ide.visualstudio": "2.0.25", "com.unity.inputsystem": "1.14.2", "com.unity.learn.iet-framework": "5.0.2", - "com.unity.memoryprofiler": "1.1.8", + "com.unity.memoryprofiler": "1.1.9", "com.unity.multiplayer.center": "1.0.0", "com.unity.postprocessing": "3.5.1", "com.unity.recorder": "5.1.2", @@ -20,7 +20,7 @@ "com.unity.timeline": "1.8.9", "com.unity.ugui": "2.0.0", "com.unity.visualeffectgraph": "17.2.0", - "com.unity.visualscripting": "1.9.7", + "com.unity.visualscripting": "1.9.9", "com.unity.modules.accessibility": "1.0.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 012a25b..5dc5122 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -123,11 +123,12 @@ "url": "https://packages.unity.com" }, "com.unity.cinemachine": { - "version": "2.10.4", + "version": "3.1.5", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.31" + "com.unity.splines": "2.0.0", + "com.unity.modules.imgui": "1.0.0" }, "url": "https://packages.unity.com" }, @@ -193,11 +194,11 @@ } }, "com.unity.ide.visualstudio": { - "version": "2.0.23", + "version": "2.0.25", "depth": 0, "source": "registry", "dependencies": { - "com.unity.test-framework": "1.1.9" + "com.unity.test-framework": "1.1.31" }, "url": "https://packages.unity.com" }, @@ -228,7 +229,7 @@ "url": "https://packages.unity.com" }, "com.unity.memoryprofiler": { - "version": "1.1.8", + "version": "1.1.9", "depth": 0, "source": "registry", "dependencies": { @@ -420,7 +421,7 @@ } }, "com.unity.visualscripting": { - "version": "1.9.7", + "version": "1.9.9", "depth": 0, "source": "registry", "dependencies": {