using System; using System.Diagnostics; using System.Reflection; using UnityEngine; namespace UnityEditor.VFX { /// /// Attribute to define the help url /// /// /// [VFXHelpURLAttribute("Context-Initialize")] /// class VFXBasicInitialize : VFXContext /// [Conditional("UNITY_EDITOR")] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)] class VFXHelpURLAttribute : HelpURLAttribute { const string fallbackVersion = "13.1"; const string url = "https://docs.unity3d.com/Packages/{0}@{1}/manual/{2}.html{3}"; /// /// The constructor of the attribute /// /// /// public VFXHelpURLAttribute(string pageName, string packageName = "com.unity.visualeffectgraph") : base(GetPageLink(packageName, pageName)) { } public static string version { get { #if UNITY_EDITOR if (TryGetPackageInfoForType(typeof(VFXHelpURLAttribute), out _, out var version)) return version; #endif return fallbackVersion; } } public static string GetPageLink(string packageName, string pageName) => string.Format(url, packageName, version, pageName, ""); #if UNITY_EDITOR /// /// Obtain package information from a specific type /// /// The type used to retrieve package information /// The name of the package containing the given type /// The version number of the package containing the given type. Only Major.Minor will be returned as fix is not used for documentation /// public static bool TryGetPackageInfoForType(Type type, out string packageName, out string version) { var packageInfo = PackageManager.PackageInfo.FindForAssembly(type.Assembly); if (packageInfo == null) { packageName = null; version = null; return false; } packageName = packageInfo.name; version = packageInfo.version.Substring(0, packageInfo.version.LastIndexOf('.')); return true; } public static string GetHelpUrl(Type t) { var attribute = (VFXHelpURLAttribute)t.GetCustomAttribute(typeof(VFXHelpURLAttribute), false); return attribute?.URL; } #endif } }