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