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——技能系统(三)的更多相关文章
- Unity——技能系统(二)
Unity技能系统(二) Unity技能系统(一) Demo展示: 五.技能管理和释放 1.CharacterSkillSystem 技能系统类,给外部(技能按钮,按键)提供技能释放方法: 技能释放逻 ...
- Unity——技能系统(一)
技能系统(一) 一.Demo展示 二.功能介绍 集成了技能,冷却,buff,UI显示,倒计时,动画等: 技能类型:弹道技能,动画事件根据帧数采用延迟调用技能,自定义释放位置(偏移,发射点两种),buf ...
- Unity——射线系统
Unity射线系统 Demo展示 UI+Physical射线测试: FPS自定义射线测试: UGUI射线工具 实现功能,鼠标点击UI,返回鼠标点击的UI对象: 需要使用到鼠标点击事件-PointerE ...
- 一个MMORPG的常规技能系统
广义的的说,和战斗结算相关的内容都算技能系统,包括技能信息管理.技能调用接口.技能目标查找.技能表现.技能结算.技能创生体(buff/法术场/弹道)管理,此外还涉及的模块包括:AI模块(技能调用者). ...
- UGUI的优点新UI系统三效率高效果好
UGUI的优点新UI系统三效率高效果好 通过对批处理(batching).纹理图集(texture atlasing)和新的canvas组件的支持,新UI系统提供了一个经过优化的解决方案,使得开发者添 ...
- python基础----以面向对象的思想编写游戏技能系统
1. 许多程序员对面向对象的思想都很了解,并且也能说得头头是道,但是在工作运用中却用的并不顺手. 当然,我也是其中之一. 不过最近我听了我们老师的讲课,对于面向对象的思想有了更深的理解,今天决定用一个 ...
- Unity常见的三种数据本地持久化方案
做游戏的时候常常会有数据配置或者存读档的需求,本文整理了常用的几种解决方案,分别是Unity自带的PlayerPrefs类,XML文件和Json文件. 一. PlayerPrefs 这是Unity自带 ...
- 三维软件转Unity的系统单位设置研究
Unity的系统单位为米,其他3D软件的模型导入,而保持和Unity的比例一致是非常重要的,下面对各软件进行测试: ㈠. 3dsmax 转 Unity的比例为100:1:也就是说Unity单位是3ds ...
- Ubuntu Linux系统三种方法添加本地软件库
闲着没事教教大家以Ubuntu Linux系统三种方法添加本地软件库,ubuntu Linux使用本地软件包作为安装源——转2007-04-26 19:47新手重新系统的概率很高,每次重装系统后都要经 ...
随机推荐
- 单机百万连接调优和Netty应用级别调优
作者:Grey 原文地址:单机百万连接调优和Netty应用级别调优 说明 本文为深度解析Netty源码的学习笔记. 单机百万连接调优 准备两台Linux服务器,一个充当服务端,一个充当客户端. 服务端 ...
- iOS Swift逻辑运算符
运算符 运算符分类 从操作数角度看:运算符包括一元.二元.三元.这里的一二三指操作数的数量,操作数指的是被操作的数值. 从运算符位置看:运算符分为前缀.中缀.后缀.例如:!b, b + c, c! 赋 ...
- xLua自定义加载器
xLua入门基础 环境配置 github下载xLua文件: xLua是腾讯开发,据说比较先进: 下载下来后将Plugins和XLua文件夹考进项目: Plugins多平台权限:XLua和C#交互: t ...
- docker采用registry部署简易仓库
解释:registry部署简易仓库,实现免密上传拉取镜像(解决不在一个容器里,也能够实现镜像拉取成功) 1.安装启动registry服务 docker pull registry docker run ...
- C++类结构体与json相互转换
1. 背景与需求 之前写C#的时候,解析json字符串一般使用的是开源的类库Newtonsoft.Json,方法十分简洁,比如: class Project { public string Input ...
- SudokuSolver 2.0:用C++实现的数独解题程序 【一】
SudokuSolver 2.0 实现效果 H:\Read\num\Release>sudoku.exe Order please: Sudoku Solver 2.0 2021/10/2 by ...
- Java(21)内部类
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228411.html 博客主页:https://www.cnblogs.com/testero ...
- 成功在Caterpillar代码中插入事件对象-20200917
首先搞清楚了Caterpillar的solidity代码生成机制.Caterpillar分为Caterpillar Core和 executepanel两部分. executePanel是UI前端,用 ...
- OO第四单元UML作业总结暨OO课程总结
目录 目录一.第四单元UML两次作业架构设计第一次作业第二次作业二.架构设计总结与OO方法理解演进三.测试理解与实践演进四.课程收获总结五.课程改进建议六.尾声 一.第四单元UML两次作业架构设计 第 ...
- Noip模拟29(瞎眼忌) 2021.8.3
T1 最长不下降子序列 在此记录自己的瞎眼... 考场上像一个傻$der$,自己为了防范上升序列和不下降序列的不同特意的造了一组$hack$数据来卡自己:(第一行是序列长度,第二行是序列) 6 1 5 ...