[Unity]BuffDebuffSystem增益减益系统(1)
发布日期:2021-05-09 11:56:13 浏览次数:23 分类:技术文章

本文共 3777 字,大约阅读时间需要 12 分钟。

BuffControl.cs有update函数不停的判断,调用。

BuffManage.cs里面含有BuffControl.cs判断的函数参数条件,并且可以随时改变,调用参数。

BloodBuff : Buff,public override void BuffFunction函数里面放类型 的函数的判断条件,判断 player_gameObject 的角色属性 是否符合条件,并且 BUFF是否在  player_gameObject 的角色 脚本里面 的List<Buff>,遍历List<Buff> 改变角色属性的函数,使其 BUFF改变角色属性 的函数 仅且执行1次,满足移除BUFF条件 。

或者是 把相关火焰参数的BUFF 放入BuffManage.cs的火焰list中,当火焰参数发生变化,增加或者减少的时候,就调用BuffManage.cs的火焰list遍历一遍,判断 相关的火焰参数的BUFF是否生效。

----------------------------------------------------代码

BuffManage.cs

using System.Collections;using System.Collections.Generic;using UnityEngine;public class BuffManage : MonoBehaviour {    #region Singleton    public static BuffManage instance;    private void Awake()    {        instance = this;    }    #endregion    public List
list_buff = new List
(); public void ForeachListBuffBool(bool IsEffect) { for (int i=0; i

Buff.cs

using UnityEngine;//.cs脚本 继承ScriptableObject,才能使得 CreateAssetMenu 生效[CreateAssetMenu(fileName = "New Buff", menuName = "Buff/Create Empty Buff")]public class Buff : ScriptableObject{    public string BuffName;    public int CharacterDamage;    public int CharacterArmor;    public bool isEffect = false;    public virtual void BuffFunction(GameObject player_gameobject)    {        //use the item        Debug.Log("    BuffFunction:" + BuffName);    }    public virtual void EffectBuff(GameObject player_gameobject)    {        //use the item        Debug.Log("    EffectBuff:"+ BuffName);    }    public virtual void FailureBuff(GameObject player_gameobject)    {        //use the item        Debug.Log("    FailureBuff:" + BuffName);    }    public virtual void Tooltip()    {        //tool tip buff    }}
 

BloodBuff.cs

using System.Collections;using System.Collections.Generic;using UnityEngine;[CreateAssetMenu(fileName = "New Equipment", menuName = "Buff/Create Buff/BloodBuff")]public class BloodBuff : Buff{    public override void BuffFunction(GameObject player_gameobject)    {        base.BuffFunction(player_gameobject);        Debug.Log("BloodBuff    BuffFunction:" + BuffName);        if(isEffect == false)        {            FailureBuff(player_gameobject);        }                if (isEffect == true)        {            EffectBuff(player_gameobject);        }    }    public override void EffectBuff(GameObject player_gameobject)    {        base.EffectBuff(player_gameobject);        Debug.Log("BloodBuff    EffectBuff:" + BuffName);    }    public override void FailureBuff(GameObject player_gameobject)    {        base.FailureBuff(player_gameobject);        Debug.Log("BloodBuff    FailureBuff:" + BuffName);    }}

BuffControl.cs

using System.Collections;using System.Collections.Generic;using UnityEngine;public class BuffControl : MonoBehaviour {    private BuffManage buffManage;    public GameObject player_gameObject;	// Use this for initialization	void Start () {        buffManage = BuffManage.instance;    }		// Update is called once per frame	void Update () {        ForeachList_Buff();    }    private void ForeachList_Buff()    {        Buff[] array_buff = buffManage.list_buff.ToArray();        for (int i=0; i< array_buff.Length ;i++)        {            if (player_gameObject != null)            {                array_buff[i].BuffFunction(player_gameObject);            }        }    }}
 

Buff_Button.cs

using System.Collections;using System.Collections.Generic;using UnityEngine;public class Buff_Button : MonoBehaviour {    public void Button_EffectBuff()//Trigger buff    {        Debug.Log("Button_EffectBuff");        BuffManage.instance.ForeachListBuffBool(true);    }    public void Button_FailureBuff()//Trigger buff    {        Debug.Log("Button_FailureBuff");        BuffManage.instance.ForeachListBuffBool(false);    }}

相关资源1,持续时间的BUFF的源码

相关资源:

1.

2.

3.

转载地址:https://blog.csdn.net/BuladeMian/article/details/80644582 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:[Unity]string.Format的用法
下一篇:[Unity][C#代码技巧]灵活运用VC的注释

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年07月15日 13时05分30秒