国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Unity BuffSystem

2019-11-14 10:07:54
字體:
供稿:網(wǎng)友
1. 寫好Unity的BuffSystem的單例主要接口using UnityEngine;using System.Collections;using Police.PaoKu;using DG.Tweening;public class BuffSystem : Singleton<BuffSystem> { public BUFFType buffChoose; public Buff[] _buffSystem; public void InvokeCallBack(BUFFType _buffType , float delayTime = 0) { DOVirtual.DelayedCall(delayTime,()=> { foreach (var o in _buffSystem) { if (o.buffType == _buffType) { o.callBack.GetComponent<BaseBuff>().Begin(new string[1] { _buffType.ToString() }); break; } } }).SetUpdate(false); } public bool ReleaseBuff(BUFFType _buffType) { foreach (var o in _buffSystem) { if (o.buffType == _buffType) { o.callBack.GetComponent<BaseBuff>().Exit(); return true; } } return false; }}public enum BUFFType{ 普通, 助推器, 盾, 免疫}[System.Serializable]public class Buff{ public BUFFType buffType; public GameObject callBack;}

2.寫好Unity 每個(gè)Buff系統(tǒng)類的每一種Buff效果基礎(chǔ)類;

using UnityEngine;using System.Collections;using System;public class BaseBuff : MonoBehaviour ,iperiod{ public float lifeTime; public float lastTime; public bool isDestroy = false; PRotected bool isBegin; public virtual void Begin(string[] _str) { isBegin = true; lastTime = lifeTime; } public virtual void Exit() { isBegin = false; lifeTime = lastTime; if (isDestroy) DestroyImmediate(this); } protected virtual void Update() { if(isBegin) lifeTime -= Time.deltaTime; if(lifeTime < 0) { Exit(); } }}public interface IPeriod{ void Begin(string[] _str); void Exit();}

3.然后舉例寫一個(gè)buff類型例子

using UnityEngine;using System.Collections;using Police.PaoKu;public class SubDefend : BaseBuff{ public override void Begin(string[] _str) { base.Begin(_str); ParkourPlayerController.Instance.Player.gameObject.AddComponent<Defend>(); } public override void Exit() { base.Exit(); Destroy(ParkourPlayerController.Instance.Player.GetComponent<Defend>()); }}

4.每個(gè)buff類型給予空物體,然后賦值給(1)的配置表 這里寫圖片描述

5.這樣的優(yōu)勢是容易擴(kuò)展,可以理解成工廠模式,而且改變每個(gè)buff代碼互不影響。


上一篇:圖論

下一篇:代碼塊

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 二连浩特市| 建昌县| 穆棱市| 卓资县| 东宁县| 佛教| 南漳县| 岑巩县| 连山| 肃宁县| 定结县| 四会市| 上杭县| 梁河县| 台前县| 中阳县| 修武县| 辽中县| 合阳县| 达州市| 尚义县| 任丘市| 法库县| 二手房| 达日县| 溧水县| 保亭| 新竹县| 鄯善县| 手机| 云林县| 崇文区| 滨州市| 吴江市| 建始县| 正定县| 黎城县| 塘沽区| 丰原市| 合阳县| 遵义市|