private void ImportShader(object sender, RoutedEventArgs e) { ImportShader import = new ImportShader(); var result = import.ShowDialog(); if (result == true) { AssetMetadata.createShaderMetadata(import.asset); viewmodel.Shaders.Add(import.asset); } else { if (!string.IsNullOrEmpty(import.Error)) { viewmodel.LogEvent(import.Error); } } }
private void EditShader(object sender, RoutedEventArgs e) { if (viewmodel.SelectedShader == null) { return; } string oldName = viewmodel.SelectedShader.Name; string oldImported = viewmodel.SelectedShader.ImportedFilename; string oldSource = viewmodel.SelectedShader.SourceFilename; ImportShader import = new ImportShader(); import.setAsset(viewmodel.SelectedShader); import.isEditMode = true; var result = import.ShowDialog(); if (result == true) { if (oldName != import.asset.Name) { var newName = import.asset.Name; import.asset.Name = oldName; //we changed the name, delete the old asset then create a new one System.IO.File.Delete(oldImported); import.asset.Name = newName; } } else { if (!string.IsNullOrEmpty(import.Error)) { viewmodel.LogEvent(import.Error); } } }
public static bool UpdateAsset(Object asset, out string error, out string successMessage) { error = ""; successMessage = ""; if (asset is MeshAsset) { MeshAsset mesh = asset as MeshAsset; var result = ImportMesh.import(mesh.SourceFilename, mesh.ImportedFilename); if (string.IsNullOrEmpty(result)) { successMessage = "Successfully updated mesh: " + mesh.Name; mesh.LastUpdated = DateTime.Now; AssetMetadata.createMeshMetadata(mesh); return(true); } } else if (asset is TextureAsset) { TextureAsset texture = asset as TextureAsset; var result = ImportTexture.import(texture.Format, texture.ChannelMappings, texture.ImportedFilename); if (string.IsNullOrEmpty(result)) { successMessage = "Successfully updated texture: " + texture.Name; texture.LastUpdated = DateTime.Now; AssetMetadata.createTextureMetadata(texture); return(true); } else { error = "ERROR: Updating texture: " + texture.Name + " failed!" + Environment.NewLine + result; } } else if (asset is ShaderAsset) { ShaderAsset shader = asset as ShaderAsset; var result = ImportShader.import(shader.SourceFilename, shader.ImportedFilename); if (string.IsNullOrEmpty(result)) { successMessage = "Successfully updated shader: " + shader.Name; shader.LastUpdated = DateTime.Now; AssetMetadata.createShaderMetadata(shader); return(true); } else { error = "ERROR: Updating shader: " + shader.Name + " failed!" + Environment.NewLine + result; } } else if (asset is MaterialAsset) { MaterialAsset material = asset as MaterialAsset; var result = MaterialImporter.Import(material); if (result) { successMessage = "Successfully updated material: " + material.Name; material.LastUpdated = DateTime.Now; AssetMetadata.createMaterialMetadata(material); return(true); } else { error = "ERROR: Updating material: " + material.Name + " failed!" + Environment.NewLine; } } else if (asset is StateGroupAsset) { var stateGroup = asset as StateGroupAsset; var result = StateGroupImporter.Import(stateGroup); if (result) { successMessage = "Successfully updated state group: " + stateGroup.Name; stateGroup.LastUpdated = DateTime.Now; AssetMetadata.createStateGroupMetadata(stateGroup); return(true); } else { error = "ERROR: Updating state group: " + stateGroup.Name + " failed!" + Environment.NewLine + result; } } return(false); }