提交
This commit is contained in:
@@ -5,6 +5,8 @@ using Cinemachine;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using UnityEditor.Localization.Plugins.XLIFF.V12;
|
||||
using DG.Tweening;
|
||||
using System.Collections;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -12,10 +14,20 @@ namespace AibisDream
|
||||
{
|
||||
[Header("切割组件")]
|
||||
public GameObject gearFollowerPrefab;
|
||||
public GameObject entrancePanelPrefab; // 入场面板预制体
|
||||
public float entranceDuration = 1.5f; // 入场动画时长
|
||||
public float exitDuration = 1.5f; // 退场动画时长
|
||||
public float panelOffsetY = 2f; // 面板在相机视野下方的偏移量
|
||||
|
||||
private GearFollower gearFollower;
|
||||
private bool isCuttingMode = false;
|
||||
private bool isEntranceComplete = false; // 入场是否完成
|
||||
private bool isGearActive = false; // 标记gear是否已激活
|
||||
private BodyModule _targetModule;
|
||||
private SpriteRenderer _targetSpriteRenderer;
|
||||
private GameObject entrancePanel; // 入场面板实例
|
||||
private Camera _mainCamera;
|
||||
private CinemachineVirtualCamera _currentVirtualCamera;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -33,23 +45,63 @@ namespace AibisDream
|
||||
CameraKit.Instance.RegisterCamera(CameraEnum.CutEmoDeep, virtualCam4);
|
||||
CameraKit.Instance.RegisterCamera(CameraEnum.CutMemoryDeep, virtualCam5);
|
||||
CameraKit.Instance.RegisterCamera(CameraEnum.CutLogicDeep, virtualCam6);
|
||||
|
||||
_mainCamera = Camera.main;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isCuttingMode && gearFollower != null)
|
||||
if (isCuttingMode && !isGearActive && gearFollower != null)
|
||||
{
|
||||
// 检测点击
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Ray ray = _mainCamera.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction);
|
||||
|
||||
if (hit.collider != null && hit.collider.gameObject.GetComponent<GearFollower>() != null)
|
||||
{
|
||||
gearFollower=hit.collider.gameObject.GetComponent<GearFollower>();
|
||||
ActivateGear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (isCuttingMode && isGearActive && gearFollower != null)
|
||||
{
|
||||
gearFollower.GearUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public void StartCutting(BodyModule targetModule)
|
||||
private void ActivateGear()
|
||||
{
|
||||
isGearActive = true;
|
||||
if (gearFollower != null)
|
||||
{
|
||||
// 解除父子关系
|
||||
gearFollower.transform.SetParent(null);
|
||||
gearFollower.Init(_targetSpriteRenderer);
|
||||
}
|
||||
|
||||
// 面板退场
|
||||
if (entrancePanel != null)
|
||||
{
|
||||
Vector3 startPosition = GetPanelSpawnPosition();
|
||||
entrancePanel.transform.DOMove(startPosition, exitDuration)
|
||||
.SetEase(Ease.InBack)
|
||||
.OnComplete(() => {
|
||||
Destroy(entrancePanel);
|
||||
entrancePanel = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator StartCutting(BodyModule targetModule)
|
||||
{
|
||||
// 检查参数
|
||||
if (targetModule == null)
|
||||
{
|
||||
Debug.LogError("targetModule 为空");
|
||||
return;
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 保存目标模块
|
||||
@@ -60,7 +112,7 @@ namespace AibisDream
|
||||
if (_targetSpriteRenderer == null)
|
||||
{
|
||||
Debug.LogError("targetSprite 为空");
|
||||
return;
|
||||
yield break;
|
||||
}
|
||||
|
||||
// 停止之前的切割
|
||||
@@ -68,21 +120,94 @@ namespace AibisDream
|
||||
|
||||
// 设置切割模式
|
||||
isCuttingMode = true;
|
||||
isEntranceComplete = false;
|
||||
|
||||
// 创建GearFollower
|
||||
Vector3 SpawnPosition = new Vector3(Screen.width / 2f, Screen.height / 4f, 0);
|
||||
GameObject gearFollowerObj = Instantiate(gearFollowerPrefab, SpawnPosition, Quaternion.identity);
|
||||
gearFollower = gearFollowerObj.GetComponent<GearFollower>();
|
||||
gearFollower.Init(_targetSpriteRenderer);
|
||||
// 创建入场面板
|
||||
CreateEntrancePanel();
|
||||
|
||||
// 等待入场动画完成
|
||||
yield return new WaitUntil(() => isEntranceComplete);
|
||||
}
|
||||
|
||||
private Vector3 GetPanelSpawnPosition()
|
||||
{
|
||||
if (_mainCamera == null)
|
||||
{
|
||||
_mainCamera = Camera.main;
|
||||
}
|
||||
|
||||
|
||||
// 获取相机的位置和旋转
|
||||
Vector3 cameraPosition = _mainCamera.transform.position;
|
||||
Quaternion cameraRotation = _mainCamera.transform.rotation;
|
||||
|
||||
// 计算相机视野下方的位置
|
||||
Vector3 forward = cameraRotation * Vector3.forward;
|
||||
Vector3 right = cameraRotation * Vector3.right;
|
||||
Vector3 up = cameraRotation * Vector3.up;
|
||||
|
||||
// 计算相机视野的底部中心点
|
||||
float height = 2f * Mathf.Tan(_mainCamera.fieldOfView * 0.5f * Mathf.Deg2Rad) * _mainCamera.nearClipPlane;
|
||||
float width = height * _mainCamera.aspect;
|
||||
|
||||
// 计算面板的起始位置(在相机视野下方)
|
||||
Vector3 bottomCenter = cameraPosition + forward * _mainCamera.nearClipPlane - up * (height * 0.5f + panelOffsetY);
|
||||
|
||||
return bottomCenter;
|
||||
}
|
||||
|
||||
private void CreateEntrancePanel()
|
||||
{
|
||||
// 获取基于当前相机位置的生成位置
|
||||
Vector3 startPosition = GetPanelSpawnPosition();
|
||||
if (startPosition == Vector3.zero)
|
||||
{
|
||||
Debug.LogError("无法获取面板生成位置");
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建入场面板,保持原始旋转
|
||||
entrancePanel = Instantiate(entrancePanelPrefab, startPosition, Quaternion.Euler(0,0,-90));
|
||||
|
||||
// 获取GearFollower组件(作为子物体)
|
||||
gearFollower = entrancePanel.GetComponentInChildren<GearFollower>();
|
||||
if (gearFollower == null)
|
||||
{
|
||||
Debug.LogError("入场面板预制体中没有找到GearFollower组件");
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算相机视野高度
|
||||
float height = 2f * Mathf.Tan(_mainCamera.fieldOfView * 0.5f * Mathf.Deg2Rad) * _mainCamera.nearClipPlane;
|
||||
|
||||
// 计算目标位置(相机视野中心偏下)
|
||||
Vector3 targetPosition = startPosition + _mainCamera.transform.up * 3.5f;
|
||||
|
||||
// 执行入场动画
|
||||
entrancePanel.transform.DOMove(targetPosition, entranceDuration)
|
||||
.SetEase(Ease.OutBack)
|
||||
.OnComplete(() => {
|
||||
isEntranceComplete = true;
|
||||
});
|
||||
}
|
||||
|
||||
public void OnCutComplete()
|
||||
{
|
||||
isCuttingMode = false;
|
||||
isEntranceComplete = false;
|
||||
isGearActive = false;
|
||||
|
||||
if (gearFollower != null)
|
||||
{
|
||||
gearFollower.FinishCutting();
|
||||
}
|
||||
|
||||
// 如果面板还存在,删除它
|
||||
if (entrancePanel != null)
|
||||
{
|
||||
Destroy(entrancePanel);
|
||||
entrancePanel = null;
|
||||
}
|
||||
}
|
||||
public void UpdateModule()
|
||||
{
|
||||
@@ -91,11 +216,62 @@ namespace AibisDream
|
||||
_targetModule.OnCuttingDown();
|
||||
}
|
||||
}
|
||||
public void SetCutTextVisible(bool visible)
|
||||
{
|
||||
if (_targetModule != null)
|
||||
{
|
||||
_targetModule.SetCutTextVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCutProgress(float progress)
|
||||
{
|
||||
if (_targetModule != null)
|
||||
{
|
||||
_targetModule.UpdateCutProgress(progress);
|
||||
}
|
||||
}
|
||||
public void StartCutTextFlicker()
|
||||
{
|
||||
if (_targetModule != null)
|
||||
{
|
||||
_targetModule.StartCutTextFlicker();
|
||||
}
|
||||
}
|
||||
public void StopCutTextFlicker()
|
||||
{
|
||||
if (_targetModule != null)
|
||||
{
|
||||
_targetModule.StopCutTextFlicker();
|
||||
}
|
||||
}
|
||||
|
||||
public void StopCutting()
|
||||
{
|
||||
isCuttingMode = false;
|
||||
if (gearFollower != null)
|
||||
isEntranceComplete = false;
|
||||
isGearActive = false;
|
||||
|
||||
if (_targetModule != null)
|
||||
{
|
||||
_targetModule.StopCutTextFlicker();
|
||||
}
|
||||
|
||||
if (entrancePanel != null)
|
||||
{
|
||||
// 获取当前相机位置
|
||||
Vector3 startPosition = GetPanelSpawnPosition();
|
||||
|
||||
// 执行退场动画
|
||||
entrancePanel.transform.DOMove(startPosition, exitDuration)
|
||||
.SetEase(Ease.InBack)
|
||||
.OnComplete(() => {
|
||||
Destroy(entrancePanel);
|
||||
entrancePanel = null;
|
||||
gearFollower = null;
|
||||
});
|
||||
}
|
||||
else if (gearFollower != null)
|
||||
{
|
||||
Destroy(gearFollower.gameObject);
|
||||
gearFollower = null;
|
||||
|
||||
Reference in New Issue
Block a user