SEToolbox.Models.ImportVoxelModel.Load C# (CSharp) Method

Load() public method

public Load ( VRage.MyPositionAndOrientation characterPosition ) : void
characterPosition VRage.MyPositionAndOrientation
return void
        public void Load(MyPositionAndOrientation characterPosition)
        {
            CharacterPosition = characterPosition;

            var vms = SpaceEngineersCore.Resources.VoxelMapStorageDefinitions;
            var contentPath = ToolboxUpdater.GetApplicationContentPath();

            foreach (var voxelMap in vms)
            {
                var fileName = SpaceEngineersCore.GetDataPathOrDefault(voxelMap.StorageFile, Path.Combine(contentPath, voxelMap.StorageFile));

                if (!File.Exists(fileName))
                    continue;

                var voxel = new GenerateVoxelDetailModel
                {
                    Name = Path.GetFileNameWithoutExtension(voxelMap.StorageFile),
                    SourceFilename = fileName,
                    FileSize = new FileInfo(fileName).Length,
                    Size = MyVoxelMap.LoadVoxelSize(fileName)
                };
                VoxelFileList.Add(voxel);
            }

            // Custom voxel files directory.
            List<string> files = new List<string>();
            if (!string.IsNullOrEmpty(GlobalSettings.Default.CustomVoxelPath) && Directory.Exists(GlobalSettings.Default.CustomVoxelPath))
            {
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V1FileExtension));
                files.AddRange(Directory.GetFiles(GlobalSettings.Default.CustomVoxelPath, "*" + MyVoxelMap.V2FileExtension));
            }

            VoxelFileList.AddRange(files.Select(file => new GenerateVoxelDetailModel
            {
                Name = Path.GetFileNameWithoutExtension(file),
                SourceFilename = file,
                FileSize = new FileInfo(file).Length,
                Size = MyVoxelMap.LoadVoxelSize(file)
            }));


            VoxelFileList = VoxelFileList.OrderBy(s => s.Name).ToList();
        }

Usage Example

コード例 #1
0
        public void ImportVoxelExecuted()
        {
            var model = new ImportVoxelModel();
            var position = ThePlayerCharacter != null ? ThePlayerCharacter.PositionAndOrientation.Value : new MyPositionAndOrientation(Vector3D.Zero, Vector3.Forward, Vector3.Up);
            model.Load(position);
            var loadVm = new ImportVoxelViewModel(this, model);

            var result = _dialogService.ShowDialog<WindowImportVoxel>(this, loadVm);
            if (result == true)
            {
                IsBusy = true;
                var newEntity = loadVm.BuildEntity();
                var structure = _dataModel.AddEntity(newEntity);
                ((StructureVoxelModel)structure).SourceVoxelFilepath = loadVm.SourceFile; // Set the temporary file location of the Source Voxel, as it hasn't been written yet.
                if (_preSelectedStructure != null)
                    SelectedStructure = _preSelectedStructure;
                IsBusy = false;
            }
        }
ImportVoxelModel