本文整理汇总了C#中AssetItem类的典型用法代码示例。如果您正苦于以下问题:C# AssetItem类的具体用法?C# AssetItem怎么用?C# AssetItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssetItem类属于命名空间,在下文中一共展示了AssetItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssetToImportMerge
/// <summary>
/// Initializes a new instance of the <see cref="AssetToImportMerge"/> class.
/// </summary>
/// <param name="previousItem">The previous item.</param>
/// <param name="diff">The difference.</param>
/// <param name="mergePreviewResult">The merge preview result.</param>
internal AssetToImportMerge(AssetItem previousItem, AssetDiff diff, MergeResult mergePreviewResult)
{
PreviousItem = previousItem;
this.Diff = diff;
this.MergePreviewResult = mergePreviewResult;
DependencyGroups = new List<AssetToImportMergeGroup>();
}
示例2: Compile
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
{
var asset = (EffectLogAsset)assetItem.Asset;
var originalSourcePath = assetItem.FullPath;
result.ShouldWaitForPreviousBuilds = true;
result.BuildSteps = new AssetBuildStep(assetItem) { new EffectLogBuildStep(context, originalSourcePath, assetItem) };
}
示例3: AssetCompiledArgs
/// <summary>
/// Constructs an <see cref="AssetCompiledArgs"/> instance.
/// </summary>
/// <param name="asset">The asset that has been compiled. Cannot be null.</param>
/// <param name="result">The result of the asset compilation. Cannot be null.</param>
public AssetCompiledArgs(AssetItem asset, AssetCompilerResult result)
{
if (asset == null) throw new ArgumentNullException("asset");
if (result == null) throw new ArgumentNullException("result");
Asset = asset;
Result = result;
}
示例4: AssetItemMutable
public AssetItemMutable(AssetItem item)
{
Location = item.Location;
SourceFolder = item.SourceFolder;
Asset = item.Asset;
ProjectFile = item.SourceProject;
}
示例5: SaveGeneratedAsset
public override void SaveGeneratedAsset(AssetItem assetItem)
{
//generate the .cs files
// Always output a result into the file
string result;
try
{
var parsingResult = XenkoShaderParser.TryPreProcessAndParse(Text, assetItem.FullPath);
if (parsingResult.HasErrors)
{
result = "// Failed to parse the shader:\n" + parsingResult;
}
else
{
// Try to generate a mixin code.
var shaderKeyGenerator = new ShaderMixinCodeGen(parsingResult.Shader, parsingResult);
shaderKeyGenerator.Run();
result = shaderKeyGenerator.Text ?? string.Empty;
}
}
catch (Exception ex)
{
result = "// Unexpected exceptions occurred while generating the file\n" + ex;
}
// We force the UTF8 to include the BOM to match VS default
var data = Encoding.UTF8.GetBytes(result);
File.WriteAllBytes(assetItem.GetGeneratedAbsolutePath(), data);
}
示例6: 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);
}
示例7: Compile
/// <inheritdoc/>
public AssetCompilerResult Compile(CompilerContext context, AssetItem assetItem)
{
if (context == null) throw new ArgumentNullException("context");
if (assetItem == null) throw new ArgumentNullException("assetItem");
var compilerResult = new AssetCompilerResult();
if (assetItem.Package == null)
{
compilerResult.Warning("Asset [{0}] is not attached to a package", assetItem);
return compilerResult;
}
var assetCompilerContext = (AssetCompilerContext)context;
// create the a package that contains only the asset and its the dependencies
var dependenciesCompilePackage = assetItem.Package.Session.CreateCompilePackageFromAsset(assetItem);
var clonedAsset = dependenciesCompilePackage.FindAsset(assetItem.Id);
CompileWithDependencies(assetCompilerContext, clonedAsset, assetItem, compilerResult);
// Check unloadable items
foreach (var currentAssetItem in dependenciesCompilePackage.Assets)
{
var unloadableItems = UnloadableObjectRemover.Run(currentAssetItem.Asset);
foreach (var unloadableItem in unloadableItems)
{
compilerResult.Log(new AssetLogMessage(dependenciesCompilePackage, currentAssetItem.ToReference(), LogMessageType.Warning, $"Unable to load the object of type {unloadableItem.UnloadableObject.TypeName} which is located at [{unloadableItem.MemberPath}] in the asset"));
}
}
// Find AssetBuildStep
var assetBuildSteps = new Dictionary<AssetId, AssetBuildStep>();
foreach (var step in compilerResult.BuildSteps.EnumerateRecursively())
{
var assetStep = step as AssetBuildStep;
if (assetStep != null)
{
assetBuildSteps[assetStep.AssetItem.Id] = assetStep;
}
}
// TODO: Refactor logging of CompilerApp and BuildEngine
// Copy log top-level to proper asset build steps
foreach (var message in compilerResult.Messages)
{
var assetMessage = message as AssetLogMessage;
// Find asset (if nothing found, default to main asset)
var assetId = assetMessage?.AssetReference.Id ?? assetItem.Id;
AssetBuildStep assetBuildStep;
if (assetBuildSteps.TryGetValue(assetId, out assetBuildStep))
{
// Log to AssetBuildStep
assetBuildStep.Logger?.Log(message);
}
}
return compilerResult;
}
示例8: Compile
/// <inheritdoc/>
public AssetCompilerResult Compile(CompilerContext context, AssetItem assetItem)
{
if (context == null) throw new ArgumentNullException("context");
if (assetItem == null) throw new ArgumentNullException("assetItem");
assetItem = assetItem.Package.Session.DependencyManager.FindDependencySet(assetItem.Id).Item;
var compilerResult = new AssetCompilerResult();
if (assetItem.Package == null)
{
compilerResult.Warning("Asset [{0}] is not attached to a package", assetItem);
return compilerResult;
}
var assetCompilerContext = (AssetCompilerContext)context;
// create the a package that contains only the asset and its the dependencies
var dependenciesCompilePackage = assetItem.Package.Session.CreateCompilePackageFromAsset(assetItem);
assetCompilerContext.Package = dependenciesCompilePackage.LocalPackages.FirstOrDefault();
var clonedAsset = dependenciesCompilePackage.FindAsset(assetItem.Id);
CompileWithDependencies(assetCompilerContext, clonedAsset, assetItem, compilerResult);
return compilerResult;
}
示例9: Compile
protected override void Compile(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
{
var asset = (SkeletonAsset)assetItem.Asset;
var assetSource = GetAbsolutePath(assetItem, asset.Source);
var extension = assetSource.GetFileExtension();
var buildStep = new AssetBuildStep(assetItem);
var importModelCommand = ImportModelCommand.Create(extension);
if (importModelCommand == null)
{
result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
return;
}
importModelCommand.SourcePath = assetSource;
importModelCommand.Location = targetUrlInStorage;
importModelCommand.Mode = ImportModelCommand.ExportMode.Skeleton;
importModelCommand.ScaleImport = asset.ScaleImport;
importModelCommand.PivotPosition = asset.PivotPosition;
importModelCommand.SkeletonNodesWithPreserveInfo = asset.NodesWithPreserveInfo;
buildStep.Add(importModelCommand);
result.BuildSteps = buildStep;
}
示例10: LoadAssets
static void LoadAssets()
{
// Get all assets that contained in different Resources folders
var rootPaths = AssetDatabase.FindAssets("Resources").Select(item => AssetDatabase.GUIDToAssetPath(item));
_assets = new List<AssetItem>();
foreach(var path in rootPaths)
{
var dirInfo = new DirectoryInfo(path);
// Exclude temporary folder if it contains "Resources" word
if (!string.Equals(dirInfo.Name, _tempFolderName))
{
var rootItem = new AssetItem();
rootItem.path = path;
rootItem.name = dirInfo.Name;
rootItem.isFolder = true;
rootItem.AddChild(GetSubAssets(rootItem.path));
_assets.Add(rootItem);
}
}
if (File.Exists(GetAbsolutePath(_saveDataPath)))
{
if (!cleared)
{
LoadData();
}
}
init = true;
}
示例11: EnsureSourcesExist
/// <summary>
/// Ensures that the sources of an <see cref="Asset"/> exist.
/// </summary>
/// <param name="result">The <see cref="AssetCompilerResult"/> in which to output log of potential errors.</param>
/// <param name="assetItem">The asset to check.</param>
/// <returns><c>true</c> if the source file exists, <c>false</c> otherwise.</returns>
/// <exception cref="ArgumentNullException">Any of the argument is <c>null</c>.</exception>
private static bool EnsureSourcesExist(AssetCompilerResult result, AssetItem assetItem)
{
if (result == null) throw new ArgumentNullException(nameof(result));
if (assetItem == null) throw new ArgumentNullException(nameof(assetItem));
var collector = new SourceFilesCollector();
var sourceMembers = collector.GetSourceMembers(assetItem.Asset);
foreach (var member in sourceMembers)
{
if (string.IsNullOrEmpty(member.Value))
{
result.Error($"Source is null for Asset [{assetItem}] in property [{member.Key}]");
return false;
}
// Get absolute path of asset source on disk
var assetDirectory = assetItem.FullPath.GetParent();
var assetSource = UPath.Combine(assetDirectory, member.Value);
// Ensure the file exists
if (!File.Exists(assetSource))
{
result.Error($"Unable to find the source file '{assetSource}' for Asset [{assetItem}]");
return false;
}
}
return true;
}
示例12: 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;
}
示例13: Compile
public AssetCompilerResult Compile(CompilerContext context, AssetItem assetItem)
{
if (context == null) throw new ArgumentNullException(nameof(context));
if (assetItem == null) throw new ArgumentNullException(nameof(assetItem));
var result = new AssetCompilerResult(GetType().Name)
{
BuildSteps = new AssetBuildStep(assetItem)
};
// Only use the path to the asset without its extension
var fullPath = assetItem.FullPath;
if (!fullPath.IsAbsolute)
{
throw new InvalidOperationException("assetItem must be an absolute path");
}
// Try to compile only if we're sure that the sources exist.
if (EnsureSourcesExist(result, assetItem))
{
Compile((AssetCompilerContext)context, assetItem, assetItem.Location.GetDirectoryAndFileName(), result);
}
return result;
}
示例14: TestInheritance
public void TestInheritance()
{
// -----------------------------------------------------------
// Tests inheritance
// -----------------------------------------------------------
// 4 assets
// [asset1] is referencing [asset2]
// [asset2]
// [asset3] is inheriting [asset1]
// We create a [project1] with [asset1, asset2, asset3]
// Check direct inherit dependencies for [asset3]: [asset1]
// -----------------------------------------------------------
var asset1 = new AssetObjectTest();
var asset2 = new AssetObjectTest();
var assetItem1 = new AssetItem("asset-1", asset1);
var assetItem2 = new AssetItem("asset-2", asset2);
var asset3 = assetItem1.CreateChildAsset();
var assetItem3 = new AssetItem("asset-3", asset3);
asset1.Reference = new AssetReference<AssetObjectTest>(assetItem2.Id, assetItem2.Location);
var project = new Package();
project.Assets.Add(assetItem1);
project.Assets.Add(assetItem2);
project.Assets.Add(assetItem3);
// Create a session with this project
using (var session = new PackageSession(project))
{
var dependencyManager = session.DependencyManager;
// Verify inheritance
{
var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
Assert.AreEqual(1, assets.Count);
Assert.AreEqual(asset3.Id, assets[0].Id);
}
// Remove the inheritance
var copyBase = asset3.Base;
asset3.Base = null;
assetItem3.IsDirty = true;
{
var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
Assert.AreEqual(0, assets.Count);
}
// Add back the inheritance
asset3.Base = copyBase;
assetItem3.IsDirty = true;
{
var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
Assert.AreEqual(1, assets.Count);
Assert.AreEqual(asset3.Id, assets[0].Id);
}
}
}
示例15: AssetLink
// This constructor exists for better factorization of code in AssetDependencies.
// It should not be turned into public as AssetItem is not valid.
internal AssetLink(IContentReference reference, ContentLinkType type)
{
if (reference == null) throw new ArgumentNullException("reference");
Item = null;
this.type = type;
this.reference = reference;
}