72 lines
2.2 KiB
C#
72 lines
2.2 KiB
C#
using System.Collections;
|
|
using AibisDream.Kit;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.Framework
|
|
{
|
|
public class CameraKit : SingletonBase<CameraKit>
|
|
{
|
|
private readonly Camera _mainCamera = Camera.main;
|
|
|
|
private Vector3 _initPos;
|
|
private float _initOrthographicSize;
|
|
|
|
private CameraKit() {}
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
// 无需初始化
|
|
_initPos = _mainCamera.transform.position;
|
|
_initOrthographicSize = _mainCamera.orthographicSize;
|
|
}
|
|
|
|
public void ResetCamara()
|
|
{
|
|
_mainCamera.transform.position = _initPos;
|
|
_mainCamera.orthographicSize = _initOrthographicSize;
|
|
}
|
|
|
|
public Tween TransCamera(Vector3 targetPos, float targetOrthographicSize, float duration)
|
|
{
|
|
var sq = DOTween.Sequence();
|
|
// 移动
|
|
sq.Join(_mainCamera.transform.DOMove(targetPos, duration));
|
|
// 缩放
|
|
sq.Join(_mainCamera.DOOrthoSize(targetOrthographicSize, duration));
|
|
|
|
return sq;
|
|
}
|
|
|
|
public Tween ReturnInitCamera(float duration)
|
|
{
|
|
return TransCamera(_initPos, _initOrthographicSize, duration);
|
|
}
|
|
|
|
public Tween TransCamera(Vector3 targetPos, float duration)
|
|
{
|
|
return _mainCamera.transform.DOMove(targetPos, duration);
|
|
}
|
|
|
|
public IEnumerator TransCameraAsync(Vector3 targetPos, float duration)
|
|
{
|
|
var targetOrthographicSize = _mainCamera.orthographicSize;
|
|
yield return TransCameraAsync(targetPos, targetOrthographicSize, duration);
|
|
}
|
|
|
|
public IEnumerator TransCameraAsync(Vector3 targetPos, float targetOrthographicSize, float duration)
|
|
{
|
|
var sq = TransCamera(targetPos, targetOrthographicSize, duration);
|
|
// 协程
|
|
while (sq.active && !sq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public IEnumerator ReturnInitCameraAsync(float duration)
|
|
{
|
|
return TransCameraAsync(_initPos, _initOrthographicSize, duration);
|
|
}
|
|
}
|
|
} |