Unity技能系统(三)

Unity技能系统(一)

Unity技能系统(二)

Demo展示

六.Buff系统

buff分为增益和减益buff,应该区分开来;

/// <summary>
/// Buff类型,可叠加
/// </summary>
public enum BuffType
{
None,
Burn = 2, //点燃
Slow = 4, //减速
Light = 8, //感电
Stun = 16, //眩晕
Poison = 32, //中毒
BeatBack = 64, //击退
BeatUp = 128, //击飞
Pull = 256, //拉拽
AddDefence = 512,
RecoverHp = 1024,
}

本来计划是也用与或非来记录buff的,一个技能可能有多个buff,但是好像用list来存储也是一样的;

一个技能只能有两个buff图标,一个增益buff给自身,一个减益buff给敌人;

一个技能的增益和减益buff可能有多重效果;

比如:技能闪电——导致减速+感电+击退+自身增加狂暴(变态技能);

但是说这么说,写起来比较麻烦,就不那么细分了,一种效果一个图标单独计时;

这里面需求比较复杂,根据需求自行改写吧;

1.BuffRun

挂载在拥有buff的物体上,计算buff的效果,如减伤,掉血,减速等;

同时负责buff计时,提供buff计时刷新接口供重复buffIcon调用(也可叠加buff层数按需求);

使用了静态方法初始化和静态链表存储了buff特效的信息,用来动态加载buff特效预制体;

public class BuffRun : MonoBehaviour
{
private float durationTime;
public BuffType bufftype;
private float value; //伤害或者加成 private float interval; private float attackTimer; private float curTime; private CharacterStatus target; //添加buff时候初始化buffrun
public void InitBuff(BuffType buffType,float duration,float value,float interval)
{
bufftype = buffType; if (buffType == BuffType.BeatBack || buffType == BuffType.BeatUp || buffType == BuffType.Pull)
duration = 2f; durationTime = duration;
this.value = value;
this.interval = interval;
curTime = 0;
} //重置buff时间
public void Reset()
{
attackTimer = 0;
curTime = 0;
} void Start()
{
curTime = 0;
target = GetComponent<CharacterStatus>();
StartCoroutine(ExcuteDamage());
} private void Update()
{
curTime += Time.deltaTime; if(curTime > durationTime)
Destroy(this);
} //执行buff效果,支持多段影响
private IEnumerator ExcuteDamage()
{
attackTimer = 0; //已持续攻击的时间 do
{
//对敌人的影响
TargetImpact(); yield return new WaitForSeconds(interval);
attackTimer += interval;
//做伤害数值的计算
} while (durationTime > attackTimer); Destroy(this);
} private void TargetImpact()
{
//buff特效挂载点,有些buff挂载不在HitFxPos,所以写在上面
Transform fxPosTf = target.HitFxPos; //根据不同buff做相应的效果响应
if (bufftype == BuffType.Burn || bufftype == BuffType.Poison || bufftype == BuffType.Light)
target.OnDamage(value, gameObject, true);
else if (bufftype == BuffType.Slow)//减速
fxPosTf = target.transform;
else if (bufftype == BuffType.BeatBack)
{
Vector3 dir = -target.transform.position + GameObject.FindGameObjectWithTag("Player").transform.position;
dir.y = 0;
target.transform.DOMove(target.transform.position - dir.normalized * value,0.5f);
durationTime = 2f;
}
else if (bufftype == BuffType.BeatUp)
{
target.transform.DOMove(target.transform.position - Vector3.up * value,0.5f);
durationTime = 2f;
}
else if (bufftype == BuffType.AddDefence)
{
fxPosTf = target.transform;
target.defence += value;
}
else if (bufftype == BuffType.RecoverHp)
{
target.OnDamage(-value, gameObject, true);
} //挂载buff特效
if (buffFx.ContainsKey(bufftype))
{
GameObject go = Resources.Load<GameObject>($"Skill/{buffFx[bufftype]}");
GameObject buffGo = GameObjectPool.I.CreateObject(buffFx[bufftype], go, fxPosTf.position, fxPosTf.rotation);
buffGo.transform.SetParent(fxPosTf);
GameObjectPool.I.Destory(buffGo, interval);
}
} //存储buff特效名称和对应buff类型
private static Dictionary<BuffType, string> buffFx = new Dictionary<BuffType, string>();
//初始化buff特效信息
public static void InitAllBuff()
{
buffFx.Add(BuffType.Burn,"Skill_32_R_Fly_100");
buffFx.Add(BuffType.Light,"Skill_75_Cast");
buffFx.Add(BuffType.Slow,"Skill_21_R_Fly_100");
buffFx.Add(BuffType.Poison,"Skill_12_R_Fly_100");
buffFx.Add(BuffType.AddDefence,"FX_CHAR_Aura");
buffFx.Add(BuffType.RecoverHp,"FX_Heal_Light_Cast");
} //获取buff剩余时间接口
public float GetRemainTime()
{
return durationTime - curTime;
} //buff结束恢复目标属性
private void OnDisable()
{
if (bufftype == BuffType.Slow)
;
else if (bufftype == BuffType.AddDefence)
target.defence -= value;
}
}

