using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
//回复技能,魔法技能,物理技能
public enum SkillType { Up, Magic, Physics };
public class SkillBase : MonoBehaviour{
protected GameObject prefab;
protected SkillType type;//类型
protected string path = “Skill/”;
protected string skillName;
protected int attValue;
public int mp;
protected People from;//从人物释放
protected People tPeople;//敌人目标
protected Dictionary<SkillType, UnityAction> typeWithSkill =
new Dictionary<SkillType, UnityAction>();
protected float time = 0;//计时器
protected float skillTime;//技能冷却时间
protected float delayTime;//延迟时间
protected float offset;//偏移量
protected Vector3 skillPoint;//攻击点
public bool IsRelease { get; private set; }//技能是否释放
protected int layer;//技能对哪个一层起作用
protected Collider[] cs;//技能碰撞体
public event UnityAction Handle;//处理方法
protected void Init(){
IsRelease = true;
layer = LayerMask.GetMask(“MyPlayer”) + LayerMask.GetMask(“Enemy”);
prefab = LoadManager.LoadGameObject(path + skillName);
typeWithSkill.Add(SkillType.Magic, MagicHurt);
typeWithSkill.Add(SkillType.Physics, PhysicsHurt);
typeWithSkill.Add(SkillType.Up, HpUp);
}
#region 技能
private void MagicHurt(){
cs = GetColliders();
foreach (Collider c in cs){
if (c.tag != from.tag){
c.GetComponent<People>().BeMagicHit(attValue, from);
c.GetComponent<People>().Anim.SetTrigger(“Hurt“);
}
}
}
private void PhysicsHurt(){
cs = GetColliders();
foreach (Collider c in cs){
if (c.tag != from.tag){
c.GetComponent<People>().BePhysicsHit(attValue, from);
c.GetComponent<People>().Anim.SetTrigger(“Hurt“);
}
}
}
private void HpUp(){
cs = GetColliders();
foreach (Collider c in cs){
if (c.tag == from.tag){
c.GetComponent<People>().AddHp(attValue);
}
}
}
#endregion
protected virtual Collider[] GetColliders(){
return null;
}
public float GetFillTime(){
if (IsRelease){
return 0;
}
time -= Time.deltaTime;
if (time < 0){
IsRelease = true;
}
return time / skillTime;
}
public void SetEventHandle(UnityAction fun){
Handle += fun;
}
public bool MayRelease(){
return (from.Mp + mp >= 0) && IsRelease;
}
//携程函数-技能释放执行
public virtual IEnumerator SkillPrefab(){
IsRelease = false;
time = skillTime;
yield return new WaitForSeconds(delayTime);//等待延迟时间
typeWithSkill[type]();
from.AddMp(mp);
skillPoint = from.transform.position + from.transform.forward * offset;
Quaternion qua = from.transform.rotation;//施放角度
GameObject effect = Instantiate(prefab, skillPoint, qua);
yield return new WaitForSeconds(3);//等待三秒
Handle?.Invoke();//时间调用
Destroy(effect);//特效销毁
}
}
技能基类创建完后创建技能子类StraightSkill