namespace UnityEditor.VFX
{
///
/// This class lets you manage Visual Effect templates
///
public static class VFXTemplateHelper
{
///
/// This method gets template information for any Visual Effect asset.
///
/// The path to a Visual Effect asset.
/// The structure that contains template information.
/// Returns true if the Visual Effect asset has template information, otherwise it returns false.
public static bool TryGetTemplate(string vfxPath, out VFXTemplateDescriptor template)
{
var importer = (VisualEffectImporter)AssetImporter.GetAtPath(vfxPath);
var nativeTemplate = importer.templateProperty;
if (!string.IsNullOrEmpty(nativeTemplate.name))
{
template = new VFXTemplateDescriptor
{
name = nativeTemplate.name,
category = nativeTemplate.category,
description = nativeTemplate.description,
icon = nativeTemplate.icon,
thumbnail = nativeTemplate.thumbnail,
};
return true;
}
template = default;
return false;
}
///
/// This method creates or updates a Visual Effect asset template.
///
/// The path to the existing Visual Effect asset.
/// The structure that contains all template information.
/// Returns true if the template is created, otherwise it returns false.
public static bool TrySetTemplate(string vfxPath, VFXTemplateDescriptor template)
{
if (string.IsNullOrEmpty(vfxPath))
return false;
if (AssetDatabase.AssetPathExists(vfxPath))
{
var importer = (VisualEffectImporter)AssetImporter.GetAtPath(vfxPath);
var nativeTemplate = new VFXTemplate
{
name = template.name,
category = template.category,
description = template.description,
icon = template.icon,
thumbnail = template.thumbnail,
};
importer.templateProperty = nativeTemplate;
return true;
}
return false;
}
}
}