Example #1
0
        private void GetNearestCell()
        {
            var cellsEntities = _entityManager.Entities.WithComponent <BuildingZoneCellComponent>();

            foreach (var cellEntity in cellsEntities)
            {
                var cell = cellEntity.GetComponent <BuildingZoneCellComponent>();

                if (_nearestCellEntity != null && _nearestCell == cell)
                {
                    continue;
                }

                var playerForwardPosition = _playerHeroTransform.position + _playerHeroTransform.forward;
                var distance = Vector3.Distance(playerForwardPosition, cell.Position);
                if (distance > _configs.CellSize || distance > _nearestCellDistance)
                {
                    continue;
                }

                var cellFloorComponent = cellEntity.GetComponent <FloorComponent>();
                if (cellFloorComponent != null)
                {
                    continue;
                }

                if (_nearestCellEntity != null)
                {
                    AddBuildingCellSceneObject();
                }

                _nearestCellDistance = distance;
                _nearestCellEntity   = cellEntity;
                _nearestCell         = cell;

                _nearestCellEntity.RemoveComponents <SceneObjectComponent>();
                _nearestCellEntity.AddComponent(new SceneObjectComponent(_configs.FloorCanBuildedPrefab, cell.Position));
            }
        }
Example #2
0
 private void ClearNearestCell()
 {
     _nearestCellEntity   = null;
     _nearestCell         = null;
     _nearestCellDistance = float.MaxValue;
 }