171 lines
4.3 KiB
C#
171 lines
4.3 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using DG.Tweening;
|
||
using DragonLi.Core;
|
||
using UnityEngine;
|
||
|
||
public class OctopusBoss : Enemy
|
||
{
|
||
public Tentacle[] tentacles;
|
||
[NonSerialized]
|
||
public Transform[] teleportPoints;
|
||
|
||
public Transform sprayRoot; // 喷射旋转节点(嘴巴)
|
||
public GameObject sprayEx; // 喷射特效(带 Trigger)
|
||
public Transform hand;
|
||
public Animator handAnimator;
|
||
public float sprayDuration = 5f;
|
||
public float sprayAngle = 40f;
|
||
public GameObject clipQuadObj;
|
||
|
||
public GameObject[] bossCrystals;
|
||
|
||
private float rotateSpeed = 180f; // 越大转得越快(插值系数)
|
||
|
||
private void Start()
|
||
{
|
||
foreach (var item in tentacles)
|
||
{
|
||
item.SetData(Data);
|
||
}
|
||
sprayEx.SetActive(false);
|
||
teleportPoints = GameInit.Ins.allBossPos;
|
||
bloodSlider.gameObject.SetActive(false);
|
||
transform.LookAt(GameManager.Ins.player.transform.position.ReflectVectorXOZ());
|
||
foreach (var item in bossCrystals)
|
||
{
|
||
item.SetActive(false);
|
||
}
|
||
}
|
||
|
||
public override void Update()
|
||
{
|
||
base.Update();
|
||
if (enemyState != EnemyState.Show && enemyState != EnemyState.Dead)
|
||
{
|
||
skill1Timer += Time.deltaTime;
|
||
skill2Timer += Time.deltaTime;
|
||
teleportTimer += Time.deltaTime;
|
||
|
||
Transform player = GameManager.Ins.player.transform;
|
||
if (!player) return;
|
||
|
||
Vector3 dir = player.position - hand.position;
|
||
dir.y = 0;
|
||
|
||
if (dir.sqrMagnitude < 0.0001f)
|
||
return;
|
||
|
||
Quaternion targetRot = Quaternion.LookRotation(dir);
|
||
|
||
hand.transform.rotation = Quaternion.RotateTowards(
|
||
hand.transform.rotation,
|
||
targetRot,
|
||
rotateSpeed * Time.deltaTime
|
||
);
|
||
}
|
||
}
|
||
|
||
public List<Tentacle> GetAliveTentacles()
|
||
{
|
||
List<Tentacle> list = new();
|
||
foreach (var t in tentacles)
|
||
if (t != null && !t.isDead)
|
||
list.Add(t);
|
||
return list;
|
||
}
|
||
|
||
public void ResetSkill1() => skill1Timer = 0;
|
||
public void ResetSkill2() => skill2Timer = 0;
|
||
public void ResetTeleport() => teleportTimer = 0;
|
||
|
||
public override void Show()
|
||
{
|
||
base.Show();
|
||
GameManager.Ins.CreateEnemySkillTip(transform.position.ReflectVectorXOZ(),3.5f);
|
||
transform.position = new Vector3(transform.position.x, -8, transform.position.z);
|
||
transform.DOMoveY(0, 4f).OnComplete(() =>
|
||
{
|
||
isShowEnd = true;
|
||
});
|
||
}
|
||
|
||
public override void EndShow()
|
||
{
|
||
base.EndShow();
|
||
enemyState = EnemyState.Idle;
|
||
foreach (var item in tentacles)
|
||
{
|
||
item.EndShow();
|
||
}
|
||
foreach (var item in bossCrystals)
|
||
{
|
||
item.SetActive(true);
|
||
}
|
||
bloodSlider.gameObject.SetActive(true);
|
||
}
|
||
|
||
public override void Hit()
|
||
{
|
||
if(enemyState!= EnemyState.Idle)
|
||
return;
|
||
base.Hit();
|
||
handAnimator.SetTrigger("hit");
|
||
}
|
||
|
||
public override void ChangeHp(float value, object info, Transform _sender)
|
||
{
|
||
if(enemyState== EnemyState.Show)
|
||
return;
|
||
base.ChangeHp(value, info, _sender);
|
||
}
|
||
|
||
public override void Dead()
|
||
{
|
||
if (isDead)
|
||
{
|
||
return;
|
||
}
|
||
GameManager.Ins.curLevel++;
|
||
health = 0;
|
||
isDead = true;
|
||
if (bloodSlider != null)
|
||
bloodSlider.gameObject.SetActive(false);
|
||
if(ColliderComponent!=null)
|
||
ColliderComponent.enabled = false;
|
||
if(behaviourTree != null)
|
||
behaviourTree.enabled = false;
|
||
GameManager.Ins.PlaySound3D("1.46",transform,true);
|
||
foreach (var item in GetAliveTentacles())
|
||
{
|
||
item.Dead();
|
||
}
|
||
foreach (var item in bossCrystals)
|
||
{
|
||
if(item==null)
|
||
continue;
|
||
item.SetActive(false);
|
||
}
|
||
StartCoroutine(DeathDissolve());
|
||
}
|
||
|
||
IEnumerator DeathDissolve()
|
||
{
|
||
// 1️⃣ 停止行为
|
||
behaviourTree.enabled = false;
|
||
ColliderComponent.enabled = false;
|
||
|
||
clipQuadObj.SetActive(true);
|
||
bloodSlider.gameObject.SetActive(false);
|
||
clipQuadObj.transform.localPosition = new Vector3(0, 5f, 0);
|
||
|
||
clipQuadObj.transform.DOLocalMoveY(-5f, 5);
|
||
yield return new WaitForSeconds(8f);
|
||
GameManager.Ins.CreateBoss(transform.position.ReflectVectorXOZ());
|
||
Destroy(gameObject);
|
||
}
|
||
}
|
||
|
||
|