This commit is contained in:
2025-05-11 00:46:26 +08:00
parent 366f9e95ec
commit 618f75f911
2404 changed files with 154475 additions and 924730 deletions

View File

@@ -0,0 +1,68 @@
using UnityEngine;
namespace ECM2.Examples
{
public sealed class SimpleCameraController : MonoBehaviour
{
#region PUBLIC FIELDS
[SerializeField]
private Transform _target;
[SerializeField]
private float _distanceToTarget = 10.0f;
[SerializeField]
private float _smoothTime = 0.1f;
#endregion
#region FIELDS
private Vector3 _followVelocity;
#endregion
#region PROPERTIES
public Transform target
{
get => _target;
set => _target = value;
}
public float distanceToTarget
{
get => _distanceToTarget;
set => _distanceToTarget = Mathf.Max(0.0f, value);
}
#endregion
#region MONOBEHAVIOUR
public void OnValidate()
{
distanceToTarget = _distanceToTarget;
}
public void Start()
{
if (_target == null)
return;
transform.position = target.position - transform.forward * distanceToTarget;
}
public void LateUpdate()
{
if (_target == null)
return;
Vector3 targetPosition = target.position - transform.forward * distanceToTarget;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref _followVelocity, _smoothTime);
}
#endregion
}
}