private IEntityModel SpawnEntity(int x, int y, ref GameObject lastRandomPrefab) { var position = FieldDimensionModel.GetFieldWorldPosition(new Vector2Int(x, y)); var randomPrefab = ConfigModel.EntityPtototypes.Random(lastRandomPrefab); lastRandomPrefab = randomPrefab; var entity = GameObjectFactory.Instantiate(randomPrefab, position); var entityController = entity.GetComponent <IEntityController>(); var entityModel = new EntityModel(Array.IndexOf(ConfigModel.EntityPtototypes, randomPrefab)); //TODO: в фабрику entityController.Model = entityModel; FieldModel.Entities.Add(entityModel); EntityMapperService.Add(entityModel, entityController); MessageSender.Send(new SpawnEntityMessage { Entity = entityModel }); return(entityModel); }
private IEnumerator Tick() { var loadingAsync = _gameObjectFactory.Load(AddressablePrefab.GridCell); while (loadingAsync.MoveNext()) { yield return(null); } var gridCell = loadingAsync.Current; for (var i = 0; i < FieldLength; i++) { for (var j = 0; j < FieldWidth; j++) { var instantiatedGridCell = _gameObjectFactory.Instantiate(gridCell); var implementors = new List <IImplementor>(); instantiatedGridCell.GetComponentsInChildren(true, implementors); _entityFactory.BuildEntity <GridCellEntityDescriptor>((uint)instantiatedGridCell.GetInstanceID(), EcsGroups.GridGroup, implementors); instantiatedGridCell.transform.position = new Vector3(-FieldLength / 2 + i, 0, -FieldWidth / 2 + j); } } }