using System; using System.Runtime.CompilerServices; using System.Diagnostics; using System.Linq; #if UNITY_EDITOR using PackageInfo = UnityEditor.PackageManager.PackageInfo; #endif [assembly: InternalsVisibleTo("Unity.RenderPipelines.Core.Editor.Tests")] namespace UnityEngine.Rendering { /// /// Attribute to define the help url /// /// /// [CoreRPHelpURLAttribute("Volume")] /// public class Volume : MonoBehaviour /// [Conditional("UNITY_EDITOR")] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum, AllowMultiple = false)] public class CoreRPHelpURLAttribute : HelpURLAttribute { /// /// The constructor of the attribute /// /// /// public CoreRPHelpURLAttribute(string pageName, string packageName = "com.unity.render-pipelines.core") : base(DocumentationInfo.GetPageLink(packageName, pageName)) { } } //We need to have only one version number amongst packages (so public) /// /// Documentation Info class. /// public class DocumentationInfo { const string fallbackVersion = "12.1"; const string url = "https://docs.unity3d.com/Packages/{0}@{1}/manual/{2}.html"; /// /// Current version of the documentation. /// public static string version { get { #if UNITY_EDITOR var packageInfo = PackageInfo.FindForAssembly(typeof(DocumentationInfo).Assembly); return packageInfo == null ? fallbackVersion : packageInfo.version.Substring(0, 4); #else return fallbackVersion; #endif } } /// /// Generates a help url for the given package and page name /// /// The package name /// The page name /// The full url page public static string GetPageLink(string packageName, string pageName) => string.Format(url, packageName, version, pageName); } /// /// Set of utils for documentation /// public static class DocumentationUtils { /// /// Obtains the help url from an enum /// /// The enum with a /// [Optional] The current value of the enum /// The full url public static string GetHelpURL(TEnum mask = default) where TEnum : struct, IConvertible { var helpURLAttribute = (HelpURLAttribute)mask .GetType() .GetCustomAttributes(typeof(HelpURLAttribute), false) .FirstOrDefault(); return helpURLAttribute == null ? string.Empty : $"{helpURLAttribute.URL}#{mask}"; } } }