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

首頁 > 學院 > 開發設計 > 正文

Unity BuffSystem

2019-11-14 09:26:27
字體:
來源:轉載
供稿:網友
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 每個Buff系統類的每一種Buff效果基礎類;

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.然后舉例寫一個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.每個buff類型給予空物體,然后賦值給(1)的配置表 這里寫圖片描述

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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 汽车| 福泉市| 额济纳旗| 淮安市| 高尔夫| 双桥区| 颍上县| 麻江县| 洪洞县| 志丹县| 收藏| 太仆寺旗| 临澧县| 伊宁市| 昭平县| 瑞金市| 射阳县| 温泉县| 肥西县| 台州市| 泗洪县| 长治市| 饶平县| 故城县| 濮阳市| 平利县| 瓮安县| 湛江市| 贡觉县| 历史| 固安县| 阳原县| 凤翔县| 昭觉县| 阳春市| 厦门市| 即墨市| 那坡县| 项城市| 兰考县| 肇庆市|