1
This commit is contained in:
337
unity/Assets/Script/GameObject/Enemy/BossAI.cs
Normal file
337
unity/Assets/Script/GameObject/Enemy/BossAI.cs
Normal file
@@ -0,0 +1,337 @@
|
||||
using Manager;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class BossAI : CombaSystem
|
||||
{
|
||||
//基本信息类
|
||||
public BossInfo _info;
|
||||
Rigidbody2D rb;
|
||||
|
||||
//玩家信息,待优化
|
||||
PlayerControler player;
|
||||
CharacterCombat characterCombat;
|
||||
|
||||
private Transform currentTarget;
|
||||
|
||||
|
||||
//玩家与敌人的距离方向
|
||||
private float dis;
|
||||
private Vector2 dir;
|
||||
|
||||
[Header("追击与攻击距离")]
|
||||
public float cheseDistance = 3f;
|
||||
public float attackDistance = 0.8f;
|
||||
|
||||
[SerializeField, Header("技能搭配")] private List<CombatAblilityBase> abilitys = new List<CombatAblilityBase>();
|
||||
private CombatAblilityBase currentAblity;
|
||||
//判断偏移
|
||||
private List<Vector2> ablityOff;
|
||||
//攻击段数
|
||||
private int attackCount;
|
||||
|
||||
//计时器
|
||||
public GameObject timer;
|
||||
|
||||
public bool isBegin = false;
|
||||
|
||||
List<CombatAblilityBase> tempAb = new List<CombatAblilityBase>();//可用技能组
|
||||
int ran;//技能组索引
|
||||
|
||||
CameraVR cameraVR;
|
||||
|
||||
public bool isYuancheng=false;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
|
||||
_animator = GetComponentInChildren<Animator>();
|
||||
rb = GetComponentInParent<Rigidbody2D>();
|
||||
currentTarget = GameObject.FindWithTag("Player").transform;
|
||||
|
||||
_info = GetComponentInParent<BossInfo>();
|
||||
|
||||
foreach (var ab in abilitys)
|
||||
{
|
||||
ab.Init(this,_animator);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (!_animator.CheckAnimationTag("summon")&&isBegin)
|
||||
{
|
||||
if (!isDie) //死亡或咆哮状态的时候不会进行攻击
|
||||
{
|
||||
MoveBoss();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (currentAblity != null)
|
||||
{
|
||||
currentAblity.UpdateAblity(currentTarget);
|
||||
}
|
||||
}
|
||||
private void MoveBoss()
|
||||
{
|
||||
if (_animator.CheckAnimationTag("Wake"))
|
||||
return;
|
||||
|
||||
if (_animator.CheckAnimationTag("hit") || _animator.CheckAnimationTag("Attack")||_animator.CheckAnimationTag("Attack_out"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (currentTarget == null)
|
||||
return;
|
||||
|
||||
LockTarget(currentTarget);
|
||||
|
||||
dis = Vector2.Distance(currentTarget.position, transform.position);
|
||||
if (dis < cheseDistance)
|
||||
{
|
||||
rb.velocity = Vector2.zero;
|
||||
//近战
|
||||
if (dis < attackDistance)
|
||||
{
|
||||
//_animator.Play("attack-charge");
|
||||
currentAblity = GetAblity(AblityClass.MelleeAttack);
|
||||
if (currentAblity != null)
|
||||
{
|
||||
//SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
|
||||
|
||||
_animator.Play(currentAblity.GetAbliltyName());
|
||||
|
||||
currentAblity.UseAblity(currentAblity);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
//远程
|
||||
else
|
||||
{
|
||||
currentAblity = GetAblity(AblityClass.YuanChenAttack);
|
||||
if (currentAblity != null)
|
||||
{
|
||||
//SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
|
||||
|
||||
_animator.Play(currentAblity.GetAbliltyName());
|
||||
|
||||
currentAblity.UseAblity(currentAblity);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!_info.isCanMove)
|
||||
return;
|
||||
_animator.Play("run");
|
||||
rb.velocity = dir * _info._moveSpeed;
|
||||
}
|
||||
|
||||
}
|
||||
private void LockTarget(Transform target)
|
||||
{
|
||||
if (!_info.isLockTarget)
|
||||
return;
|
||||
dir = (target.position - transform.position).normalized;
|
||||
if(_info.isFix)
|
||||
{
|
||||
Fix(dir);
|
||||
}
|
||||
}
|
||||
private void Fix(Vector2 dir)
|
||||
{
|
||||
if (dir.x < 0)
|
||||
{
|
||||
transform.root.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
if (dir.x > 0)
|
||||
{
|
||||
transform.root.localScale = new Vector3(-1, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Yuancheng()
|
||||
{
|
||||
isYuancheng = true;
|
||||
}
|
||||
public void OnCloseYuancheng()
|
||||
{
|
||||
isYuancheng = false;
|
||||
}
|
||||
public void TeleportEvent()
|
||||
{
|
||||
if (currentTarget == null) return;
|
||||
transform.root.transform.position = currentTarget.transform.position;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 近战攻击
|
||||
/// </summary>
|
||||
public override void MelleeAttackAnimEvent()
|
||||
{
|
||||
if (currentAblity != null)
|
||||
{
|
||||
AttackAreaPos = transform.position;
|
||||
|
||||
ablityOff = currentAblity.GetAbliltyOffest();
|
||||
|
||||
AttackAreaPos.x += ablityOff[attackCount].x;
|
||||
AttackAreaPos.y += ablityOff[attackCount].y;
|
||||
attackCount++;
|
||||
if (attackCount >= ablityOff.Count)
|
||||
{
|
||||
attackCount = 0;
|
||||
}
|
||||
|
||||
if (_info.isCanMove)
|
||||
{
|
||||
AttackAreaPos.x = this.transform.parent.localScale.x < 0 ? Mathf.Abs(offsetX) : -Mathf.Abs(offsetX);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
base.MelleeAttackAnimEvent();
|
||||
}
|
||||
|
||||
Collider2D[] hitColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0, layerMasks[0]);
|
||||
if(currentAblity!=null&¤tAblity.GetAbliltyVFX()!=null)
|
||||
{
|
||||
SoundManager.Instance.PlayEffect(_audio, currentAblity.GetAbliltyVFX());
|
||||
}
|
||||
|
||||
foreach (Collider2D hitInfo in hitColliders)
|
||||
{
|
||||
|
||||
player = hitInfo.GetComponent<PlayerControler>();
|
||||
if (player != null && player.GetIsDodge())
|
||||
{
|
||||
Debug.Log("玩家无敌");
|
||||
_animator.speed = 0;
|
||||
StartCoroutine(ScalTime(1f));
|
||||
|
||||
return;
|
||||
}
|
||||
characterCombat = hitInfo.GetComponentInChildren<CharacterCombat>();
|
||||
//if(characterCombat._animator.CheckAnimationTag("Roll"))
|
||||
//{
|
||||
// //无敌闪避
|
||||
// _animator.speed = 0;
|
||||
// StartCoroutine(ScalTime(1f));
|
||||
// return;
|
||||
//}
|
||||
|
||||
characterCombat.TakeDamage(attack);
|
||||
Debug.Log("玩家受伤");
|
||||
}
|
||||
}
|
||||
IEnumerator ScalTime(float timer)
|
||||
{
|
||||
yield return new WaitForSeconds(timer);
|
||||
_animator.speed = 1;
|
||||
}
|
||||
public override void TakeDamage(string aniName, float attack)
|
||||
{
|
||||
|
||||
if (isDie || _animator.CheckAnimationTag("summon")||_animator.CheckAnimationTag("Wake"))//咆哮不会被攻击
|
||||
return;
|
||||
Debug.Log("被玩家攻击" + _info.attackedCount);
|
||||
|
||||
_info.attackedCount++;//耐力次数增加
|
||||
|
||||
if (_info.attackedCount > _info.maxAttackedCount)
|
||||
{
|
||||
_info.attackedCount = 0;//重新计数
|
||||
|
||||
_animator.Play("summon");
|
||||
if(_summerClip!=null)
|
||||
{
|
||||
SoundManager.Instance.PlayEffect(_audio,_summerClip);
|
||||
}
|
||||
|
||||
//吼叫
|
||||
|
||||
|
||||
//摄像机震动
|
||||
|
||||
cameraVR=UnityExpandFunction.GetCamera();
|
||||
if (cameraVR != null)
|
||||
{
|
||||
cameraVR.ShakeCamera(1f, 5);
|
||||
}
|
||||
|
||||
//回血
|
||||
currentHp += 200;
|
||||
if (currentHp >= maxHp)
|
||||
currentHp = maxHp;
|
||||
OnHit?.Invoke(currentHp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//受伤
|
||||
currentHp -= attack;//血量减少
|
||||
OnHit?.Invoke(currentHp);//执行受伤事件,血量UI减少
|
||||
if (currentHp <= 0)
|
||||
{
|
||||
isDie = true;
|
||||
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
if(_animator.CheckAnimationTag("Attack"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_animator.Play(aniName);
|
||||
}
|
||||
private CombatAblilityBase GetAblity(AblityClass ablity)
|
||||
{
|
||||
tempAb.Clear();
|
||||
foreach (var ab in abilitys)
|
||||
{
|
||||
if (ab.GetAbliltyIsDone() && ab.GetAbliltyClass() == ablity)
|
||||
{
|
||||
tempAb.Add(ab);
|
||||
}
|
||||
}
|
||||
if(tempAb.Count==0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ran = UnityEngine.Random.Range(0,tempAb.Count);
|
||||
if (tempAb[ran] != null)
|
||||
return tempAb[ran];
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void SetBegin(bool b)
|
||||
{
|
||||
isBegin = b;
|
||||
//开始
|
||||
_animator.Play("sleeping");
|
||||
UIManager.Instance.Show<UIEnterScene>().InitInfo(_info.bossHead, _info.bossName);
|
||||
}
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
|
||||
Gizmos.color = Color.yellow;
|
||||
Gizmos.DrawWireSphere(transform.position, cheseDistance);
|
||||
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawWireSphere(transform.position, attackDistance);
|
||||
}
|
||||
}
|
||||
11
unity/Assets/Script/GameObject/Enemy/BossAI.cs.meta
Normal file
11
unity/Assets/Script/GameObject/Enemy/BossAI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d151185264385eb48b7823df0a3c2d04
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
unity/Assets/Script/GameObject/Enemy/BossInfo.cs
Normal file
28
unity/Assets/Script/GameObject/Enemy/BossInfo.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BossInfo : MonoBehaviour
|
||||
{
|
||||
|
||||
[Header("名字与头像")]
|
||||
public string bossName;
|
||||
public Sprite bossHead;
|
||||
|
||||
[Header("失衡最大次数")]
|
||||
public int maxAttackedCount;
|
||||
[Header("被攻击次数")]
|
||||
public int attackedCount=0;
|
||||
|
||||
//是否允许锁定目标
|
||||
[Header("索敌")]
|
||||
public bool isLockTarget;
|
||||
[Header("移动")]
|
||||
public bool isCanMove;
|
||||
[Header("翻转")]
|
||||
public bool isFix;
|
||||
|
||||
[Header("移动速度")]
|
||||
public float _moveSpeed;
|
||||
}
|
||||
11
unity/Assets/Script/GameObject/Enemy/BossInfo.cs.meta
Normal file
11
unity/Assets/Script/GameObject/Enemy/BossInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c35bd5b6f66429b47a669052403acc96
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
64
unity/Assets/Script/GameObject/Enemy/Enemy.cs
Normal file
64
unity/Assets/Script/GameObject/Enemy/Enemy.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
//using System;
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using UnityEngine;
|
||||
//using UnityEngine.Events;
|
||||
|
||||
|
||||
//普通怪物
|
||||
//public class Enemy : CharacterManager
|
||||
//{
|
||||
// [Header("距离")]
|
||||
// public float cheseDistance = 3f;
|
||||
// public float attackDistance = 0.8f;
|
||||
|
||||
// public UnityEvent<Vector2> OnMoveInput;
|
||||
// public Action OnAttack;
|
||||
|
||||
// private Transform player;
|
||||
|
||||
// //玩家与敌人的距离方向
|
||||
// private float dis;
|
||||
// private Vector2 dir;
|
||||
|
||||
|
||||
// private void Awake()
|
||||
// {
|
||||
// player = GameObject.FindWithTag("Player").transform;
|
||||
// }
|
||||
|
||||
// private void Update()
|
||||
// {
|
||||
// if (player == null)
|
||||
// return;
|
||||
// dis = Vector2.Distance(player.position,transform.position);
|
||||
// if(dis<cheseDistance)
|
||||
// {
|
||||
// //追击
|
||||
// if(dis<=attackDistance)
|
||||
// {
|
||||
// OnMoveInput?.Invoke(Vector2.zero);
|
||||
// //攻击
|
||||
// OnAttack?.Invoke();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dir = player.position - transform.position;
|
||||
// OnMoveInput?.Invoke(dir.normalized);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// OnMoveInput?.Invoke(Vector2.zero);//放弃追击
|
||||
// }
|
||||
// }
|
||||
// private void OnDrawGizmosSelected()
|
||||
// {
|
||||
|
||||
// Gizmos.color = Color.yellow;
|
||||
// Gizmos.DrawWireSphere(transform.position,cheseDistance);
|
||||
|
||||
// Gizmos.color = Color.red;
|
||||
// Gizmos.DrawWireSphere(transform.position, attackDistance);
|
||||
// }
|
||||
//}
|
||||
11
unity/Assets/Script/GameObject/Enemy/Enemy.cs.meta
Normal file
11
unity/Assets/Script/GameObject/Enemy/Enemy.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77c1c191d793d434ca113069f4ef2880
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
142
unity/Assets/Script/GameObject/Enemy/EnemyController.cs
Normal file
142
unity/Assets/Script/GameObject/Enemy/EnemyController.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
//using System.Collections;
|
||||
//using System.Collections.Generic;
|
||||
//using UnityEngine;
|
||||
//using System;
|
||||
//using Manager;
|
||||
|
||||
|
||||
//普通怪物
|
||||
//public class EnemyController : MonoBehaviour
|
||||
//{
|
||||
// public GameObject attackVFX;
|
||||
|
||||
// [Header("移动速度")] public float currentSpeed;
|
||||
// [Header("攻击")]
|
||||
// [SerializeField] private bool isAttack = true;
|
||||
// [SerializeField] private float attackCollDuration = 1;
|
||||
|
||||
// private bool isDead=false;
|
||||
// public Vector2 MoveInput
|
||||
// {
|
||||
// get;set;
|
||||
// }
|
||||
|
||||
// private Enemy enemy;
|
||||
|
||||
// private Rigidbody2D rb;
|
||||
// private SpriteRenderer sr;
|
||||
// private Animator animator;
|
||||
// private Collider2D colliderEnemy;
|
||||
|
||||
// [Header("攻击,间隔")]
|
||||
// public float attackDamage = 20;
|
||||
// public float attackDuration = 1.5f;
|
||||
// public LayerMask playerLayer;
|
||||
|
||||
// private void Awake()
|
||||
// {
|
||||
// rb = transform.parent.GetComponent<Rigidbody2D>();
|
||||
// colliderEnemy = transform.parent.GetComponent<Collider2D>();
|
||||
// sr = GetComponent<SpriteRenderer>();
|
||||
// animator = GetComponent<Animator>();
|
||||
// enemy = transform.parent.GetComponent<Enemy>();
|
||||
// }
|
||||
// private void Start()
|
||||
// {
|
||||
// enemy.OnAttack += OnAttack;
|
||||
// }
|
||||
|
||||
// private void FixedUpdate()
|
||||
// {
|
||||
// if(!isDead)
|
||||
// {
|
||||
// OnMove();
|
||||
// }
|
||||
// SetAnimation();
|
||||
// }
|
||||
// private void OnMove()
|
||||
// {
|
||||
// if (MoveInput.magnitude > 0.1f && currentSpeed > 0)
|
||||
// {
|
||||
// rb.velocity = MoveInput * currentSpeed;
|
||||
// if(MoveInput.x<0)
|
||||
// {
|
||||
// sr.flipX = false;
|
||||
// }
|
||||
// if (MoveInput.x > 0)
|
||||
// {
|
||||
// sr.flipX = true;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rb.velocity = Vector2.zero;
|
||||
// }
|
||||
// }
|
||||
// void OnAttack()
|
||||
// {
|
||||
// if(isAttack)
|
||||
// {
|
||||
// isAttack = false;
|
||||
// StartCoroutine(nameof(AttackCoroutine));
|
||||
// }
|
||||
// }
|
||||
// IEnumerator AttackCoroutine()
|
||||
// {
|
||||
// animator.SetTrigger("Attack");
|
||||
|
||||
// yield return new WaitForSeconds(attackCollDuration);
|
||||
// isAttack = true;
|
||||
// }
|
||||
|
||||
// public void EnemyHurt()
|
||||
// {
|
||||
// animator.SetTrigger("Hurt");
|
||||
// }
|
||||
// public void EnemyDead()
|
||||
// {
|
||||
// rb.velocity = Vector2.zero;
|
||||
// isDead = true;
|
||||
// colliderEnemy.enabled = false;
|
||||
// }
|
||||
// void SetAnimation()
|
||||
// {
|
||||
// animator.SetBool("isWalk",MoveInput.magnitude>0);
|
||||
// animator.SetBool("isDead", isDead);
|
||||
// }
|
||||
// public void DestoryEnemy()
|
||||
// {
|
||||
// Destroy(transform.parent.gameObject);
|
||||
// }
|
||||
|
||||
// public void MelleeAttackAnimEvent()
|
||||
// {
|
||||
// Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, enemy.attackDistance, playerLayer);
|
||||
|
||||
|
||||
// foreach (Collider2D hitInfo in hitColliders)
|
||||
// {
|
||||
// hitInfo.transform.root.GetComponentInChildren<CharacterCombat>().TakeDamage();
|
||||
// }
|
||||
// }
|
||||
// public void YuanChengAttackAnimEvent(string name)
|
||||
// {
|
||||
// Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, enemy.attackDistance, playerLayer);
|
||||
|
||||
// foreach (Collider2D hitInfo in hitColliders)
|
||||
// {
|
||||
// GameObject go=Instantiate(attackVFX,transform.position,Quaternion.identity);
|
||||
// go.AddComponent<VFXMove>();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void Protected(string name)
|
||||
// {
|
||||
// string monster = "Perfab/Monsters/" + name;
|
||||
// UnityEngine.Object go =Resloader.Load<GameObject>(monster);
|
||||
// if(go!=null)
|
||||
// {
|
||||
// GameObject m= (GameObject)Instantiate(go,transform.root);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
11
unity/Assets/Script/GameObject/Enemy/EnemyController.cs.meta
Normal file
11
unity/Assets/Script/GameObject/Enemy/EnemyController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0032ed98b43e5f44f9531330d1776782
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user