-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathVFXHelpURLAttribute.cs
More file actions
77 lines (69 loc) · 2.64 KB
/
Copy pathVFXHelpURLAttribute.cs
File metadata and controls
77 lines (69 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Diagnostics;
using System.Reflection;
using UnityEngine;
namespace UnityEditor.VFX
{
/// <summary>
/// Attribute to define the help url
/// </summary>
/// <example>
/// [VFXHelpURLAttribute("Context-Initialize")]
/// class VFXBasicInitialize : VFXContext
/// </example>
[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}";
/// <summary>
/// The constructor of the attribute
/// </summary>
/// <param name="pageName"></param>
/// <param name="packageName"></param>
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
/// <summary>
/// Obtain package information from a specific type
/// </summary>
/// <param name="type">The type used to retrieve package information</param>
/// <param name="packageName">The name of the package containing the given type</param>
/// <param name="version">The version number of the package containing the given type. Only Major.Minor will be returned as fix is not used for documentation</param>
/// <returns></returns>
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
}
}