/// <summary> /// 实例化实体 /// </summary> /// <param name="container"></param> /// <param name="type"></param> /// <param name="entityName"></param> /// <returns></returns> public static Entity Create(EntityContainer container, DataTag dataTag) { var entityObj = new GameObject(dataTag.Get <string>("name")); var entity = entityObj.AddComponent <Entity>(); container.Add(entity); entity.Owner = container; entity.SetEntityData(dataTag); if (entity.IsSelectable) { entityObj.layer = SelectableLayer; } else { entityObj.layer = Layer; } return(entity); }
/// <summary> /// 设置实体数据 /// </summary> /// <param name="entityData"></param> public void SetEntityData(DataTag entityData) { // 设置代理 var entityProxyName = entityData.Get <string>("type"); // 创建行为 _entityProxy = GameManager.ProxyManager.Get <IEntity>(entityProxyName); foreach (var entityBehaviour in _entityProxy.EntityBehaviours) { if (gameObject.GetComponent(entityBehaviour) == null) { gameObject.AddComponent(entityBehaviour); } } gameObject.SendMessage("OnEntityCreated"); // 同步标签 _entityDataTag = entityData; // 加载 LoadFromEntityData(); }