public void SetCell(HexagonsWithCenter cells) { RemoveCell(); position = cells.center.entityStandPosition; centerCell = cells.center; m_Cells.AddRange(cells.allCells); foreach (HexCell cell in cells.allCells) { cell.SetEntity(this); } }
/// <summary> /// 出生 /// </summary> public void Born(HexagonsWithCenter cells) { if (entityState == EntityState.PendingBorn) { SetCell(cells); entityState = EntityState.Alive; GameEvent.EntityEvent.FireOnBeforeEntityBorn(this); OnBorn(); GameEvent.EntityEvent.FireOnEntityBorn(this); } }
public Entity Create(string keyName, RoomInstance room, HexCell cell, BaseParams param) { JEntityConfig config = GetEntityConfig(keyName); if (config == null) { Debug.LogError("找不到名为 " + keyName + "的EntityConfig"); return(null); } Type type = config.entityType; if (type == null) { Debug.LogError(keyName + " 找不到类型 " + config.type); return(null); } EntityModel entityModel = EntityModelManager.instance.GetEntityModel(config.entityModel); if (entityModel == null) { Debug.LogError("找不到 " + keyName + "的EntityModel " + config.entityModel); return(null); } HexagonsWithCenter cells = room.hexRoom.FindClearCellsInRange(config.size, cell, -1); if (cells == null) { Debug.LogError("找不到出生点!对象" + keyName); return(null); } //保证Y轴 uint oid = 0; do { oid = GuidCreator.GetOid(); }while (m_EntityDict.ContainsKey(oid)); Entity entity = Entity.CreateEntity(type, oid, keyName, config, entityModel, cells, param); if (entity != null) { m_EntityDict.Add(entity.oid, entity); room.AddEntity(entity); entity.Born(cells); } return(entity); }
static public Entity CreateEntity(Type type, uint oid, string keyName, JEntityConfig config, EntityModel entityModel, HexagonsWithCenter cells, BaseParams param) { GameObject entityObj = new GameObject(); EntityModel model = GameObject.Instantiate <GameObject>(entityModel.gameObject).GetComponent <EntityModel>(); Entity entity = entityObj.AddComponent(type) as Entity; if (entity.Initialize(oid, keyName, config, model, cells, param)) { return(entity); } else { return(null); } }
static public TEntity CreateEntity <TEntity>(uint oid, string keyName, JEntityConfig config, EntityModel entityModel, HexagonsWithCenter cells, BaseParams param) where TEntity : Entity { Entity e = CreateEntity(typeof(TEntity), oid, keyName, config, entityModel, cells, param); if (e == null) { return(null); } else { return(e as TEntity); } }
public bool Initialize(uint oid, string keyName, JEntityConfig config, EntityModel entityModel, HexagonsWithCenter cells, BaseParams param) { gameObject.layer = LayerMask.NameToLayer(Layers.entity); this.oid = oid; this.keyName = keyName; gameObject.name = keyName + "_" + oid; entityState = EntityState.PendingCreate; m_Config = config; modelComponent = AddEntityComponent <ModelComponent>(); modelComponent.SetModel(entityModel); if (OnInitialize(config, param) && OnCreateComponent()) { CreateComponentComplete(); entityState = EntityState.PendingBorn; return(true); } else { Debug.LogError("初始化" + keyName + "失败"); entityState = EntityState.Dead; return(false); } }