2021-12-17 01:27:10 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using DG.Tweening;
|
|
|
|
using Sirenix.OdinInspector;
|
2021-12-22 10:01:30 +08:00
|
|
|
using UnityEngine.Rendering;
|
2021-12-24 02:07:24 +08:00
|
|
|
using UnityEngine.Rendering.Universal;
|
2021-12-17 01:27:10 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 以撒类,控制以撒Boss
|
|
|
|
/// </summary>
|
|
|
|
public class YiSa : Enemy
|
|
|
|
{
|
|
|
|
// _____ _ _ _
|
|
|
|
// | __ \ | | | (_)
|
|
|
|
// | |__) | _| |__ | |_ ___
|
|
|
|
// | ___/ | | | '_ \| | |/ __|
|
|
|
|
// | | | |_| | |_) | | | (__
|
|
|
|
// |_| \__,_|_.__/|_|_|\___|
|
|
|
|
|
2021-12-17 19:54:50 +08:00
|
|
|
|
2021-12-17 01:27:10 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 攻击用鬼魂的预制体
|
|
|
|
/// </summary>
|
|
|
|
[Header("攻击用鬼魂的预制体")][FoldoutGroup("预制体")]
|
|
|
|
public GameObject goust;
|
|
|
|
/// <summary>
|
|
|
|
/// 鬼魂攻击玩家时,生成位置离玩家的距离
|
|
|
|
/// </summary>
|
|
|
|
[Header("鬼魂攻击玩家时,生成位置离玩家的距离")][FoldoutGroup("以撒")]
|
|
|
|
public float atkOffsetDistance;
|
2021-12-17 19:54:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 疯狂的鬼魂的攻击间隔时间
|
|
|
|
/// </summary>
|
|
|
|
[Header("疯狂的鬼魂的攻击间隔时间")][FoldoutGroup("以撒")]
|
|
|
|
public float crazyGoustTimeBetweenAttacks;
|
|
|
|
/// <summary>
|
|
|
|
/// 正常的鬼魂的攻击间隔时间
|
|
|
|
/// </summary>
|
|
|
|
[Header("正常的鬼魂的攻击间隔时间")][FoldoutGroup("以撒")]
|
|
|
|
public float normalGoustTimeBetweenAttacks;
|
2021-12-17 01:27:10 +08:00
|
|
|
|
2021-12-22 10:01:30 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 鬼魂的粒子材质
|
|
|
|
/// </summary>
|
|
|
|
[Header("鬼魂的粒子材质")][FoldoutGroup("材质")]
|
|
|
|
public Material GoustMaterial;
|
|
|
|
/// <summary>
|
|
|
|
/// 屏幕后特效组件
|
|
|
|
/// </summary>
|
|
|
|
[Header("屏幕后特效组件")] [FoldoutGroup("材质")]
|
|
|
|
public Volume volume;
|
2021-12-24 02:07:24 +08:00
|
|
|
|
2021-12-17 01:27:10 +08:00
|
|
|
// _____ _ _
|
|
|
|
// | __ \ (_) | |
|
|
|
|
// | |__) | __ ___ ____ _| |_ ___
|
|
|
|
// | ___/ '__| \ \ / / _` | __/ _ \
|
|
|
|
// | | | | | |\ V / (_| | || __/
|
|
|
|
// |_| |_| |_| \_/ \__,_|\__\___|
|
2021-12-17 19:54:50 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 攻击之间的间隔时间
|
|
|
|
/// </summary>
|
|
|
|
private float timeBetweenAttacks;
|
2021-12-17 01:27:10 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 返回类型为协程、参数为空的委托类型
|
|
|
|
/// </summary>
|
|
|
|
private delegate IEnumerator Action();
|
|
|
|
private MyPlayer player;
|
2021-12-17 19:54:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 目前是否处于狂暴状态
|
|
|
|
/// </summary>
|
|
|
|
[Header("目前是否处于狂暴状态")][FoldoutGroup("状态")][ReadOnly]
|
|
|
|
private bool isCrazy;
|
|
|
|
/// <summary>
|
|
|
|
/// 颜色补正,主要在狂暴系统中更改
|
|
|
|
/// </summary>
|
|
|
|
private Color colorOffset;
|
|
|
|
/// <summary>
|
|
|
|
/// 震动动画
|
|
|
|
/// </summary>
|
|
|
|
private Tweener shakeTweener;
|
2021-12-17 01:27:10 +08:00
|
|
|
|
|
|
|
// _____ _ _ ____ _
|
|
|
|
// / ____| | | | _ \ | |
|
|
|
|
// | | __ _| | | |_) | __ _ ___| | __
|
|
|
|
// | | / _` | | | _ < / _` |/ __| |/ /
|
|
|
|
// | |___| (_| | | | |_) | (_| | (__| <
|
|
|
|
// \_____\__,_|_|_|____/ \__,_|\___|_|\_\
|
|
|
|
|
|
|
|
void Start(){
|
|
|
|
Init();
|
|
|
|
//测试用开启
|
2021-12-23 01:19:03 +08:00
|
|
|
//InCrazy();
|
|
|
|
//StartCoroutine(StartAATK());
|
2021-12-17 01:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// _ _ _
|
|
|
|
// | \ | | | |
|
|
|
|
// | \| | ___ _ __ _ __ ___ __ _| |
|
|
|
|
// | . ` |/ _ \| '__| '_ ` _ \ / _` | |
|
|
|
|
// | |\ | (_) | | | | | | | | (_| | |
|
|
|
|
// |_| \_|\___/|_| |_| |_| |_|\__,_|_|
|
|
|
|
|
|
|
|
private void Init(){
|
|
|
|
//找到必要的物体和组件
|
|
|
|
player = FindObjectOfType<MyPlayer>();
|
2021-12-17 19:54:50 +08:00
|
|
|
//初始化攻击间隔时间
|
|
|
|
timeBetweenAttacks = normalGoustTimeBetweenAttacks;
|
|
|
|
//初始化颜色补正
|
|
|
|
colorOffset = Color.white;
|
2021-12-24 02:07:24 +08:00
|
|
|
GoustMaterial.SetColor("Color_",new Color(14,61,255));
|
|
|
|
//初始化生命值
|
|
|
|
HPLeft = HP;
|
2021-12-17 01:27:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 执行一次攻击
|
|
|
|
/// </summary>
|
2021-12-23 01:19:03 +08:00
|
|
|
public IEnumerator StartAATK(){
|
2021-12-17 01:27:10 +08:00
|
|
|
//等待攻击间隔
|
|
|
|
yield return new WaitForSeconds(timeBetweenAttacks);
|
|
|
|
//决定行动
|
|
|
|
Action action = DecideAAction();
|
|
|
|
//开始行动
|
|
|
|
StartCoroutine(action());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 决定行动的函数
|
|
|
|
/// </summary>
|
|
|
|
private Action DecideAAction(){
|
|
|
|
Action action;
|
|
|
|
///从0、1中随机生成一种
|
|
|
|
int r = Random.Range(0,2);
|
|
|
|
if(r == 0)
|
|
|
|
action = Rush;
|
|
|
|
else
|
|
|
|
action = Lighting;
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator Rush(){
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
Debug.Log("以撒使用了冲撞");
|
|
|
|
//当以撒使用冲撞时
|
|
|
|
//首先构建一个生成位置,以玩家为中心,向随机位置偏移固定距离便是
|
|
|
|
Vector3 appearPos = (
|
|
|
|
//玩家位置
|
|
|
|
player.transform.position +
|
|
|
|
//加上定长随机方向偏移量
|
|
|
|
new Vector3(
|
|
|
|
Random.Range(-1f,1f),Random.Range(-1f,1f),0
|
|
|
|
).normalized *
|
|
|
|
atkOffsetDistance
|
|
|
|
);
|
|
|
|
//在该位置生成一个鬼魂
|
|
|
|
YiSaGoust t = Instantiate(
|
|
|
|
goust,
|
|
|
|
appearPos,
|
|
|
|
Quaternion.identity
|
|
|
|
).GetComponent<YiSaGoust>();
|
2021-12-17 19:54:50 +08:00
|
|
|
//给鬼魂以颜色补正
|
|
|
|
t.GetComponent<SpriteRenderer>().DOColor(colorOffset,2f);
|
2021-12-17 01:27:10 +08:00
|
|
|
//让鬼魂淡出
|
2021-12-17 19:54:50 +08:00
|
|
|
//Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
|
2021-12-17 01:27:10 +08:00
|
|
|
//记录一下本次攻击的冲撞方向
|
|
|
|
Vector2 rushDir = player.transform.position - t.transform.position;
|
|
|
|
//告知该鬼魂执行冲撞攻击
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
t.RushATK(rushDir);
|
|
|
|
//ATKEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator Lighting(){
|
|
|
|
Debug.Log("以撒使用了落雷");
|
|
|
|
//在玩家头顶某位置召唤鬼魂
|
|
|
|
YiSaGoust t = Instantiate(
|
|
|
|
goust,player.transform.position +
|
|
|
|
new Vector3(0,2f,0),Quaternion.identity
|
|
|
|
).GetComponent<YiSaGoust>();
|
2021-12-25 00:37:29 +08:00
|
|
|
yield return new WaitForEndOfFrame();
|
2021-12-17 19:54:50 +08:00
|
|
|
//给鬼魂以颜色补正
|
|
|
|
t.GetComponent<SpriteRenderer>().DOColor(colorOffset,2f);
|
2021-12-25 00:37:29 +08:00
|
|
|
//激活鬼魂动画
|
|
|
|
t.animator.SetBool("isLightning",true);
|
|
|
|
//0.5秒淡入显示鬼魂
|
|
|
|
Tweener tweener = t.GetComponent<SpriteRenderer>().DOFade(1,0.5f);
|
2021-12-17 01:27:10 +08:00
|
|
|
//给玩家一秒的反应时间
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
t.LightningATK();
|
|
|
|
//ATKEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 攻击结束的时候触发,重新开始新一轮攻击
|
|
|
|
/// </summary>
|
2021-12-23 01:19:03 +08:00
|
|
|
public void ATKEnd(){
|
|
|
|
if(state == State.atk) StartCoroutine(StartAATK());
|
|
|
|
}
|
2021-12-17 01:27:10 +08:00
|
|
|
|
2021-12-17 19:54:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 进入狂暴状态
|
|
|
|
/// </summary>
|
|
|
|
private void InCrazy(){
|
2021-12-22 10:01:30 +08:00
|
|
|
//修改特效粒子为红色
|
|
|
|
GoustMaterial.SetColor("Color_",new Color(255,0,0));
|
|
|
|
//修改屏幕后特效辉光为红色
|
2021-12-24 02:07:24 +08:00
|
|
|
StartCoroutine(SetVolumeColor(volume, 0));
|
2021-12-22 10:01:30 +08:00
|
|
|
|
2021-12-17 19:54:50 +08:00
|
|
|
//修改标记表示开始狂暴
|
|
|
|
isCrazy = true;
|
|
|
|
//修改攻击间隔时间
|
|
|
|
timeBetweenAttacks = crazyGoustTimeBetweenAttacks;
|
|
|
|
//修改鬼魂颜色补正
|
|
|
|
colorOffset = Color.red;
|
|
|
|
//让石像震动
|
|
|
|
shakeTweener = transform.DOShakePosition(0.5f,0.1f,50,90,false,false).SetLoops(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 脱离狂暴装填
|
|
|
|
/// </summary>
|
|
|
|
private void OutCrazy(){
|
2021-12-22 10:01:30 +08:00
|
|
|
//修改特效粒子为原色
|
|
|
|
GoustMaterial.SetColor("Color_",new Color(14,61,255));
|
|
|
|
//修改屏幕后特效辉光为红色
|
2021-12-24 02:07:24 +08:00
|
|
|
StartCoroutine(SetVolumeColor(volume, 1));
|
2021-12-17 19:54:50 +08:00
|
|
|
//消除狂暴标记
|
|
|
|
isCrazy = false;
|
|
|
|
//修改攻击间隔时间
|
|
|
|
timeBetweenAttacks = normalGoustTimeBetweenAttacks;
|
|
|
|
//修改鬼魂颜色补正
|
|
|
|
colorOffset = Color.white;
|
|
|
|
//让石像停止震动
|
|
|
|
shakeTweener.Kill();
|
|
|
|
}
|
|
|
|
|
2021-12-17 01:27:10 +08:00
|
|
|
// ______ _
|
|
|
|
// | ____| | |
|
|
|
|
// | |____ _____ _ __ | |_
|
|
|
|
// | __\ \ / / _ \ '_ \| __|
|
|
|
|
// | |___\ V / __/ | | | |_
|
|
|
|
// |______\_/ \___|_| |_|\__|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 当有男童被救的时候从男童触发
|
|
|
|
/// </summary>
|
|
|
|
public void OnSave(Boy boy){
|
2021-12-17 19:54:50 +08:00
|
|
|
//当有男童被救,触发狂暴
|
|
|
|
InCrazy();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnBeHit(MyPlayer.AtkMethod hitMethod, int hitDir){
|
|
|
|
//只有狂暴状态会受击
|
|
|
|
if(isCrazy){
|
|
|
|
//结算生命值
|
|
|
|
HPLeft -= MyPlayer.atkMethodMagnification[hitMethod];
|
|
|
|
//解除狂暴
|
|
|
|
OutCrazy();
|
2021-12-23 01:19:03 +08:00
|
|
|
if(CheckDead()) OnDead();
|
2021-12-17 19:54:50 +08:00
|
|
|
}
|
2021-12-17 01:27:10 +08:00
|
|
|
}
|
2021-12-23 01:19:03 +08:00
|
|
|
public override void OnDead(){
|
2021-12-25 00:37:29 +08:00
|
|
|
//新建一个以撒灵魂,播放其消亡动画
|
|
|
|
StartCoroutine(ShowADeadGoust());
|
|
|
|
//播放自身碎裂动画
|
|
|
|
GetComponent<Animator>().SetBool("isDead",true);
|
2021-12-23 01:19:03 +08:00
|
|
|
state = State.dead;
|
|
|
|
FindObjectOfType<Transfer>().GetComponent<BoxCollider2D>().enabled = true;
|
2021-12-23 18:22:59 +08:00
|
|
|
//上传玩家进度
|
|
|
|
FindObjectOfType<PlayerInfo>().rate = (int) MyPlayer.Progress.过基;
|
|
|
|
FindObjectOfType<PlayerInfo>().UpdatePlayerInfo();
|
2021-12-23 01:19:03 +08:00
|
|
|
}
|
2021-12-25 00:37:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// //新建一个以撒灵魂,播放其消亡动画
|
|
|
|
/// </summary>
|
|
|
|
private IEnumerator ShowADeadGoust(){
|
|
|
|
//在雕像上方生成一个鬼魂
|
|
|
|
YiSaGoust t = Instantiate(
|
|
|
|
goust,transform.position +
|
|
|
|
new Vector3(0,2f,0),Quaternion.identity
|
|
|
|
).GetComponent<YiSaGoust>();
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
//播放鬼魂消亡动画
|
|
|
|
t.animator.SetBool("isDead",true);
|
|
|
|
t.GetComponent<SpriteRenderer>().DOFade(0,0.8f);
|
|
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
Destroy(t.gameObject);
|
|
|
|
}
|
2021-12-24 02:07:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 修改屏幕后特效
|
|
|
|
/// </summary>
|
|
|
|
private IEnumerator SetVolumeColor(Volume volume,float endValue)
|
|
|
|
{
|
|
|
|
Bloom bloom;
|
|
|
|
volume.profile.TryGet<Bloom>(out bloom);
|
|
|
|
Color color = bloom.tint.value;
|
|
|
|
if (color.g > endValue)
|
|
|
|
{
|
|
|
|
while (color.g>endValue)
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.05f);
|
|
|
|
color.g -= 0.1f;
|
|
|
|
color.b -= 0.1f;
|
|
|
|
bloom.tint.SetValue(new ColorParameter(color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (color.g<endValue)
|
|
|
|
{
|
|
|
|
yield return new WaitForSeconds(0.05f);
|
|
|
|
color.g += 0.1f;
|
|
|
|
color.b += 0.1f;
|
|
|
|
bloom.tint.SetValue(new ColorParameter(color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-12-17 01:27:10 +08:00
|
|
|
|
2021-12-24 02:07:24 +08:00
|
|
|
|
2021-12-17 01:27:10 +08:00
|
|
|
|
|
|
|
}
|