CameraObject
This commit is contained in:
@@ -9,6 +9,7 @@ using UnityEngine;
|
||||
using Demo.Game.Attr;
|
||||
using System.IO;
|
||||
using Convention;
|
||||
using Demo.Game.ConfigType;
|
||||
|
||||
namespace Demo.Game
|
||||
{
|
||||
@@ -62,6 +63,10 @@ namespace Demo.Game
|
||||
[Scriptable(nameof(MakeCameraObject))]
|
||||
public class CameraObject : ScriptableObject
|
||||
{
|
||||
protected override ScriptLoadableConfig MakeConfig()
|
||||
{
|
||||
return new CameraObjectConfig();
|
||||
}
|
||||
private Camera MainCamera => Camera.main;
|
||||
private CinemachineCamera m_VirtualCamera;
|
||||
private CinemachineCamera VirtualCamera
|
||||
@@ -100,7 +105,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetOrthographic(bool orthographic)
|
||||
{
|
||||
MainCamera.orthographic = orthographic;
|
||||
GetConfig<CameraObjectConfig>().orthographic = MainCamera.orthographic = orthographic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -109,7 +114,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetFieldOfView(float fieldOfView)
|
||||
{
|
||||
MainCamera.fieldOfView = fieldOfView;
|
||||
GetConfig<CameraObjectConfig>().fieldOfView = MainCamera.fieldOfView = fieldOfView;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,7 +123,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetOrthographicSize(float orthographicSize)
|
||||
{
|
||||
MainCamera.orthographicSize = orthographicSize;
|
||||
GetConfig<CameraObjectConfig>().orthographicSize = MainCamera.orthographicSize = orthographicSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -127,7 +132,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetNearClipPlane(float nearClipPlane)
|
||||
{
|
||||
MainCamera.nearClipPlane = nearClipPlane;
|
||||
GetConfig<CameraObjectConfig>().nearClipPlane = MainCamera.nearClipPlane = nearClipPlane;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -136,7 +141,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetFarClipPlane(float farClipPlane)
|
||||
{
|
||||
MainCamera.farClipPlane = farClipPlane;
|
||||
GetConfig<CameraObjectConfig>().farClipPlane = MainCamera.farClipPlane = farClipPlane;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,7 +150,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetDepth(float depth)
|
||||
{
|
||||
MainCamera.depth = depth;
|
||||
GetConfig<CameraObjectConfig>().depth = MainCamera.depth = depth;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,6 +159,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetVirtualCameraFollow(ScriptableObject target)
|
||||
{
|
||||
GetConfig<CameraObjectConfig>().VirtualCameraFollow = GetRoot().FindIndex(target);
|
||||
VirtualCamera.Follow = target.transform;
|
||||
}
|
||||
|
||||
@@ -163,6 +169,7 @@ namespace Demo.Game
|
||||
[Convention.RScript.Variable.Attr.Method]
|
||||
public void SetVirtualCameraLookAt(ScriptableObject target)
|
||||
{
|
||||
GetConfig<CameraObjectConfig>().VirtualCameraLookAt = GetRoot().FindIndex(target);
|
||||
VirtualCamera.LookAt = target.transform;
|
||||
}
|
||||
|
||||
@@ -178,28 +185,11 @@ namespace Demo.Game
|
||||
var body = VirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineFollow;
|
||||
if (body != null)
|
||||
{
|
||||
GetConfig<CameraObjectConfig>().VirtualCameraFollowOffset = new Vector3(x, y, z);
|
||||
body.FollowOffset = new Vector3(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置虚拟相机跟随阻尼
|
||||
/// </summary>
|
||||
/// <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(CinemachineCore.Stage.Body) as CinemachineFollow;
|
||||
// if (body != null)
|
||||
// {
|
||||
// body.XDamping = x;
|
||||
// body.YDamping = y;
|
||||
// body.ZDamping = z;
|
||||
// }
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 设置虚拟相机观察阻尼
|
||||
/// </summary>
|
||||
@@ -212,6 +202,7 @@ namespace Demo.Game
|
||||
var aim = VirtualCamera.GetCinemachineComponent(CinemachineCore.Stage.Body) as CinemachineRotationComposer;
|
||||
if (aim != null)
|
||||
{
|
||||
GetConfig<CameraObjectConfig>().VirtualCameraLookAtDamping = new Vector3(x, y, z);
|
||||
aim.Damping = new(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user