2.BuffIcon

buff图标类,显示倒计时数字显示;

这里写的不是很好,应该加载buffrun的同时加载bufficon,bufficon中不需要单独计时;

暂时改不动了=-=;

bufficon中添加buffRun字段,添加bufficon的同时,赋值buffrun;

通过buffrun获取buff类型和剩余倒计时;

这也用静态方法存储了bufficon的信息,用来动态加载,可以通过外部导入数据来存储;

public static Dictionary<BuffType, string> buffIconName = new Dictionary<BuffType, string>();

public static void InitBuffIconName()
{
buffIconName.Add(BuffType.Burn,"Buff_13");
buffIconName.Add(BuffType.Slow,"Buff_15");
buffIconName.Add(BuffType.Stun,"Buff_12");
buffIconName.Add(BuffType.Poison,"Buff_14");
buffIconName.Add(BuffType.BeatBack,"Buff_5");
buffIconName.Add(BuffType.BeatUp,"Buff_4");
buffIconName.Add(BuffType.Pull,"Buff_6");
buffIconName.Add(BuffType.AddDefence,"Buff_3");
buffIconName.Add(BuffType.RecoverHp,"Buff_7");
buffIconName.Add(BuffType.Light,"Buff_8");
}

这里写的不太行,参考一下吧;

public class BuffIcon : MonoBehaviour
{
public Text textCD;
public Image imgIcon; private float durationTime;
private float curTime; public BuffType buffType; public void LoadIcon(BuffType buffType, float duration)
{
durationTime = duration;
this.buffType = buffType;
Sprite[] temp = Resources.LoadAll<Sprite>("BuffIcon/Buff");
if (temp != null)
{
foreach (var sp in temp)
{
if (sp.name == SkillDeployer.buffIconName[buffType])
{
imgIcon.sprite = Instantiate(sp);
}
}
}
} private void OnEnable()
{
curTime = 0;
} void Update()
{
curTime += Time.deltaTime; textCD.text = (durationTime - curTime).ToString("F0"); if (curTime > durationTime)
{
gameObject.SetActive(false);
curTime = 0;
}
} public void Refresh()
{
//Debug.Log("已有buff刷新持续时间");
curTime = 0;
}
}

3.坑点

1.敌人uiPortrait的UI尽量不用使用延迟设置Active来控制显隐藏,Active为false时,bufficon将不再运行,等下次再显示uiPortrait时buff图标会显示错误;

2.采用每次造成伤害将当前目标的uiPortrait调整到显示位置,其他所有敌人的uiPortrait调整位置超出显示区域;

因此需要一个单例来存储所有的uiPortrait;就将它写在MonsterMgr中吧,反正也是用来管理敌人的,顺便管理一下敌人头像也没什么毛病;

提供三个方法,添加uiPortrait,删除uiPortrait,隐藏uiPortrait(移除显示区域);

private List<UIPortrait> allEnemyPortraits = new List<UIPortrait>();
public void AddEnemyPortraits(UIPortrait uiPortrait)
{
allEnemyPortraits.Add(uiPortrait);
}
public void RemoveEnemyPortraits(UIPortrait uiPortrait)
{
allEnemyPortraits.Remove(uiPortrait);
}
public void HideAllEnemyPortraits()
{
foreach (var it in allEnemyPortraits)
{
it.GetComponent<RectTransform>().anchoredPosition = hidePos;
}
}

4.扇形倒计时

UIbuff图标放置两层image组件物体,父节点设置透明度;

子物体image组件按下图设置,填充模式,填充百分比,以及顺逆时针;

代码动态设置fillAmount的百分比;

//技能倒计时举例,写在Update中
float cd = csm.skills[i].coolRemain;
skillImgs[i].fillAmount = 1 - cd / csm.skills[i].skill.coolTime;
skillTexts[i].text = cd.ToString("F0");
if (skillTexts[i].text == "0")
skillTexts[i].text = "";

效果:

