128 lines
3.2 KiB
C#
128 lines
3.2 KiB
C#
using DG.Tweening;
|
|
using DragonLi.Core;
|
|
using Mirror;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class EnergyPump : NetworkBehaviour
|
|
{
|
|
public SphereCollider sphere;
|
|
|
|
public int energyPumpTag;
|
|
|
|
public GameObject txt;
|
|
|
|
[NonSerialized]
|
|
public int HpIndex;
|
|
|
|
private Tween shakeTween;
|
|
[Header("Shake Settings")]
|
|
public float duration = 0.3f; // 抖动持续时间
|
|
public float strength = 0.2f; // 抖动强度
|
|
public int vibrato = 20; // 抖动的振动次数
|
|
|
|
private bool isShaking = false;
|
|
private Vector3 originalPos;
|
|
|
|
public void ColliderEnergyPump()
|
|
{
|
|
GameManager.Ins.EnergyPumpFillAmount += 0.2f;
|
|
EventDispatcher.TriggerEvent("ChangeEnergyPumpUI", GameManager.Ins.EnergyPumpFillAmount);
|
|
sphere.enabled = false;
|
|
transform.gameObject.SetActive(false);
|
|
NetworkServer.Destroy(transform.gameObject);
|
|
}
|
|
|
|
public void ShowLandMask()
|
|
{
|
|
switch (energyPumpTag)
|
|
{
|
|
case 1:
|
|
GameManager.Ins?.ShowLandmark(2, 3);
|
|
GameManager.Ins.HudMessage(1);
|
|
break;
|
|
case 2:
|
|
|
|
GameManager.Ins.HudMessage(2);
|
|
GameManager.Ins?.ShowLandmark(4, 5);
|
|
break;
|
|
case 3:
|
|
GameManager.Ins.ShowLandmark(7, 8);
|
|
GameObject rockfall = GameManager.Ins.GenerateRockfall(new Vector3(6f, 22.3f, 3.26f), new Vector3(-90, 0, 0));
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
NetworkServer.Destroy(rockfall);
|
|
}, 5.0f);
|
|
GameManager.Ins.HudMessage(4);
|
|
|
|
break;
|
|
case 4:
|
|
GameManager.Ins.ShowLandmark(9, 10);
|
|
GameManager.Ins.HudMessage(5);
|
|
break;
|
|
case 5:
|
|
GameManager.Ins.ShowLandmark(11, 12);
|
|
GameManager.Ins.HudMessage(6);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
public void Init(int energyPumpTag)
|
|
{
|
|
this.energyPumpTag = energyPumpTag;
|
|
originalPos = transform.localPosition;
|
|
HpIndex = 10;
|
|
CoroutineTaskManager.Instance.WaitSecondTodo(() =>
|
|
{
|
|
Over();
|
|
}, 10f);
|
|
}
|
|
|
|
public void Over()
|
|
{
|
|
|
|
AudioManager.Ins?.SoundPlayOneShot("TouchEnergyPump", false);
|
|
ShowLandMask();
|
|
EventDispatcher.TriggerEvent("NextTrriger");
|
|
ColliderEnergyPump();
|
|
Debug.Log("过关");
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
txt.transform.parent.GetComponent<Transform>().LookAt(GameInit.Ins.MRCamera.transform);
|
|
}
|
|
|
|
public void ApplyDamage(float value, object info, Transform _sender)
|
|
{
|
|
HpIndex--;
|
|
if (HpIndex <= 0)
|
|
{
|
|
Over();
|
|
return;
|
|
}
|
|
|
|
Shake();
|
|
}
|
|
|
|
public void Shake()
|
|
{
|
|
if (isShaking) return;
|
|
|
|
isShaking = true;
|
|
|
|
shakeTween = transform.DOShakePosition(duration, strength, vibrato)
|
|
.OnComplete(() =>
|
|
{
|
|
transform.localPosition = originalPos;
|
|
isShaking = false;
|
|
});
|
|
}
|
|
|
|
public float Health { get; set; }
|
|
|
|
}
|