156 lines
4.4 KiB
C#
156 lines
4.4 KiB
C#
using Manager;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CharacterCombat : CombaSystem
|
|
{
|
|
|
|
[Header("音效")]
|
|
public AudioSource audioSource;
|
|
public PlayerControler controler;
|
|
|
|
[Header("特效")]
|
|
public GameObject effect;
|
|
|
|
CameraVR cameraVR;
|
|
|
|
protected override void Awake()
|
|
{
|
|
maxHp = PlayerInfo.Instance.info.maxHp;
|
|
currentHp = PlayerInfo.Instance.info.currentHp;
|
|
attack = PlayerInfo.Instance.info.testAttack;
|
|
|
|
audioSource = transform.root.GetComponentInChildren<AudioSource>();
|
|
|
|
_animator = GetComponent<Animator>();
|
|
|
|
PlayerInfo.Instance.OnUpdateAttrbute += OnChangeAttrbute;
|
|
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
PlayerInfo.Instance.OnUpdateAttrbute -= OnChangeAttrbute;
|
|
}
|
|
|
|
public override void MelleeAttackAnimEvent()
|
|
{
|
|
base.MelleeAttackAnimEvent();
|
|
|
|
Collider2D[] hitColliders = Physics2D.OverlapBoxAll(AttackAreaPos,attackSize,0,layerMasks[0]);
|
|
Collider2D[] destructiveColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0,layerMasks[1]);
|
|
Collider2D[] treeColliders = Physics2D.OverlapBoxAll(AttackAreaPos, attackSize, 0, layerMasks[2]);
|
|
|
|
|
|
foreach (Collider2D hitInfo in hitColliders)
|
|
{
|
|
|
|
if(hitInfo.tag=="Enemy")
|
|
{//小怪
|
|
}
|
|
if (hitInfo.tag == "Boss")
|
|
{
|
|
|
|
hitInfo.GetComponentInChildren<BossAI>().TakeDamage("hurt-front",GetAttack());
|
|
if (_summerClip != null)
|
|
SoundManager.Instance.PlayEffect(_audio, _summerClip);
|
|
//加入卡肉,特效
|
|
if(effect!=null)
|
|
{
|
|
GameObject go = Instantiate(effect);
|
|
|
|
go.transform.position = hitInfo.transform.position + new Vector3(0,4,0);
|
|
|
|
//开始计时
|
|
string timerPath = "Perfab/Timer";
|
|
GameObject timer = Resloader.Load<GameObject>(timerPath);//寻找预制体
|
|
|
|
GameObject time = Instantiate(timer);
|
|
time.GetComponent<Timer>().CreateTime(0.2f, () =>
|
|
{
|
|
ManagersMode.Poll.UnSpwan("EffectPoll", effect.name, go);
|
|
}, false);
|
|
|
|
}
|
|
|
|
cameraVR = UnityExpandFunction.GetCamera();
|
|
if (cameraVR != null)
|
|
{
|
|
cameraVR.ShakeCamera(0.5f, 2);
|
|
}
|
|
}
|
|
}
|
|
foreach (Collider2D hitInfo in destructiveColliders)
|
|
{
|
|
|
|
}
|
|
foreach (Collider2D hitInfo in treeColliders)//数目
|
|
{
|
|
Debug.Log("攻击树木");
|
|
hitInfo.GetComponentInChildren<Tree>().TakeDamage();
|
|
}
|
|
}
|
|
|
|
|
|
//受伤
|
|
public override void TakeDamage(float atk)
|
|
{
|
|
currentHp -= atk;
|
|
|
|
OnHit?.Invoke(currentHp);//UI显示
|
|
|
|
if(currentHp<=0)
|
|
{
|
|
//死亡
|
|
return;
|
|
}
|
|
_animator.Play("hurt");
|
|
}
|
|
private void OnChangeAttrbute(LotteryType type, float value)
|
|
{
|
|
switch (type)
|
|
{
|
|
case LotteryType.Hp:
|
|
currentHp += value;
|
|
if(currentHp>=maxHp)
|
|
{
|
|
currentHp = maxHp;
|
|
}
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
case LotteryType.Mp:
|
|
maxHp += value;
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
case LotteryType.Attack:
|
|
attack += value;
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
case LotteryType.UpMaxHp:
|
|
PlayerInfo.Instance.info.maxHp += value;
|
|
maxHp += value;
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
case LotteryType.UpHp:
|
|
Date.Instance.ItemDate[1].value += (int)value;
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
case LotteryType.UpAttack:
|
|
PlayerInfo.Instance.info.attack += value;
|
|
attack += value;
|
|
OnHit?.Invoke(currentHp);
|
|
break;
|
|
default:break;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 攻击力量
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public float GetAttack()
|
|
{
|
|
return attack + (PlayerInfo.Instance.info.Level * 10);
|
|
}
|
|
}
|