架构理论"/>
从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之架构理论
发布评论