96 lines
2.7 KiB
C#
96 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using DragonLi.Core;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public enum TaskBoxType
|
|
{
|
|
TaskStartBox,
|
|
TaskEndBox,
|
|
}
|
|
|
|
public class TaskBox : MonoBehaviour
|
|
{
|
|
public Animator boxAnimator;
|
|
|
|
public GameObject[] effectObjs;
|
|
|
|
[Header("References")]
|
|
public ParticleSystem explosionEffect; // 宝箱爆炸烟雾粒子
|
|
|
|
public int id;
|
|
|
|
public void Start()
|
|
{
|
|
foreach (var obj in effectObjs)
|
|
{
|
|
obj.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void Init(int curId,TaskBoxType boxType)
|
|
{
|
|
id = curId;
|
|
if (boxType == TaskBoxType.TaskStartBox)
|
|
{
|
|
effectObjs[id].SetActive(true);
|
|
StartCoroutine(ShowBox());
|
|
}
|
|
else if (boxType == TaskBoxType.TaskEndBox)
|
|
{
|
|
transform.localScale = Vector3.one*1.5f;
|
|
transform.eulerAngles = new Vector3(0, 180, 0);
|
|
}
|
|
|
|
}
|
|
|
|
IEnumerator ShowBox()
|
|
{
|
|
transform.DOMoveY(0, 1f).OnComplete(() =>
|
|
{
|
|
GameManager.Ins.PlaySound3DRPC("1.27",transform);
|
|
});
|
|
yield return new WaitForSeconds(1);
|
|
float duration = 0.6f; // 总持续时间
|
|
float shrinkScale = 0.7f; // 最小缩放比例
|
|
float expandScale = 1.2f; // 最大缩放比例
|
|
transform.localScale = Vector3.one; // 确保初始是原始大小
|
|
Sequence seq = DOTween.Sequence();
|
|
seq.Append(transform.DOScale(shrinkScale, duration * 0.3f).SetEase(Ease.InQuad)); // 缩小
|
|
seq.Append(transform.DOScale(expandScale, duration * 0.4f).SetEase(Ease.OutBack)); // 放大到略大于原始
|
|
seq.Append(transform.DOScale(1f, duration * 0.3f).SetEase(Ease.OutElastic)); // 回弹到正常大小
|
|
yield return new WaitForSeconds(duration);
|
|
GameManager.Ins.PlaySound3DRPC("1.28",transform);
|
|
boxAnimator.SetBool("isOpen",true);
|
|
yield return new WaitForSeconds(2f);
|
|
StartCoroutine(ExplosionRoutine());
|
|
}
|
|
|
|
private IEnumerator ExplosionRoutine()
|
|
{
|
|
explosionEffect.gameObject.SetActive(true);
|
|
// 1. 播放爆炸烟雾
|
|
if (explosionEffect != null)
|
|
explosionEffect.Play();
|
|
|
|
// 2. 隐藏宝箱模型
|
|
boxAnimator.gameObject.SetActive(false);
|
|
|
|
// 3. 等待烟雾效果(可根据粒子时长调整)
|
|
float waitTime = explosionEffect != null ? explosionEffect.main.duration : 0.5f;
|
|
yield return new WaitForSeconds(0.1f);
|
|
switch (GameManager.Ins.taskManager.curTaskId)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
}
|
|
private GameObject _gemKey;
|
|
}
|