115 lines
3.7 KiB
C#
115 lines
3.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using DG.Tweening; // 引入 DoTween 命名空间
|
|
using Yarn.Unity;
|
|
using AibisDream;
|
|
using AibisDream.Kit;
|
|
using AibisDream.UI;
|
|
|
|
public class LineInteraction : MonoBehaviour
|
|
{
|
|
public GameObject actorGroup; // 关联的Playable Director
|
|
public PlayableDirector timelineDirector; // 关联的Playable Director
|
|
public SpriteRenderer scissorSpriteRenderer; // 剪刀的SpriteRenderer
|
|
public SpriteRenderer cutLineSpriteRenderer; // 剪刀的SpriteRenderer
|
|
public Sprite closedScissorSprite; // 剪刀合上的Sprite
|
|
public Sprite openScissorSprite; // 剪刀张开的Sprite
|
|
public float openYMin; // Y轴范围的最小值
|
|
public float openYMax; // Y轴范围的最大值
|
|
public float fadeDuration = 0.5f; // 淡入淡出持续时间
|
|
|
|
private bool isActive = false;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
// 初始状态不激活
|
|
actorGroup.SetActive(false);
|
|
scissorSpriteRenderer.transform.localPosition =
|
|
new Vector3(12f, openYMin - 3, scissorSpriteRenderer.transform.position.z);
|
|
cutLineSpriteRenderer.enabled = false;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (!isActive) return;
|
|
|
|
// 获取鼠标在世界坐标中的位置
|
|
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
|
|
Camera.main.nearClipPlane));
|
|
|
|
// 更新剪刀的Y轴位置以跟随鼠标
|
|
scissorSpriteRenderer.transform.localPosition = new Vector3(scissorSpriteRenderer.transform.localPosition.x,
|
|
mousePosition.y, scissorSpriteRenderer.transform.localPosition.z);
|
|
|
|
// 检查Y轴位置并更换Sprite
|
|
if (mousePosition.y >= openYMin && mousePosition.y <= openYMax)
|
|
{
|
|
scissorSpriteRenderer.sprite = openScissorSprite;
|
|
cutLineSpriteRenderer.enabled = true;
|
|
// 检查玩家交互(例如按下鼠标左键);剪一次后立即禁用,避免重复剪线/音效
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
isActive = false;
|
|
ContinueTimeline();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
scissorSpriteRenderer.sprite = closedScissorSprite;
|
|
cutLineSpriteRenderer.enabled = false;
|
|
}
|
|
}
|
|
|
|
[YarnCommand("play_timeline_cutline")]
|
|
public void PlayTimeline()
|
|
{
|
|
timelineDirector.Play();
|
|
}
|
|
|
|
public void FinishCutLine()
|
|
{
|
|
StartCoroutine(FinishSequence());
|
|
}
|
|
|
|
private IEnumerator FinishSequence()
|
|
{
|
|
// Timeline 末尾 Black Fade 已盖黑:交接给 UI 黑幕,避免销毁 Cutline 时露头
|
|
var panel = UIManager.Instance.GetPanel<ScreenTransitionPanel>();
|
|
yield return panel.FadeInAsync(0f);
|
|
|
|
Destroy(gameObject);
|
|
|
|
// CutLine 节点内 fade_out 揭开头部
|
|
DialogController.Instance.StartDialogNode("OnCutLineComplete");
|
|
}
|
|
|
|
public void ActivateInteraction()
|
|
{
|
|
StartCoroutine(InteractionSequence());
|
|
}
|
|
|
|
private IEnumerator InteractionSequence()
|
|
{
|
|
// 开始阶段:淡入
|
|
scissorSpriteRenderer.transform.DOLocalMoveX(7.39f, fadeDuration);
|
|
cutLineSpriteRenderer.DOFade(1f, fadeDuration);
|
|
AudioManager.Instance.PlaySfx("event:/Scriptal/scissor_in");
|
|
yield return new WaitForSeconds(fadeDuration);
|
|
|
|
// 执行阶段:激活交互逻辑
|
|
isActive = true;
|
|
|
|
// 等待交互完成
|
|
yield return null;
|
|
}
|
|
|
|
void ContinueTimeline()
|
|
{
|
|
AudioManager.Instance.PlaySfx("event:/ActionFB/wire_cut");
|
|
timelineDirector.Play();
|
|
}
|
|
} |