using UnityEditor.Experimental.GraphView;
using UnityEngine;
namespace UnityEditor.VFX
{
///
/// This structure provides all useful information for a VFX template
///
public struct VFXTemplateDescriptor
{
///
/// Name of the template which will be displayed in the template window
///
public string name;
///
/// Category is used to group templates together in the template window
///
public string category;
///
/// Give some description to your template so that we know what it's doing
///
public string description;
///
/// This icon is displayed next to the name in the template window
///
public Texture2D icon;
///
/// Thumbnail is displayed with the description in the details panel of the template window
///
public Texture2D thumbnail;
///
/// Same as the name, inherited from the interface ITemplateDescriptor
///
public string header => name;
}
///
/// Helper class to create or update a Visual Effect asset template
///
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 vfxTemplateDescriptor)
{
if (VFXTemplateHelperInternal.TryGetTemplateStatic(vfxPath, out var graphViewTemplate))
{
vfxTemplateDescriptor = new VFXTemplateDescriptor
{
name = graphViewTemplate.name,
category = graphViewTemplate.category,
description = graphViewTemplate.description,
icon = graphViewTemplate.icon,
thumbnail = graphViewTemplate.thumbnail,
};
return true;
}
vfxTemplateDescriptor = 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 vfxTemplateDescriptor)
{
return VFXTemplateHelperInternal.TrySetTemplateStatic(vfxPath, new GraphViewTemplateDescriptor
{
name = vfxTemplateDescriptor.name,
category = vfxTemplateDescriptor.category,
description = vfxTemplateDescriptor.description,
icon = vfxTemplateDescriptor.icon,
thumbnail = vfxTemplateDescriptor.thumbnail,
});
}
}
}