Cinemachine版本兼容
This commit is contained in:
@@ -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<CinemachineCamera>();
|
||||
return m_VirtualCamera;
|
||||
}
|
||||
}
|
||||
|
||||
public static CameraObject MakeCameraObject()
|
||||
{
|
||||
@@ -19,21 +32,15 @@ namespace Demo.Game
|
||||
return null;
|
||||
}
|
||||
// Binding Output
|
||||
FindObjectOfType<SceneGameWindow>().ModuleCamera =
|
||||
mainCameraTransform.gameObject.GetComponent<CinemachineVirtualCameraBase>();
|
||||
FindFirstObjectByType<SceneGameWindow>().ModuleCamera =
|
||||
mainCameraTransform.gameObject.GetComponent<CinemachineCamera>();
|
||||
return mainCameraTransform.gameObject.AddComponent<CameraObject>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
MainCamera = Camera.main;
|
||||
VirtualCamera = GetComponent<CinemachineVirtualCamera>();
|
||||
}
|
||||
|
||||
public override IEnumerator UnloadScript()
|
||||
{
|
||||
yield return base.UnloadScript();
|
||||
FindObjectOfType<SceneGameWindow>().ModuleCamera = null;
|
||||
FindFirstObjectByType<SceneGameWindow>().ModuleCamera = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -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<Cinemachine.CinemachineTransposer>();
|
||||
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
|
||||
/// <param name="x">X轴阻尼</param>
|
||||
/// <param name="y">Y轴阻尼</param>
|
||||
/// <param name="z">Z轴阻尼</param>
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetVirtualCameraFollowDamping(float x, float y, float z)
|
||||
{
|
||||
var body = VirtualCamera.GetCinemachineComponent<Cinemachine.CinemachineTransposer>();
|
||||
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;
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 设置虚拟相机观察阻尼
|
||||
@@ -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<Cinemachine.CinemachineComposer>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user