226 lines
6.8 KiB
C#
226 lines
6.8 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using DG.Tweening;
|
||
using DragonLi.Core;
|
||
using LitJson;
|
||
using Spine.Unity;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using XUI;
|
||
using Random = UnityEngine.Random;
|
||
using Common;
|
||
using System.Collections;
|
||
using SpineAnimation = Common.SpineAnimation;
|
||
|
||
public class HUDPanel : UIBehaviour
|
||
{
|
||
/// <summary>
|
||
/// 倒计时文本
|
||
/// </summary>
|
||
public TextMeshProUGUI LessTimeText;
|
||
|
||
[Header("血液特效")]
|
||
public GameObject bloodEffectPrefab; // 血液特效预制体
|
||
public float bloodEffectDuration = 2f; // 血液特效持续时间
|
||
|
||
[Header("计时器")]
|
||
public GameObject timerPanel; // 计时器面板
|
||
public TextMeshProUGUI timerText; // 计时器文本
|
||
|
||
[Header("幽灵UI")]
|
||
public GameObject ghostUIPrefab; // 幽灵UI预制体
|
||
public float ghostUIDuration = 3f; // 幽灵UI显示时间
|
||
public Transform ghostUIContainer; // 幽灵UI容器
|
||
|
||
[Header("幽灵UI - Spine动画")]
|
||
public SkeletonGraphic ghostSpineGraphic; // 幽灵UI的Spine组件
|
||
public string ghostSpineAnimationName = "fly"; // Spine动画名称
|
||
|
||
// 用于存储实例化幽灵UI的Spine动画引用
|
||
//private Dictionary<GameObject, SpineAnimation> _ghostSpineAnimations = new Dictionary<GameObject, SpineAnimation>();
|
||
|
||
public static void Show()
|
||
{
|
||
OverlayUIManager.Ins.Cover("UI/HUDPanel", false);
|
||
}
|
||
|
||
public override void OnUIShow(params object[] args)
|
||
{
|
||
base.OnUIShow(args);
|
||
GameManager.Ins.playerHUD = this;
|
||
bloodEffectPrefab.SetActive(false);
|
||
ghostUIPrefab.SetActive(false);
|
||
}
|
||
void Update()
|
||
{
|
||
}
|
||
|
||
#region 森林猎杀事件
|
||
|
||
/// <summary>
|
||
/// 显示血液特效(野猪冲刺攻击时)
|
||
/// </summary>
|
||
public void ShowBloodEffect()
|
||
{
|
||
if (bloodEffectPrefab != null)
|
||
{
|
||
var effect = Instantiate(bloodEffectPrefab, transform);
|
||
effect.SetActive(true);
|
||
|
||
// 设置随机位置
|
||
var rectTransform = effect.GetComponent<RectTransform>();
|
||
if (rectTransform != null)
|
||
{
|
||
int randomX = Random.Range(-200, 200);
|
||
int randomY = Random.Range(-100, 100);
|
||
rectTransform.anchoredPosition = new Vector2(randomX, randomY);
|
||
}
|
||
|
||
// 自动淡出并销毁
|
||
var canvasGroup = effect.GetComponent<CanvasGroup>();
|
||
if (canvasGroup == null)
|
||
canvasGroup = effect.AddComponent<CanvasGroup>();
|
||
|
||
canvasGroup.DOFade(0, bloodEffectDuration).OnComplete(() =>
|
||
{
|
||
Destroy(effect);
|
||
});
|
||
}
|
||
else
|
||
{
|
||
// 如果没有预制体,使用简单的红色闪烁效果
|
||
ShowSimpleBloodEffect();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示简单的血液效果(屏幕边缘红色闪烁)
|
||
/// </summary>
|
||
private void ShowSimpleBloodEffect()
|
||
{
|
||
// 创建一个全屏红色遮罩
|
||
GameObject bloodOverlay = new GameObject("BloodOverlay");
|
||
bloodOverlay.transform.SetParent(transform);
|
||
bloodOverlay.transform.SetAsLastSibling();
|
||
|
||
var image = bloodOverlay.AddComponent<Image>();
|
||
image.color = new Color(1, 0, 0, 0.3f); // 半透明红色
|
||
|
||
var rectTransform = bloodOverlay.GetComponent<RectTransform>();
|
||
rectTransform.anchorMin = Vector2.zero;
|
||
rectTransform.anchorMax = Vector2.one;
|
||
rectTransform.sizeDelta = Vector2.zero;
|
||
rectTransform.anchoredPosition = Vector2.zero;
|
||
|
||
// 淡出动画
|
||
var canvasGroup = bloodOverlay.AddComponent<CanvasGroup>();
|
||
canvasGroup.alpha = 1f;
|
||
canvasGroup.DOFade(0, bloodEffectDuration).OnComplete(() =>
|
||
{
|
||
Destroy(bloodOverlay);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新计时器显示
|
||
/// </summary>
|
||
public void UpdateTimer(float remainingTime)
|
||
{
|
||
if (timerPanel != null)
|
||
{
|
||
timerPanel.SetActive(remainingTime > 0);
|
||
}
|
||
|
||
if (timerText != null)
|
||
{
|
||
int minutes = Mathf.FloorToInt(remainingTime / 60f);
|
||
int seconds = Mathf.FloorToInt(remainingTime % 60f);
|
||
timerText.text = string.Format("{0:00}:{1:00}", minutes, seconds);
|
||
|
||
// 时间紧迫时变红
|
||
if (remainingTime <= 30f)
|
||
{
|
||
timerText.color = Color.red;
|
||
}
|
||
else
|
||
{
|
||
timerText.color = Color.white;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示计时器
|
||
/// </summary>
|
||
public void ShowTimer()
|
||
{
|
||
if (timerPanel != null)
|
||
timerPanel.SetActive(true);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隐藏计时器
|
||
/// </summary>
|
||
public void HideTimer()
|
||
{
|
||
if (timerPanel != null)
|
||
timerPanel.SetActive(false);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 梦境毒苹果事件
|
||
|
||
/// <summary>
|
||
/// 显示幽灵 UI(幽灵碰到玩家时调用)
|
||
/// </summary>
|
||
public void ShowGhostUI()
|
||
{
|
||
if (ghostUIPrefab != null && ghostUIContainer != null)
|
||
{
|
||
// 实例化幽灵 UI
|
||
GameObject ghostInstance = Instantiate(ghostUIPrefab, ghostUIContainer);
|
||
ghostInstance.SetActive(true);
|
||
|
||
var rectTransform = ghostInstance.GetComponent<RectTransform>();
|
||
if (rectTransform != null)
|
||
{
|
||
// 设置初始位置 x=752, y=0
|
||
rectTransform.anchoredPosition = new Vector2(752, 0);
|
||
|
||
// 移动时间
|
||
float moveDuration = 4f;
|
||
|
||
// 创建动画序列
|
||
Sequence sequence = DOTween.Sequence();
|
||
|
||
// 从右向左移动 (752 -> -967),同时上下浮动
|
||
sequence.Join(rectTransform.DOAnchorPosX(-967, moveDuration));
|
||
sequence.Join(rectTransform.DOAnchorPosY(50, moveDuration / 4).SetEase(Ease.InOutSine).SetLoops(4, LoopType.Yoyo));
|
||
|
||
// 移动完成后恢复初始位置并隐藏
|
||
sequence.AppendCallback(() =>
|
||
{
|
||
rectTransform.anchoredPosition = new Vector2(752, 0);
|
||
ghostInstance.SetActive(false);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 显示多个幽灵UI
|
||
/// </summary>
|
||
public void ShowMultipleGhostUI(int count)
|
||
{
|
||
for (int i = 0; i < count; i++)
|
||
{
|
||
// 延迟显示,形成依次出现的效果
|
||
DOVirtual.DelayedCall(i * 0.2f, () => ShowGhostUI());
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|