从0动手撸moba之架构理论

编程入门 行业动态 更新时间:2024-10-10 00:23:13

从0动手撸moba之<a href=https://www.elefans.com/category/jswz/34/1771112.html style=架构理论"/>

从0动手撸moba之架构理论

笔者最爱玩的手游王者荣耀。最近也是研究王者荣耀的战斗设计,林林种种的有一些自己的想法,分享出来,后续会陆陆续续把完整的设计方案思路写出来,希望能与大家一起讨论。水平有限,望高人指点,谢谢!

 Moba当中有英雄,小兵,塔,野怪等。这些在设计当中我统一都叫Entity。类似Ecs,我们这个Entity都会挂着数据和组件。组件是进行逻辑操作,这样就能达到很高的解耦。组件与组件间如果想进行通信,一种做法是Entity提供获取组件得能力,一种是Entity本身有个事件管理器,通过注册事件->触发来实现。这二种都实现了,第一种写代码的时候方便些,但会产生依赖,第二种解耦。同样的每个Entity之间通信需要用事件来处理。

具体如下:

public abstract class BaseEntity : MonoBehaviour,IPool
{protected Dictionary<ComponentType, BaseComponent> m_Components = new Dictionary<ComponentType, BaseComponent>();protected Dictionary<DataType, BaseData> m_Datas = new Dictionary<DataType, BaseData>();public EventComponent EntityEvent;public SelfCompEventComponent SelfCompEvent;public bool m_IsAlive;public abstract EntityType GetEntityType();public abstract CampType GetCampType();public virtual void OnInit(params object[] args){EntityEvent = TryAddComponent(ComponentType.Event) as EventComponent;SelfCompEvent = TryAddComponent(ComponentType.SelfCompEvent) as SelfCompEventComponent;OnEntityLoad(args);}public virtual void OnEntityLoad(params object[] args){}public BaseComponent TryAddComponent(ComponentType componentType,params object[] args){if (m_Components.ContainsKey(componentType))return m_Components[componentType];BaseComponent component = PoolManager.Instance.GetComponent(componentType,this, args);m_Components[componentType] = component;return component;}public BaseData TryAddData(DataType dataType,params object[] args){if (m_Datas.ContainsKey(dataType))return m_Datas[dataType] ;BaseData data = PoolManager.Instance.GetData(dataType, args);m_Datas[dataType] = data;return data;}public T GetComponent<T>(ComponentType type) where T : BaseComponent{if (!m_Components.ContainsK

更多推荐

从0动手撸moba之架构理论

本文发布于:2024-03-09 12:38:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1724989.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   理论   moba

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!