本文整理汇总了C#中SiliconStudio.Core.IO.UFile类的典型用法代码示例。如果您正苦于以下问题:C# UFile类的具体用法?C# UFile怎么用?C# UFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UFile类属于SiliconStudio.Core.IO命名空间,在下文中一共展示了UFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestUpdateAssetUrl
public void TestUpdateAssetUrl()
{
var projectDir = new UFile(Path.Combine(Environment.CurrentDirectory, "testxk"));
// Create a project with an asset reference a raw file
var project = new Package { FullPath = projectDir };
var assetItem = new AssetItem("test", new AssetObjectTest() { Reference = new AssetReference<AssetObjectTest>(Guid.Empty, "good/location")});
project.Assets.Add(assetItem);
var goodAsset = new AssetObjectTest();
project.Assets.Add(new AssetItem("good/location", goodAsset));
// Add the project to the session to make sure analysis will run correctly
var session = new PackageSession(project);
// Create a session with this project
var analysis = new PackageAnalysis(project,
new PackageAnalysisParameters()
{
IsProcessingAssetReferences = true,
ConvertUPathTo = UPathType.Absolute,
IsProcessingUPaths = true
});
var result = analysis.Run();
Assert.IsFalse(result.HasErrors);
Assert.AreEqual(1, result.Messages.Count);
Assert.IsTrue(result.Messages[0].ToString().Contains("changed"));
var asset = (AssetObjectTest)assetItem.Asset;
Assert.AreEqual(goodAsset.Id, asset.Reference.Id);
Assert.AreEqual("good/location", asset.Reference.Location);
}
示例2: AssetToImport
/// <summary>
/// Initializes a new instance of the <see cref="AssetToImport"/> class.
/// </summary>
/// <param name="file">The file.</param>
/// <exception cref="System.ArgumentNullException">file</exception>
internal AssetToImport(UFile file)
{
if (file == null) throw new ArgumentNullException("file");
this.file = file;
ByImporters = new List<AssetToImportByImporter>();
Enabled = true;
}
示例3: GetAbsolutePath
/// <summary>
/// Returns the absolute path on the disk of an <see cref="UFile"/> that is relative to the asset location.
/// </summary>
/// <param name="assetItem">The asset on which is based the relative path.</param>
/// <param name="relativePath">The path relative to the asset path that must be converted to an absolute path.</param>
/// <returns>The absolute path on the disk of the <see cref="relativePath"/> argument.</returns>
/// <exception cref="ArgumentException">The <see cref="relativePath"/> argument is a null or empty <see cref="UFile"/>.</exception>
protected static UFile GetAbsolutePath(AssetItem assetItem, UFile relativePath)
{
if (string.IsNullOrEmpty(relativePath)) throw new ArgumentException("The relativePath argument is null or empty");
var assetDirectory = assetItem.FullPath.GetParent();
var assetSource = UPath.Combine(assetDirectory, relativePath);
return assetSource;
}
示例4: ImportScene
public static EntityHierarchyData ImportScene(UFile sourceUrl, EntityGroupAssetBase source, Guid sourceRootEntity)
{
if (source == null) throw new ArgumentNullException("source");
// Extract the scene starting from given root
var newAsset = ExtractSceneClone(source, sourceRootEntity);
// Generate entity mapping
var reverseEntityMapping = new Dictionary<Guid, Guid>();
foreach (var entityDesign in newAsset.Hierarchy.Entities)
{
// Generate new Id
var newEntityId = Guid.NewGuid();
// Update mappings
reverseEntityMapping.Add(entityDesign.Entity.Id, newEntityId);
// Update entity with new id
entityDesign.Entity.Id = newEntityId;
}
// Rewrite entity references
// Should we nullify invalid references?
EntityAnalysis.RemapEntitiesId(newAsset.Hierarchy, reverseEntityMapping);
return newAsset.Hierarchy;
}
示例5: Load
public object Load(Stream stream, UFile filePath, ILogger log, out bool aliasOccurred, out Dictionary<YamlAssetPath, OverrideType> overrides)
{
PropertyContainer properties;
var result = AssetYamlSerializer.Default.Deserialize(stream, null, log != null ? new SerializerContextSettings { Logger = log } : null, out aliasOccurred, out properties);
properties.TryGetValue(AssetObjectSerializerBackend.OverrideDictionaryKey, out overrides);
return result;
}
示例6: Load
public object Load(Stream stream, UFile filePath, ILogger log, out bool aliasOccurred, out Dictionary<YamlAssetPath, OverrideType> overrides)
{
aliasOccurred = false;
var assetFileExtension = filePath.GetFileExtension().ToLowerInvariant();
var type = AssetRegistry.GetAssetTypeFromFileExtension(assetFileExtension);
var asset = (SourceCodeAsset)Activator.CreateInstance(type);
var textAccessor = asset.TextAccessor as SourceCodeAsset.DefaultTextAccessor;
if (textAccessor != null)
{
// Don't load the file if we have the file path
textAccessor.FilePath = filePath;
// Set the assets text if it loaded from an in-memory version
// TODO: Propagate dirtiness?
if (stream is MemoryStream)
{
var reader = new StreamReader(stream, Encoding.UTF8);
textAccessor.Set(reader.ReadToEnd());
}
}
// No override in source code assets
overrides = new Dictionary<YamlAssetPath, OverrideType>();
return asset;
}
示例7: IsSupportingFile
public static bool IsSupportingFile(this IAssetImporter importer, UFile file)
{
if (file == null) throw new ArgumentNullException("file");
if (file.GetFileExtension() == null) return false;
return FileUtility.GetFileExtensionsAsSet(importer.SupportedFileExtensions).Contains(file.GetFileExtension());
}
示例8: DoCommandOverride
protected override Task<ResultStatus> DoCommandOverride(ICommandContext commandContext)
{
// This path for effects xml is now part of this tool, but it should be done in a separate exporter?
using (var inputStream = File.OpenRead(SourcePath))
using (var outputStream = AssetManager.FileProvider.OpenStream(Location, VirtualFileMode.Create, VirtualFileAccess.Write))
{
inputStream.CopyTo(outputStream);
var objectURL = new ObjectUrl(UrlType.ContentLink, Location);
if (DisableCompression)
commandContext.AddTag(objectURL, DisableCompressionSymbol);
}
if (SaveSourcePath)
{
// store absolute path to source
// TODO: the "/path" is hardcoded, used in EffectSystem and ShaderSourceManager. Find a place to share this correctly.
var pathLocation = new UFile(Location.FullPath + "/path");
using (var outputStreamPath = AssetManager.FileProvider.OpenStream(pathLocation, VirtualFileMode.Create, VirtualFileAccess.Write))
{
using (var sw = new StreamWriter(outputStreamPath))
{
sw.Write(SourcePath.FullPath);
}
}
}
return Task.FromResult(ResultStatus.Successful);
}
示例9: SettingsEntry
/// <summary>
/// Initializes a new instance of the <see cref="SettingsEntry"/> class.
/// </summary>
/// <param name="profile">The profile this <see cref="SettingsEntry"/>belongs to.</param>
/// <param name="name">The name associated to this <see cref="SettingsEntry"/>.</param>
protected SettingsEntry(SettingsProfile profile, UFile name)
{
if (profile == null) throw new ArgumentNullException("profile");
if (name == null) throw new ArgumentNullException("name");
Profile = profile;
Name = name;
}
示例10: IsSupportingFile
public virtual bool IsSupportingFile(string filePath)
{
if (filePath == null) throw new ArgumentNullException("filePath");
var file = new UFile(filePath);
if (file.GetFileExtension() == null) return false;
return FileUtility.GetFileExtensionsAsSet(SupportedFileExtensions).Contains(file.GetFileExtension());
}
示例11: SettingsKey
/// <summary>
/// Initializes a new instance of the <see cref="SettingsKey"/> class.
/// </summary>
/// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
/// <param name="container">The <see cref="SettingsContainer"/> containing this <see cref="SettingsKey"/>.</param>
/// <param name="defaultValue">The default value associated to this settings key.</param>
protected SettingsKey(UFile name, SettingsContainer container, object defaultValue)
{
Name = name;
DisplayName = name;
DefaultObjectValue = defaultValue;
Container = container;
Container.RegisterSettingsKey(name, defaultValue, this);
}
示例12: PackageLoadingAssetFile
/// <summary>
/// Initializes a new instance of the <see cref="PackageLoadingAssetFile" /> class.
/// </summary>
/// <param name="package">The package this asset will be part of.</param>
/// <param name="filePath">The relative file path (from default asset folder).</param>
/// <param name="sourceFolder">The source folder (optional, can be null).</param>
/// <exception cref="System.ArgumentException">filePath must be relative</exception>
public PackageLoadingAssetFile(Package package, UFile filePath, UDirectory sourceFolder)
{
if (filePath.IsAbsolute)
throw new ArgumentException("filePath must be relative", filePath);
SourceFolder = UPath.Combine(package.RootDirectory, sourceFolder ?? package.GetDefaultAssetFolder());
FilePath = UPath.Combine(SourceFolder, filePath);
}
示例13: SettingsKey
/// <summary>
/// Initializes a new instance of the <see cref="SettingsKey"/> class.
/// </summary>
/// <param name="name">The name of this settings key. Must be unique amongst the application.</param>
/// <param name="group">The <see cref="SettingsGroup"/> containing this <see cref="SettingsKey"/>.</param>
/// <param name="defaultValueCallback">A function that returns the default value associated to this settings key.</param>
protected SettingsKey(UFile name, SettingsGroup group, Func<object> defaultValueCallback)
{
Name = name;
DisplayName = name;
DefaultObjectValueCallback = defaultValueCallback;
Group = group;
Group.RegisterSettingsKey(name, defaultValueCallback(), this);
}
示例14: Import
/// <summary>
/// Imports the model.
/// </summary>
/// <param name="localPath">The path of the asset.</param>
/// <param name="importParameters">The parameters used to import the model.</param>
/// <returns>A collection of assets.</returns>
public override IEnumerable<AssetItem> Import(UFile localPath, AssetImporterParameters importParameters)
{
var rawAssetReferences = new List<AssetItem>(); // the asset references without subdirectory path
var entityInfo = GetEntityInfo(localPath, importParameters.Logger);
//var isImportingEntity = importParameters.IsTypeSelectedForOutput<EntityAsset>();
var isImportingModel = importParameters.IsTypeSelectedForOutput<ModelAsset>();
var isImportingMaterial = importParameters.IsTypeSelectedForOutput<MaterialAsset>() ||
isImportingModel;
var isImportingTexture = importParameters.IsTypeSelectedForOutput<TextureAsset>() ||
isImportingMaterial;
// 1. Textures
if (isImportingTexture)
{
ImportTextures(entityInfo.TextureDependencies, rawAssetReferences);
}
// 2. Skeleton
AssetItem skeletonAsset = null;
if (importParameters.IsTypeSelectedForOutput<SkeletonAsset>())
{
skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo);
}
// 3. Animation
if (importParameters.IsTypeSelectedForOutput<AnimationAsset>())
{
ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset);
}
// 4. Materials
if (isImportingMaterial)
{
ImportMaterials(rawAssetReferences, entityInfo.Materials);
}
// 5. Model
if (isImportingModel)
{
var modelItem = ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset);
// 5. Entity (currently disabled)
//if (isImportingEntity)
//{
// var entityAssetItem = ImportEntity(rawAssetReferences, localPath, modelItem);
//
// // Apply EntityAnalysis
// EntityAnalysis.UpdateEntityReferences(((EntityAsset)entityAssetItem.Asset).Hierarchy);
//}
}
return rawAssetReferences;
}
示例15: Import
public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters)
{
var asset = new TextureAsset { Source = rawAssetPath };
// Creates the url to the texture
var textureUrl = new UFile(rawAssetPath.GetFileName(), null);
yield return new AssetItem(textureUrl, asset);
}