Unity——技能系统(三)的更多相关文章

  1. Unity——技能系统(二)

    Unity技能系统(二) Unity技能系统(一) Demo展示: 五.技能管理和释放 1.CharacterSkillSystem 技能系统类,给外部(技能按钮,按键)提供技能释放方法: 技能释放逻 ...

  2. Unity——技能系统(一)

    技能系统(一) 一.Demo展示 二.功能介绍 集成了技能,冷却,buff,UI显示,倒计时,动画等: 技能类型:弹道技能,动画事件根据帧数采用延迟调用技能,自定义释放位置(偏移,发射点两种),buf ...

  3. Unity——射线系统

    Unity射线系统 Demo展示 UI+Physical射线测试: FPS自定义射线测试: UGUI射线工具 实现功能,鼠标点击UI,返回鼠标点击的UI对象: 需要使用到鼠标点击事件-PointerE ...

  4. 一个MMORPG的常规技能系统

    广义的的说,和战斗结算相关的内容都算技能系统,包括技能信息管理.技能调用接口.技能目标查找.技能表现.技能结算.技能创生体(buff/法术场/弹道)管理,此外还涉及的模块包括:AI模块(技能调用者). ...

  5. UGUI的优点新UI系统三效率高效果好

    UGUI的优点新UI系统三效率高效果好 通过对批处理(batching).纹理图集(texture atlasing)和新的canvas组件的支持,新UI系统提供了一个经过优化的解决方案,使得开发者添 ...

  6. python基础----以面向对象的思想编写游戏技能系统

    1. 许多程序员对面向对象的思想都很了解,并且也能说得头头是道,但是在工作运用中却用的并不顺手. 当然,我也是其中之一. 不过最近我听了我们老师的讲课,对于面向对象的思想有了更深的理解,今天决定用一个 ...

  7. Unity常见的三种数据本地持久化方案

    做游戏的时候常常会有数据配置或者存读档的需求,本文整理了常用的几种解决方案,分别是Unity自带的PlayerPrefs类,XML文件和Json文件. 一. PlayerPrefs 这是Unity自带 ...

  8. 三维软件转Unity的系统单位设置研究

    Unity的系统单位为米,其他3D软件的模型导入,而保持和Unity的比例一致是非常重要的,下面对各软件进行测试: ㈠. 3dsmax 转 Unity的比例为100:1:也就是说Unity单位是3ds ...

  9. Ubuntu Linux系统三种方法添加本地软件库

    闲着没事教教大家以Ubuntu Linux系统三种方法添加本地软件库,ubuntu Linux使用本地软件包作为安装源——转2007-04-26 19:47新手重新系统的概率很高,每次重装系统后都要经 ...

随机推荐

  1. iSCSI 服务器搭建

    一.简介 SCSI(Small Computer System Interface),小型计算机系统接口,是一种用于计算机及其周边设备之间(硬盘.软驱.光驱.打印机.扫描仪等)系统级接口的独立处理器标 ...

  2. P4929-[模板]舞蹈链(DLX)

    正题 题目链接:https://www.luogu.com.cn/problem/P4929 题目大意 \(n*m\)的矩形有\(0/1\),要求选出若干行使得每一列有且仅有一个\(1\). 解题思路 ...

  3. JVM学习笔记——栈区

    栈区 Stack Area 栈是运行时的单位,堆是存储单位,栈解决程序的运行问题,即程序如何执行,如何处理数据. 每个线程在创建时都创建一个该线程私有的虚拟机栈,每个栈里有许多栈帧,一个栈帧对应一个 ...

  4. vue3 专用 indexedDB 封装库,基于Promise告别回调地狱

    IndexedDB 的官网 https://developer.mozilla.org/zh-CN/docs/Web/API/IndexedDB_API 这个大概是官网吧,原始是英文的,现在陆续是出中 ...

  5. javascript-原生-面向对象

    1.javascript面向对象程序设计 概述:javascript不想其他面向对象编程语言那样有类的概念,javascript没有类(构造函数)的概念,只有对象的概念. 2.理解javascript ...

  6. Vue3学习(八)之 Vue CLI多环境配置

    一.前言 这里相对于之前就没那么麻烦了,通俗点说就是使用配置文件来管理多环境,实现环境的切换. 二.实现切换 1.增加开发和生产配置文件 在web的根目录下,创建开发环境切换配置文件.env.dev, ...

  7. 【UE4 C++ 基础知识】<13> 多线程——TaskGraph

    概述 TaskGraph 系统是UE4一套抽象的异步任务处理系统 TaskGraph 可以看作一种"基于任务的并行编程"设计思想下的实现 通过TaskGraph ,可以创建任意多线 ...

  8. Go语言核心36讲(Go语言进阶技术七)--学习笔记

    13 | 结构体及其方法的使用法门 我们都知道,结构体类型表示的是实实在在的数据结构.一个结构体类型可以包含若干个字段,每个字段通常都需要有确切的名字和类型. 前导内容:结构体类型基础知识 当然了,结 ...

  9. 什么是产品待办列表?(What is Product Backlog)

    正如scrum指南中所描述的,产品待办事项列表是一个紧急而有序的列表,其中列出了改进产品所需的内容.它是scrum团队承担的工作的唯一来源. 在sprint计划 (Sprint Planning)活动 ...

  10. 通过简单例子 | 快速理清 UML 中类与类的六大关系

    关于封面:我想我们都会离开 类与类之间的六大关系 泛化 ( Generalization ) ---> 表继承关系 实现 ( Realization ) 关联 ( Association ) 聚 ...